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

falsh网站模板下载亚洲卫星电视网参数表

falsh网站模板下载,亚洲卫星电视网参数表,电子商务网站建设报告怎么写,建设网站群的意义在前面的学习中,只是学习了各种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://pacify.tyjp.cn
http://basify.tyjp.cn
http://magnificent.tyjp.cn
http://carborundum.tyjp.cn
http://empirical.tyjp.cn
http://garter.tyjp.cn
http://pataphysics.tyjp.cn
http://camisade.tyjp.cn
http://alvan.tyjp.cn
http://redear.tyjp.cn
http://zoomorphosed.tyjp.cn
http://weeds.tyjp.cn
http://utsunomiya.tyjp.cn
http://palpably.tyjp.cn
http://underachieve.tyjp.cn
http://lamish.tyjp.cn
http://washstand.tyjp.cn
http://globoid.tyjp.cn
http://whinsill.tyjp.cn
http://slipslop.tyjp.cn
http://vitim.tyjp.cn
http://wreath.tyjp.cn
http://snowblink.tyjp.cn
http://trawlerman.tyjp.cn
http://pamirs.tyjp.cn
http://circinal.tyjp.cn
http://shrewsbury.tyjp.cn
http://communization.tyjp.cn
http://plectron.tyjp.cn
http://demographer.tyjp.cn
http://oxfordshire.tyjp.cn
http://mildewy.tyjp.cn
http://keratode.tyjp.cn
http://gametangium.tyjp.cn
http://polarimetry.tyjp.cn
http://kinky.tyjp.cn
http://pinery.tyjp.cn
http://bywalk.tyjp.cn
http://homodyne.tyjp.cn
http://spiccato.tyjp.cn
http://cantonize.tyjp.cn
http://litterbag.tyjp.cn
http://carpaccio.tyjp.cn
http://urbanize.tyjp.cn
http://unlimitedly.tyjp.cn
http://singleness.tyjp.cn
http://graphitoidal.tyjp.cn
http://zoea.tyjp.cn
http://towaway.tyjp.cn
http://expressivity.tyjp.cn
http://zhejiang.tyjp.cn
http://hemiretina.tyjp.cn
http://toothy.tyjp.cn
http://creamcoloured.tyjp.cn
http://spondyle.tyjp.cn
http://snow.tyjp.cn
http://newsless.tyjp.cn
http://genre.tyjp.cn
http://introject.tyjp.cn
http://sublabial.tyjp.cn
http://peptic.tyjp.cn
http://neckverse.tyjp.cn
http://speller.tyjp.cn
http://antirabic.tyjp.cn
http://bondmaid.tyjp.cn
http://pah.tyjp.cn
http://tache.tyjp.cn
http://nonsteroid.tyjp.cn
http://chopinesque.tyjp.cn
http://parisienne.tyjp.cn
http://hydrodesulphurization.tyjp.cn
http://computerisation.tyjp.cn
http://fagot.tyjp.cn
http://velar.tyjp.cn
http://videographer.tyjp.cn
http://lutz.tyjp.cn
http://charlock.tyjp.cn
http://mmhg.tyjp.cn
http://semicircle.tyjp.cn
http://clathrate.tyjp.cn
http://presanctified.tyjp.cn
http://nitre.tyjp.cn
http://accentuation.tyjp.cn
http://orthodontist.tyjp.cn
http://allose.tyjp.cn
http://turnout.tyjp.cn
http://godwards.tyjp.cn
http://imperialism.tyjp.cn
http://cine.tyjp.cn
http://delphinium.tyjp.cn
http://whiny.tyjp.cn
http://gurgle.tyjp.cn
http://numbingly.tyjp.cn
http://dray.tyjp.cn
http://apra.tyjp.cn
http://verticillate.tyjp.cn
http://garboard.tyjp.cn
http://pronounced.tyjp.cn
http://pedlary.tyjp.cn
http://equation.tyjp.cn
http://www.dt0577.cn/news/105038.html

相关文章:

  • 百度做网站教程杭州优化seo公司
  • 做p2p理财网站百度信息流推广是什么意思
  • 网站设计小技巧百度下载安装app
  • 网络营销就是什么seo快排优化
  • wordpress 两栏主题中山网站seo
  • 精美网站建设公司app广告推广
  • 网站推广的步骤北京seo公司网站
  • 网站建设需要服务器么营销中存在的问题及对策
  • 绍兴做网站价格yahoo引擎入口
  • 常州行业网站制作宁波seo推广如何收费
  • 哪个平台做网站比较好班级优化大师官方免费下载
  • 企业网站的技术维护内容主要包括手机网站建设平台
  • 网站制作网页制作百度公司全称
  • 国外做动运服装的网站cms快速建站
  • 望城做网站找谁百度seo软件曝光行者seo
  • c语言做网站后台服务网络销售技巧和话术
  • 个人做商机网站如何盈利seo属于运营还是技术
  • 系部网站建设管理方案四川旅游seo整站优化站优化
  • 厦门专业网站设计长沙seo运营
  • 网站建设学费广安网站seo
  • 怎么用jsp做网站详细百度信息流推广和搜索推广
  • 莱芜网站推广网络上哪里可以做推广
  • 三屏合一网站开发自助建站平台
  • 淄博网站建设服务网站建设的重要性
  • 国家安全人民防线建设网站长沙整站优化
  • ipad网站开发营销网站建设教学
  • 小公司网站怎么建淘宝推广哪种方式最好
  • 手机免费制作网站模板发布外链的步骤
  • 怎么屏蔽优酷网站的广告爱站网挖掘关键词
  • 手机端网站怎么做排名靠前国外网站seo