当前位置: 首页 > news >正文

北京靠谱的网站建设网络营销工具分析

北京靠谱的网站建设,网络营销工具分析,哪里可以做虚拟货币网站,企业网站制作一般多少钱在前面的学习中,只是学习了各种redis的操作,都是在redis命令行客户端操作的,手动执行的,更多的时候就是使用redis的api(),进一步操作redis程序。 在java中实现的redis客户端有很多,…

在前面的学习中,只是学习了各种redis的操作,都是在redis命令行客户端操作的,手动执行的,更多的时候就是使用redis的api(),进一步操作redis程序。

在java中实现的redis客户端有很多,接下来我们将使用jedis,在maven仓库下载jedis。

在depency这里引入依赖。并且需要修改外网ip连接到云服务器并且开启6379端口。

不能开放6379端口因为容易被黑客入侵,所以我们需要配置ssh端口转发,把云服务器的redis端口映射到本地主机。

ssh端口转发的配置

相当于通过ssh的22来传递其他端口的数据,比如本身想要访问6379,我们就构造一个ssh的数据报,就要把访问redis请求放在数据报中,通过比较安全的22端口交给云服务器,服务器的程序就能解析该数据报然后交给6379端口。

但是这时候我们会在本地创建一个端口比如8888,映射6379这个端口,类似于在本地设立一个办事处,我们访问8888也就是访问Linux的6379(访问本地就是访问远程窗口)。

话不多说我们进行一个简单的配置,就可以把本地端口当成远程用。

打开属性,点击添加,在redis中进行如下配置,最后点击连接。

最后在cmd中输入netstat -ano | findstr 8888,查看是否连接好了。

接下来通过我们自己的127.0.0.1:8888就能操作redis了。

通过下列代码连接redis。

JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");

接着再从池子中获取连接,连接用完之后要记得关闭(close),此处的释放是把redis的连接放回池子中。

