开发手记:JedisConnectionException: Could not get a resource from the pool

对于Redis,生产环境是集群模式,测试环境是单例模式,如果在生产环境中用单例模式会报错。

解决办法,通过云配置,将配置进行自动化配置。

另附一份Redis配置:

#*********************Redis单节点配置************************
# Redis服务器地址
spring.redis.host=10.5.172.67
# Redis服务器连接端口
spring.redis.port=7006  

#*********************RedisCluster集群配置************************
# Redis服务器地址
spring.redis.hosts=10.30.10.169:6379,10.30.10.170:6379,10.30.10.171:6379,10.30.10.169:6380,10.30.10.170:6380,10.30.10.171:6380
# 读取超时时间(毫秒),源码:JedisConnectionFactory中在jedisCluster中设置的和timeout连接超时是一致的。
#         return StringUtils.hasText(getPassword())
#                ? new JedisCluster(hostAndPort, timeout, timeout, redirects, password, poolConfig)
#                : new JedisCluster(hostAndPort, timeout, redirects, poolConfig); 
spring.redis.sotimeout=1000  
# 最大重试次数
spring.redis.maxAttempts=2  
#集群间最大跳转次数,如果不设置maxRedirects值,源码中默认为5。一般当此值设置过大时,容易报:Too many Cluster redirections
#源码是在JedisConnectionFactory中设置的new JedisCluster(hostAndPort, timeout, timeout, redirects, password, poolConfig) 
spring.redis.maxRedirects=5

#*********************Redis通用配置************************
# Redis服务器连接密码(默认为空)
spring.redis.password=  hol@123456
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8  
# 连接池最大阻塞等待时间(使用负值表示没有限制),单位毫秒
spring.redis.pool.max-wait=-1  
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8  
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=1  
# 连接池中逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
spring.redis.pool.min-evictableIdleTimeMillis=1800000  
# 连接超时时间(毫秒)
spring.redis.timeout=1000  
# redis cacheManager过期时间,单位秒,默认为0,代表永不过期
spring.redis.cacheManager.expire = 86400

 

posted @ 2018-02-03 11:53  gudi  阅读(1043)  评论(0编辑  收藏  举报