转载

Spring Boot redis连接池配置,Spring Session配置

1.POM配置

[html] view plain copy
<embed id="ZeroClipboardMovie_1" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_7" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_7" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=7&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. <!--  redis -->  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        <dependency>  
  3.             <groupId>redis.clients</groupId>  
  4. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            <artifactId>jedis</artifactId>  
  5.             <version>2.9.0</version>  
  6. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        </dependency>  
  7.         <!--  spring-session -->  
  8. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">         <dependency>  
  9.             <groupId>org.springframework.session</groupId>  
  10. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            <artifactId>spring-session-data-redis</artifactId>  
  11.         </dependency>  
  12. </libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:>


2.配置文件application.properties

[html] view plain copy
<embed id="ZeroClipboardMovie_2" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_2" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_8" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_8" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=8&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. # REDIS (RedisProperties)  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># Redis数据库索引(默认为0)  
  3. spring.redis.database=0  
  4. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># Redis服务器地址  
  5. spring.redis.host=localhost  
  6. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># Redis服务器连接端口  
  7. spring.redis.port=6379  
  8. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># Redis服务器连接密码(默认为空)  
  9. spring.redis.password=admin  
  10. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># 连接池最大连接数(使用负值表示没有限制)  
  11. spring.redis.pool.max-active=8  
  12. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># 连接池最大阻塞等待时间(使用负值表示没有限制)  
  13. spring.redis.pool.max-wait=-1  
  14. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># 连接池中的最大空闲连接  
  15. spring.redis.pool.max-idle=8  
  16. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># 连接池中的最小空闲连接  
  17. spring.redis.pool.min-idle=0  
  18. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""># 连接超时时间(毫秒)  
  19. spring.redis.timeout=0  
  20. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">#spring-session 使用  
  21. spring.session.store-type=none  
  22. </libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:>


3.redis链接池配置属性

[html] view plain copy
<embed id="ZeroClipboardMovie_3" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_3" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_9" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_9" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=9&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. package com.config;  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  3. import org.slf4j.Logger;  
  4. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import org.slf4j.LoggerFactory;  
  5. import org.springframework.beans.factory.annotation.Value;  
  6. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import org.springframework.cache.annotation.CachingConfigurerSupport;  
  7. import org.springframework.context.annotation.Bean;  
  8. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import org.springframework.context.annotation.Configuration;  
  9. import org.springframework.session.data.redis.config.ConfigureRedisAction;  
  10. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import redis.clients.jedis.JedisPool;  
  11. import redis.clients.jedis.JedisPoolConfig;  
  12. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  13. /**  
  14. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""> * Created by Administrator on 2017/5/9.  
  15.  */  
  16. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">@Configuration  
  17. public class RedisConfig extends CachingConfigurerSupport {  
  18. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    Logger logger = LoggerFactory.getLogger(RedisConfig.class);  
  19.   
  20. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    /**  
  21.      * SpringSession  需要注意的就是redis需要2.8以上版本,然后开启事件通知,在redis配置文件里面加上  
  22. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">     * notify-keyspace-events Ex  
  23.      * Keyspace notifications功能默认是关闭的(默认地,Keyspace 时间通知功能是禁用的,因为它或多或少会使用一些CPU的资源)。  
  24. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">     * 或是使用如下命令:  
  25.      * redis-cli config set notify-keyspace-events Egx  
  26. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">     * 如果你的Redis不是你自己维护的,比如你是使用阿里云的Redis数据库,你不能够更改它的配置,那么可以使用如下方法:在applicationContext.xml中配置  
  27.      * <util:constant static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>  
  28. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">     * @return  
  29.      */  
  30. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    @Bean  
  31.     public ConfigureRedisAction configureRedisAction() {  
  32. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        return ConfigureRedisAction.NO_OP;  
  33.     }  
  34. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  35.     @Value("${spring.redis.host}")  
  36. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    private String host;  
  37.   
  38. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    @Value("${spring.redis.port}")  
  39.     private int port;  
  40. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  41.     @Value("${spring.redis.timeout}")  
  42. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    private int timeout;  
  43.   
  44. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    @Value("${spring.redis.pool.max-idle}")  
  45.     private int maxIdle;  
  46. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  47.     @Value("${spring.redis.pool.max-wait}")  
  48. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    private long maxWaitMillis;  
  49.   
  50. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    @Value("${spring.redis.password}")  
  51.     private String password;  
  52. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  53.     @Bean  
  54. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    public JedisPool redisPoolFactory() {  
  55.         logger.info("JedisPool注入成功!!");  
  56. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        logger.info("redis地址:" + host + ":" + port);  
  57.         JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();  
  58. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        jedisPoolConfig.setMaxIdle(maxIdle);  
  59.         jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);  
  60. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  61.       JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);  
  62. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        //   JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);   //无密码情况  
  63.         return jedisPool;  
  64. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    }  
  65. }  
  66. </libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:>