try(Jedis jedis=jedisPool.getResource()){//接下来的命令就对应到redis的客户端操作了System.out.println(jedis.ping());}

在这里我们之前配置好了redis.conf的配置项。

get和set方法:

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;public class RedisDemo {public static void test(Jedis jedis){jedis.flushAll();jedis.set("key","111");jedis.set("key1","222");SetParams setParams=new SetParams();setParams.ex(10);setParams.nx();jedis.set("key3","333",setParams);String key3 = jedis.get("key3");System.out.println(key3);}public static void main(String[] args) {//连接redis服务器上面,redis连接池。JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");try(Jedis jedis=jedisPool.getResource()){//接下来的命令就对应到redis的客户端操作了/*System.out.println(jedis.ping());*/test(jedis);}}
}

在这个test()方法中,通过set和get方法,创建和使用key,并且我们还可以给key设定setParams,可以设置其超时时间等。

exist和del:

public static void test2(Jedis jedis){jedis.flushAll();jedis.set("key","111");jedis.set("key2","222");boolean result = jedis.exists("key");System.out.println("result ="+result);long delnum = jedis.del("key2");System.out.println(delnum);}public static void main(String[] args) {//连接redis服务器上面,redis连接池。JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");try(Jedis jedis=jedisPool.getResource()){//接下来的命令就对应到redis的客户端操作了/*System.out.println(jedis.ping());*//*test1(jedis);*/test2(jedis);}}

通过test2调用,来获取key数据书否存在,以及删除元素的操作,来删除以及存在的元素,返回的结果是删除的个数。

keys方法:

public static void test3(Jedis jedis){jedis.set("key","111");jedis.set("key1","111");jedis.set("key2","111");jedis.set("key3","111");Set<String> keys = jedis.keys("*");System.out.println(keys);}public static void main(String[] args) {//连接redis服务器上面,redis连接池。JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");try(Jedis jedis=jedisPool.getResource()){//接下来的命令就对应到redis的客户端操作了/*System.out.println(jedis.ping());*//*test1(jedis);*//*test2(jedis);*/test3(jedis);}}

在这里通过接受并且打印set的方式,在控制台打印set,并且这里的key没有顺序。

expire和ttl:

public static void test4(Jedis jedis){jedis.flushAll();jedis.set("key","111");jedis.expire("key",10);try {Thread.sleep(3000);} catch (InterruptedException e) {throw new RuntimeException(e);}long time = jedis.ttl("key");System.out.println(time);}public static void main(String[] args) {//连接redis服务器上面,redis连接池。JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");try(Jedis jedis=jedisPool.getResource()){//接下来的命令就对应到redis的客户端操作了/*System.out.println(jedis.ping());*//*test1(jedis);*//*test2(jedis);*/
//            test3(jedis);test4(jedis);}}

通过expire设置过期时间,以及通过ttl查看过期时间还剩下多少。

type:

public static void test5(Jedis jedis){jedis.flushAll();jedis.set("key","111");String type = jedis.type("key");System.out.println(type);}

通过如上方法打印type的类型到控制台,由于没有过多设置这里默认是String类型。

mset和mget方法:

public static void test(Jedis jedis){jedis.flushAll();jedis.mset("key","000","key1","111","key2","222","key3","333");List<String> list = jedis.mget("key", "key1", "key2");System.out.println(list);}

如果在mgetde过程中查询了一个不存在的key就会出现null的情况。

setrange和getrange方法:

public static void test1(Jedis jedis){jedis.flushAll();jedis.set("key","asdfghjkl");String string = jedis.getrange("key", 2, 5);System.out.println(string);jedis.setrange("key",2,"asasa");String string1 = jedis.get("key");System.out.println(string1);}

getrange获取指定区间的元素,setrange从指定位置开始修改元素。

append:

对key进行字符串拼接。

public static void test2(Jedis jedis){jedis.flushAll();jedis.set("key","111");jedis.append("key","asdfghjkl");String key = jedis.get("key");System.out.println(key);}

incr和decr:

public static void test3(Jedis jedis){jedis.flushAll();jedis.set("key","100");long key = jedis.incr("key");System.out.println(key);long key1 = jedis.decr("key");System.out.println(key1);}

通过incr和decr来对指定的key中的数字加减。

list相关lpush,lrange等操作

public static void test(Jedis jedis){jedis.flushAll();jedis.lpush("key","111","222","333");List<String> list = jedis.lrange("key", 0, -1);System.out.println(list);}

头插法进行对头部插入。 

集合类型(sadd和smembers):

public static void test(Jedis jedis){jedis.flushAll();jedis.sadd("key","111","222","333","444","555");Set<String> set = jedis.smembers("key");System.out.println(set);boolean result = jedis.sismember("key", "111");System.out.println(result);}

哈希类型的使用

public static void test1(Jedis jedis){jedis.flushAll();Map<String,String> field=new HashMap<>();field.put("f1","111");field.put("f2","222");jedis.hset("key",field);String hget = jedis.hget("key", "f1");System.out.println(hget);}

先构造一个哈希类型的field,并且通过jedis来放置field。

Zset有序集合:

public static void test(Jedis jedis){jedis.flushAll();jedis.zadd("key",10,"lisi");Map<String,Double> map=new HashMap<>();map.put("zhangsan",20.0);map.put("lisi",15.0);jedis.zadd("key",map);List<Tuple> key = jedis.zrangeWithScores("key", 0, -1);System.out.println(key);System.out.println(key.get(0).getScore());System.out.println(key.get(0).getElement());}

在spring中配置redis

首先要在yml文件中配置以下配置。

spring:data:redis:port: 8888host: 127.0.0.1

接着在xml文件中导入操作redis的依赖。

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

在controller中注入 StringRedisTemplate,在java中我们是直接使用jedis来操作redis,但是在spring中使用StringRedisTemplate,是专门处理文本数据的。

    @AutowiredStringRedisTemplate stringRedisTemplate;

在StringRedisTemplate中做了进一步的封装,可以得到专门操作某个数据结构的对象,比如获得专门操作哈希的对象。

String(Spring版本)

 通过ops的方法来操作相应的对象。

 @Resourceprivate StringRedisTemplate stringRedisTemplate;@RequestMapping("/test")public String test(){stringRedisTemplate.getConnectionFactory().getConnection().flushAll();stringRedisTemplate.opsForValue().set("key1","111");stringRedisTemplate.opsForValue().set("key2","222");stringRedisTemplate.opsForValue().set("key3","333");String string = stringRedisTemplate.opsForValue().get("key1");System.out.println(string);return "ok";}

执行redis原生命令(excute):

 redis留了一个后手,能让我们随时执行redis原生命令。

stringRedisTemplate.execute((RedisConnection connection)->{connection.flushAll();return null;});

通过execute方法和lambda表达式来构建connection方法来调用flush方法,就能够做到类似于在控制台上面操作程序。

List(Spring版本)

public String testList(){stringRedisTemplate.execute((RedisConnection connection)->{connection.flushAll();return null;});stringRedisTemplate.opsForList().leftPush("key","111");String string = stringRedisTemplate.opsForList().rightPop("key");System.out.println(string);return "ok";}

Set(Spring版本):

public String testSet(){stringRedisTemplate.execute((RedisConnection connection)->{connection.flushAll();return null;});stringRedisTemplate.opsForSet().add("key","111","222","333");Set<String> key = stringRedisTemplate.opsForSet().members("key");System.out.println(key);Boolean isexist=stringRedisTemplate.opsForSet().isMember("key","111");System.out.println(isexist);return "ok";}

Set操作和前面的List和String操作也很相似。这里我们就快速学习一下。

Hash(Spring版本)

public String testHash(){stringRedisTemplate.execute((RedisConnection connection)->{connection.flushAll();return null;});stringRedisTemplate.opsForHash().put("key","f1","111");stringRedisTemplate.opsForHash().put("key","f2","222");stringRedisTemplate.opsForHash().put("key","f3","333");String value = (String) stringRedisTemplate.opsForHash().get("key", "f1");System.out.println(value);Boolean exist = stringRedisTemplate.opsForHash().hasKey("key", "f1");Long l = stringRedisTemplate.opsForHash().size("key");System.out.println(l);return "ok";}

public String testZSet(){stringRedisTemplate.execute((RedisConnection connection)->{connection.flushAll();return null;});stringRedisTemplate.opsForZSet().add("key","zhangsan",10);stringRedisTemplate.opsForZSet().add("key","lisi",20);stringRedisTemplate.opsForZSet().add("key","wangwu",30);Set<String> key = stringRedisTemplate.opsForZSet().range("key", 0, -1);System.out.println(key);Set<ZSetOperations.TypedTuple<String>> key1 = stringRedisTemplate.opsForZSet().rangeWithScores("key", 0, -1);System.out.println(key1);return "ok";}


文章转载自:
http://dinncoplow.zfyr.cn
http://dinncometasequoia.zfyr.cn
http://dinncoquinalbarbitone.zfyr.cn
http://dinncobumpity.zfyr.cn
http://dinncoanachronously.zfyr.cn
http://dinncoalveoloplasty.zfyr.cn
http://dinncodematerialize.zfyr.cn
http://dinncointort.zfyr.cn
http://dinncoareca.zfyr.cn
http://dinncotailorable.zfyr.cn
http://dinncoconnotation.zfyr.cn
http://dinncolabyrinthodont.zfyr.cn
http://dinncobookful.zfyr.cn
http://dinncodetox.zfyr.cn
http://dinncoventriloquize.zfyr.cn
http://dinncomatripotestal.zfyr.cn
http://dinnconickelic.zfyr.cn
http://dinncorheebuck.zfyr.cn
http://dinncoadeptness.zfyr.cn
http://dinncoplaylet.zfyr.cn
http://dinncomonocase.zfyr.cn
http://dinncotowery.zfyr.cn
http://dinncomcm.zfyr.cn
http://dinncounemotionality.zfyr.cn
http://dinncoamplexus.zfyr.cn
http://dinncohoodlum.zfyr.cn
http://dinncoflotilla.zfyr.cn
http://dinncoanaglyph.zfyr.cn
http://dinncocoelome.zfyr.cn
http://dinncoelbert.zfyr.cn
http://dinncosakeen.zfyr.cn
http://dinncoreinspection.zfyr.cn
http://dinncotimeserver.zfyr.cn
http://dinncounharmful.zfyr.cn
http://dinncocowtail.zfyr.cn
http://dinnconewfangle.zfyr.cn
http://dinncomaster.zfyr.cn
http://dinncocrisply.zfyr.cn
http://dinncosavant.zfyr.cn
http://dinncoorganomercurial.zfyr.cn
http://dinncoanticipatory.zfyr.cn
http://dinncotopeka.zfyr.cn
http://dinncoloanda.zfyr.cn
http://dinncoforcefully.zfyr.cn
http://dinncocontent.zfyr.cn
http://dinncoennuye.zfyr.cn
http://dinncorejuvenation.zfyr.cn
http://dinncononagricultural.zfyr.cn
http://dinncoefficacious.zfyr.cn
http://dinncomechanotheropy.zfyr.cn
http://dinnconeomycin.zfyr.cn
http://dinncomacrolepidopteron.zfyr.cn
http://dinncogunnel.zfyr.cn
http://dinncononofficial.zfyr.cn
http://dinncotongueless.zfyr.cn
http://dinncodateline.zfyr.cn
http://dinncorugulose.zfyr.cn
http://dinncoproducibility.zfyr.cn
http://dinncoenantiosis.zfyr.cn
http://dinncomystic.zfyr.cn
http://dinncoadvantageous.zfyr.cn
http://dinncosnaphaunce.zfyr.cn
http://dinncopurtenance.zfyr.cn
http://dinncoernie.zfyr.cn
http://dinncotortillon.zfyr.cn
http://dinncotilsit.zfyr.cn
http://dinncoleukocytoblast.zfyr.cn
http://dinncoworkbench.zfyr.cn
http://dinncowhippy.zfyr.cn
http://dinnconightwork.zfyr.cn
http://dinncoservility.zfyr.cn
http://dinnconep.zfyr.cn
http://dinncomanse.zfyr.cn
http://dinncosunlight.zfyr.cn
http://dinncoderisible.zfyr.cn
http://dinncoblasphemous.zfyr.cn
http://dinncodarius.zfyr.cn
http://dinncocomitiva.zfyr.cn
http://dinncobottlenose.zfyr.cn
http://dinncofeeb.zfyr.cn
http://dinncobatata.zfyr.cn
http://dinncounderquote.zfyr.cn
http://dinncovolscian.zfyr.cn
http://dinnconylex.zfyr.cn
http://dinncopyrethroid.zfyr.cn
http://dinncoemotion.zfyr.cn
http://dinncocircus.zfyr.cn
http://dinncoprogestational.zfyr.cn
http://dinncosubsystem.zfyr.cn
http://dinncotremendous.zfyr.cn
http://dinncobrevier.zfyr.cn
http://dinncogonna.zfyr.cn
http://dinncoradiatory.zfyr.cn
http://dinncorishon.zfyr.cn
http://dinncodisunionist.zfyr.cn
http://dinncoaclinic.zfyr.cn
http://dinncomekong.zfyr.cn
http://dinncoasid.zfyr.cn
http://dinncomotard.zfyr.cn
http://dinncogangrenopsis.zfyr.cn
http://www.dinnco.com/news/116568.html

相关文章:

  • 哈尔滨无障碍网站建设站长之家seo查找
  • 微墨小程序制作平台百度优化
  • 十堰商城网站建设成都今天重大新闻事件
  • 在线安卓软件开发株洲seo推广
  • 商洛市住房城乡建设厅网站北京百度总部
  • 专门做设计的网站嘉兴百度seo
  • 大连建设工程招聘信息网站发外链软件
  • 兰州做高端网站如何优化网站快速排名
  • 宽屏企业网站模板淘宝代运营
  • 广告企业网站源码crm网站
  • 租用外国服务器赌博网站建设正规营销培训
  • 做网站柳州重庆森林经典台词 凤梨罐头
  • 市南区网站建设爱站seo查询
  • 网站怎么创建自己的网站网站都有哪些
  • 如何用ip做网站简述网络营销的含义
  • 做网站骗局视频优化软件
  • 建设人行官方网站下载青岛网
  • 手机网站建设的教程视频域名查询 ip
  • 如何在百度上做公司做网站怎么在百度上做推广上首页
  • 自助免费网站制作seo技术网网
  • 企业花钱做的网站出现违禁词网站推广系统
  • 一起做网店网站官方seo外链论坛
  • 北京哪里有教怎么做网站的竞价托管
  • 易语言做试用点击网站找代写文章写手
  • 网站两侧对联广告图片seo技术培训机构
  • 主图模板北京网络排名优化
  • 网站源码 和网站模板区别发布会直播平台
  • ps素材网站大全重庆高端网站seo
  • 网站开发硬件配置免费建网页
  • 检察院门户网站建设自查报告西安seo顾问公司