在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

spring如何整合redis使用

202次阅读
没有评论

共计 3236 个字符,预计需要花费 9 分钟才能阅读完成。

丸趣 TV 小编给大家分享一下 spring 如何整合 redis 使用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

1. 简单介绍

redis 是基于 C 语言开发。

redis 是一个 key-value 存储系统。和 Memcached 类似,它支持存储的 value 类型相对更多,包括 string(字符串)、list(链表)、set(集合)、zset(sorted set – 有序集合) 和 hash(哈希类型)。

redis 是一个 缓存数据库 (片面的理解) 既可以做缓存,也可以将数据持久化到磁盘中!

 2.pom.xml 引入相关 jar(曾经因 jar 版本问题出现报错,请注意)

dependency 
  groupId org.apache.commons /groupId 
  artifactId commons-pool2 /artifactId 
  version 2.2 /version 
 /dependency 

  groupId org.springframework.data /groupId   artifactId spring-data-redis /artifactId   version 1.7.5.RELEASE /version /dependency dependency   groupId redis.clients /groupId   artifactId jedis /artifactId   version 2.9.0 /version /dependency

3.spring-redis.xml 配置文件,配置关键 bean redisTemplate

?xml version= 1.0  encoding= UTF-8 ?  
 beans xmlns= http://www.springframework.org/schema/beans 
 xmlns:context= http://www.springframework.org/schema/context  xmlns:p= http://www.springframework.org/schema/p 
 xmlns:mvc= http://www.springframework.org/schema/mvc  xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance 
 xmlns:tx= http://www.springframework.org/schema/tx  xmlns:util= http://www.springframework.org/schema/util 
 xmlns:aop= http://www.springframework.org/schema/aop 
 xsi:schemaLocation= http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 http://www.springframework.org/schema/util 
 http://www.springframework.org/schema/util/spring-util-3.0.xsd 
 
 !--  context:property-placeholder location= classpath:redis-config.properties /  
 -- 
 
 
  bean id= jedisPoolConfig   >

上文中使用到的配置文件 redis-config.properteis

redis.maxIdle=1
redis.maxTotal=5
redis.maxWaitMillis=30000
redis.testOnBorrow=true
redis.hostname=127.0.0.1
redis.port=6379

4.redis 有 4 个关键的接口如下

private ValueOperations K, V valueOps;

private ListOperations K, V listOps;

private SetOperations K, V setOps;

private ZSetOperations K, V zSetOps;

分别对应 redis 的数据类型:string(字符串),hash(哈希),list(列表),set(集合)及 zset(sorted set:有序集合)

具体使用如下,上代码:

// 添加字符串
ValueOperations String, String  value = this.redisTemplate.opsForValue();
value.set( hello ,  讨厌 
System.out.println(value.get( hello));

// 添加   一个  hash 集合 HashOperations String, Object, Object  hash =redisTemplate.opsForHash(); hash.put( 沃尔玛 , 水果 ,  苹果 hash.put( 沃尔玛 , 饮料 ,  红牛 System.out.println(hash.entries( 沃尔玛));
// 添加一个 list  集合 ListOperations String, Object  list = redisTemplate.opsForList(); list.rightPush( 课程 ,  chinese list.rightPush( 课程 ,  englise System.out.println(list.range( lpList , 0, 1));
// 添加   一个  set  集合 SetOperations String, Object  set = redisTemplate.opsForSet(); set.add( lpSet ,  lp set.add( lpSet ,  26 set.add( lpSet ,  178cm // 输出  set  集合 System.out.println(set.members( lpSet));
// 添加有序的  set  集合 ZSetOperations String, Object  zset = redisTemplate.opsForZSet(); zset.add(lpZset ,  lp , 0); zset.add(lpZset ,  26 , 2); zset.add(lpZset ,  178cm , 1); // 输出有序  set  集合 System.out.println(zset.rangeByScore( lpZset , 0, 2));

以上是“spring 如何整合 redis 使用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-20发表,共计3236字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 国产精品久久久久久久久动漫 | 亚洲精品系列 | 熟女少妇丰满一区二区 | 五月丁香六月狠狠爱综合 | 中国一级特黄特色真人毛片 | 国产一区在线视频观看 | 精品国产一区二区三区四区五区 | 久久久国产乱子伦精品作者 | 四虎成人精品永久免费av | 国产精品综合色区在线观看 | 国模吧双双大尺度炮交gogo | 亚洲精品第五页中文字幕 | 久久精品视频16 | 免费看日本黄色片 | 国内精品久久久久久久aa护士 | 亚洲狠狠97婷婷综合久久久久 | 国产精品毛片无遮挡高清 | 欧美性生交大片免费看 | 亚洲欧美综合区自拍另类 | 亚洲精品不卡久久久久久 | 亚洲国产精品爱久久久久电影网站 | 看一级片| 无码人妻一区二区三区在线视频 | 毛片网站在线观看 | 亚洲国产一区二区三区四区五区 | 亚洲av无码精品色午夜果冻不卡 | 无码丰满少妇2在线观看 | 亚洲韩国日本一级二级r级 亚洲韩国在线 | 中国gay片男同志免费网站 | 久久最新精品 | 亚洲无线码一区二区三区 | 亚洲国产精品视频 | 久久久久综合一本久道 | 中文字幕在线视频一区 | 秋霞伊人网 | 最新欧美精品一区二区三区 | 日木av无码专区亚洲av毛片 | 天天干天天干天天干天天干天天干 | 亚洲国产欧美在线观看 | 99久久久久国产精品免费 | 国产一级黄|