redis工具类

[html] view plain copy
<embed id="ZeroClipboardMovie_4" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_4" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_10" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_10" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=10&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. package com.util;  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import org.springframework.beans.factory.annotation.Autowired;  
  3. import org.springframework.stereotype.Component;  
  4. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">import redis.clients.jedis.Jedis;  
  5. import redis.clients.jedis.JedisPool;  
  6. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  7. /**  
  8. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"=""> * Created by Administrator on 2017/5/9.  
  9.  */  
  10. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">@Component("redisClient")  
  11. public class RedisClient {  
  12. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    @Autowired  
  13.     private JedisPool jedisPool;  
  14. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  15.     public void set(String key, String value) throws Exception {  
  16. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        Jedis jedis = null;  
  17.         try {  
  18. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            jedis = jedisPool.getResource();  
  19.             jedis.set(key, value);  
  20. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        } finally {  
  21.             //返还到连接池  
  22. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            jedis.close();  
  23.         }  
  24. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    }  
  25.   
  26. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    public String get(String key) throws Exception  {  
  27.   
  28. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        Jedis jedis = null;  
  29.         try {  
  30. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            jedis = jedisPool.getResource();  
  31.             return jedis.get(key);  
  32. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">        } finally {  
  33.             //返还到连接池  
  34. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">            jedis.close();  
  35.         }  
  36. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">    }  
  37.   
  38. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">  
  39. }  
  40. </libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:>


redis应用

[html] view plain copy
<embed id="ZeroClipboardMovie_5" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_5" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_11" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_11" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=11&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. redisClient.set("redis_key", "abc");  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">String value=redisClient.get("redis_key");  
  3. logger.info("redis_key value:{}", value);  
  4. </libox-sizing:>




4.application 添加启用springsession注解

@EnableRedisHttpSession //spring session
和session一样正常使用即可
[html] view plain copy
<embed id="ZeroClipboardMovie_6" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_6" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=6&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
<embed id="ZeroClipboardMovie_12" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="17" height="16" name="ZeroClipboardMovie_12" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=12&width=17&height=16" wmode="transparent" style="outline: 0px; word-break: break-all;">
  1. @RequestMapping("/setSession")  
  2. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">   public String setSession(HttpServletRequest request) throws Exception {  
  3.        request.getSession().setAttribute("user", "message");  
  4. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">       return null;  
  5.    }  
  6. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">   @RequestMapping("/getSession")  
  7.    public String getSession(HttpServletRequest request) throws Exception {  
  8. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">      String message= (String)request.getSession().getAttribute("user");  
  9.        logger.info("spring Session message:{}", message);  
  10. <libox-sizing: border-box;="" outline:="" 0px;="" padding:="" 0px="" 3px="" 10px="" !important;="" margin-top:="" 8px;="" margin-right:="" margin-bottom:="" margin-left:="" 40px;="" border-top:="" none;="" border-right:="" border-bottom:="" border-left:="" solid="" rgb(108,="" 226,="" 108);="" border-image:="" initial;="" list-style-type:="" decimal;="" list-style-image:="" background-color:="" rgb(248,="" 248,="" 248);="" color:="" rgb(92,="" 92,="" 92);="" line-height:="" 20px;="" list-style-position:="" outside="" word-break:="" break-all;"="">       return null;  
  11.    }  
  12. </libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:></libox-sizing:>


正文到此结束
Loading...