欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

spring如何整合redis使用

小編給大家分享一下spring如何整合redis使用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)建站成立與2013年,先為永昌等服務(wù)建站,永昌等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為永昌企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

1.簡單介紹

redis 是基于C語言開發(fā)。

redis是一個(gè)key-value存儲(chǔ)系統(tǒng)。和Memcached類似,它支持存儲(chǔ)的value類型相對(duì)更多,包括string(字符串)、list(鏈表)、set(集合)、zset(sorted set --有序集合)和hash(哈希類型)。

redis 是一個(gè) 緩存數(shù)據(jù)庫(片面的理解) 既可以做緩存,也可以將數(shù)據(jù)持久化到磁盤中!

 2.pom.xml 引入相關(guān)jar (曾經(jīng)因jar 版本問題出現(xiàn)報(bào)錯(cuò),請注意)

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


<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 配置文件,配置關(guān)鍵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" class="redis.clients.jedis.JedisPoolConfig">
    	 <property name="maxIdle" value="${redis.maxIdle}" /> 
	    <property name="maxTotal" value="${redis.maxTotal}" /> 
	    <property name="blockWhenExhausted" value="true" /> 
	    <property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> 
	    <property name="testOnBorrow" value="${redis.testOnBorrow}" /> 
    </bean>
  
  <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> 
    <property name="hostName" value="${redis.hostname}" /> 
    <property name="port" value="${redis.port}"/> 
    <property name="poolConfig" ref="jedisPoolConfig" /> 
    <property name="usePool" value="true"/> 
  </bean> 
  
  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  
    <property name="connectionFactory"  ref="jedisConnectionFactory" />  
    <property name="keySerializer">  
      <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />  
    </property>   
    <property name="valueSerializer">  
      <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />  
    </property>  
    <property name="hashKeySerializer">   
      <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>   
    </property>  
    <property name="hashValueSerializer">  
      <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>   
    </property> 
   </bean> 
  
  
</beans>

上文中使用到的配置文件 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個(gè)關(guān)鍵的接口如下

private ValueOperations<K, V> valueOps;

private ListOperations<K, V> listOps;

private SetOperations<K, V> setOps;

private ZSetOperations<K, V> zSetOps;

分別對(duì)應(yīng)redis的數(shù)據(jù)類型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合)

具體使用如下,上代碼:

//添加字符串
ValueOperations<String, String> value = this.redisTemplate.opsForValue();
value.set("hello", "討厭");
System.out.println(value.get("hello"));


//添加 一個(gè) hash集合
HashOperations<String, Object, Object>  hash =redisTemplate.opsForHash();
hash.put("沃爾瑪","水果", "蘋果");
hash.put("沃爾瑪","飲料", "紅牛");
System.out.println(hash.entries("沃爾瑪"));


//添加一個(gè)list 集合
ListOperations<String, Object> list = redisTemplate.opsForList();
list.rightPush("課程", "chinese");
list.rightPush("課程", "englise");
System.out.println(list.range("lpList", 0, 1));


//添加 一個(gè) 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使用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:spring如何整合redis使用
瀏覽地址:http://aaarwkj.com/article30/iipspo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站商城網(wǎng)站、、微信小程序、關(guān)鍵詞優(yōu)化自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
欧美一区二区三区日韩色| 国产91日韩欧美在线观看| 精品亚洲国产成人av| 精品亚洲国产成人av| 高清中文一区二区三区| 日韩毛片免费看美日韩毛片| 久久精品国产亚洲av高清一区| 91色综合久久久久婷婷| 国产伦理在线观看一区二区| 欧美日韩黄片免费在线观看| 久久伊人亚洲精品中文字幕| 国产精品一区二区剧情熟女| 天堂网av高清在线播放| 日本免费一区二区三区手机在线 | 亚洲国际精品女人乱码| 国产精品久久久久久久久| 国产成人综合精品久久| 欧美日韩亚洲国产激情| 日韩一区二区三级电影| 日本高清不卡在线播放| 国产亚洲一区二区日韩欧美 | 国产三级传媒视频在线观看| 国产成人精品久久性色av| 韩国av高清在线观看| 成人深夜免费观看视频| 欧美日韩一区二区综合性色| 日韩中文免费av一区| 欧美一区二区成人精品视频| av在线播放网址网站| 亚洲欧美日韩颜射极品| 久久最新视频中文字幕| 日本亚洲中文字幕无吗| 亚洲伦理在线一区二区| 久久国产精品一区免费观看| 在线视频网友自拍偷拍| 国产乱av一区二区三区| 国产亚洲欧美日韩各类| 丰满熟女人妻中文字幕免费| 亚洲男人的av天堂生活| 亚洲国产精品久久久精品| 日韩伦理高清在线观看|