redis使用问题一:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool] with root cause

首先说下redis最简单得使用,出去配置。

需要在你要使用得缓存得地方,例如mybatis在mapper.xml中加入:

<cache eviction="LRU" type="cn.jbit.cache.RedisCache"/>

由于是第一次使用redis,再调试代码得时候报错:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool] with root cause

无法获得redis的链接。

后来重新配置了redis连接池得参数:

#最大空闲数,数据库连接的最大空闲时间。超过空闲数量,数据库连接将被标记为不可用,然后被释放。设为0表示无限制
redis.maxIdle=50
#最大连接数:能够同时建立的“最大链接个数”#jedis的最大活跃连接数设为0表示无限制
redis.maxActive=50
#最大等待时间:单位ms
#jedis池没有连接对象返回时,等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。
#如果超过等待时间,则直接抛出JedisConnectionException
redis.maxWait=1000
##############################问题注解#############################
##
注解:运行报错:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException:
Could not get a resource from the pool] with root cause

maxActive是最大激活连接数,这里取值为50,表示同时最多有50个数据连 接。maxIdle是最大的空闲连接数,这里取值为50,
表示即使没有数据库连接时依然可以保持20空闲的
连接,而不被清除,随时处于待命状态。MaxWait是最大等待秒钟数,这里取值-1,
表示无限等待,直到超时为止,也可取值9000,表示9秒后超时。
而自己开始的设置是:redis.maxIdle=10 redis.maxActive=50
#########################################################################
 
 

猜你喜欢

转载自www.cnblogs.com/zeussbook/p/9033222.html