Tomcat配置如下
server.xml
在 GlobalNamingResources 标签中插入如下代码,注意 configPath 的路径
<Resource name="bean/redisson"
auth="Container"
factory="org.redisson.JndiRedissonFactory"
configPath="${catalina.base}/conf/redisson.json"
closeMethod="shutdown"/>
context.xml
在 Context 标签中插入如下代码,注意 configPath 的路径
<Manager className="org.redisson.tomcat.RedissonSessionManager"
configPath="${catalina.base}/conf/redisson.json"
readMode="REDIS" updateMode="DEFAULT" broadcastSessionEvents="false"/>
redisson.json
这个文件我是放在了 tomcat/conf 目录下
配置文件各个字段请参看
https://github.com/redisson/redisson/wiki/2.-%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95
{
"clusterServersConfig":{
"idleConnectionTimeout":10000,
"pingTimeout":1000,
"connectTimeout":10000,
"timeout":3000,
"retryAttempts":3,
"retryInterval":1500,
"reconnectionTimeout":3000,
"failedAttempts":3,
"password":null,
"subscriptionsPerConnection":5,
"clientName":null,
"loadBalancer":{
"class":"org.redisson.connection.balancer.RoundRobinLoadBalancer"
},
"slaveSubscriptionConnectionMinimumIdleSize":1,
"slaveSubscriptionConnectionPoolSize":50,
"slaveConnectionMinimumIdleSize":32,
"slaveConnectionPoolSize":64,
"masterConnectionMinimumIdleSize":32,
"masterConnectionPoolSize":64,
"readMode":"SLAVE",
"nodeAddresses":[
"redis://ip:端口",
"redis://ip:端口",
"redis://ip:端口",
"redis://ip:端口"
],
"scanInterval":1000
},
"threads":0,
"nettyThreads": 0,
"codec":{
"class":"org.redisson.codec.JsonJacksonCodec"
},
"transportMode":"NIO"
}
tomcat中添加jar包到 lib 目录下,具体请看
-
JDK 1.8+适用
redisson-all-3.6.4.jarTomcat 6.x适用 redisson-tomcat-6-3.6.4.jar
Tomcat 7.x适用 redisson-tomcat-7-3.6.4.jar
Tomcat 8.x适用 redisson-tomcat-8-3.6.4.jar
Tomcat 9.x适用 redisson-tomcat-9-3.6.4.jar -
JDK 1.6+适用
redisson-all-2.11.4.jarTomcat 6.x适用 redisson-tomcat-6-2.11.4.jar
Tomcat 7.x适用 redisson-tomcat-7-2.11.4.jar
Tomcat 8.x适用 redisson-tomcat-8-2.11.4.jar
亲测有效,附官方Github地址
https://github.com/redisson/redisson
本人前端,如有错漏,以官方为准,大牛轻喷~~