redis使用问题一:Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool] with root cause
本文使用的是spring-data-redis
首先说下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的链接。
方法1.重新配置了redis连接池得参数:需要按照自己缓存的数量而设置最大链接数。
- #最大空闲数,数据库连接的最大空闲时间。超过空闲数量,数据库连接将被标记为不可用,然后被释放。设为0表示无限制
- redis.maxIdle=50
- #最大连接数:能够同时建立的“最大链接个数”#jedis的最大活跃连接数设为0表示无限制,这个属性就是高版本的maxTotal
- 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,
- 表示无限等待,直到超时为止,一般取值3000,表示3秒后超时。
- 而自己开始的设置是:redis.maxIdle=10 redis.maxActive=50
- #########################################################################
- 如果问题继续存在
- 方法2.问题还是没解决,多次调试,发现链接资源没释放有关系,当然我的代码中是做了资源释放的。
先看poolConfig
- <!-- redis数据源 -->
- <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxIdle" value="${redis.maxIdle}" />
- <property name="maxTotal" value="${redis.maxActive}" />
- <property name="maxWaitMillis" value="${redis.maxWait}" />
- <property name="testOnBorrow" value="${redis.testOnBorrow}" />
- </bean>
- redis.properties文件配置
- #最大链接数
- redis.maxTotal=100
- #最大空闲数,数据库连接的最大空闲时间。超过空闲数量,数据库连接将被标记为不可用,然后被释放。设为0表示无限制
- redis.maxIdle=20
- ##jedis的最大活跃连接数设为0表示无限制
- redis.maxActive=100
- #最大等待时间:单位ms
- #jedis池没有连接对象返回时,等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。
- #如果超过等待时间,则直接抛出JedisConnectionException
- redis.maxWait=1000
- #使用连接时,检测连接是否成功
- redis.testOnBorrow=true
redis文件
- public void clear() {
- JedisConnection connection = null;
- try {
- connection = jedisConnectionFactory.getConnection();
- connection.flushDb();
- connection.flushAll();
- System.out.println("clear=redis======>");
- } catch (JedisConnectionException e) {
- connection.close();//释放链接
- e.printStackTrace();
- } finally {
- if (connection != null) {
- connection.close();//释放连接
- }
- }
- }
- 问题的主要原因是使用连接池的链接后没有释放资源,当然开始我的代码就释放了使用的链接资源,但是还是会出现链接资源拿不到的情况。
可能是因为异常没有释放链接资源,我这个getConnection()是使用的第三方静态注入依赖于ehcache,只需要在需要缓存的dao或者mapper
加入注解,即可缓存并同步刷新最新数据。不需要在业务层手动的set,update,remove数据。
如果是getResource()这种方式获取的redis链接,用returnToPool(jedis)或jedis.close()是可以解决问题的;
最让我们忽略的原因就是你的redis是山寨版集成的,从新手博客上直接copy被坑的不要不要的。要么用spring boot集成的redis要么集成原生的。
- 具体情况酌情处理
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.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
超时 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: jav ...
- ERR Unsupported CONFIG parameter: notify-keyspace-events; nested exception is redis.clients.jedis.exceptions.JedisDataException
异常信息 时间:2017-04-05 15:53:57,361 - 级别:[ WARN] - 消息: [other] The web application [ROOT] appears to hav ...
- redis报错:java.net.SocketException: Broken pipe (Write failed); nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe (Write failed)
最近写了一个服务通过springboot构建,里面使用了redis作为缓存,发布到服务器运行成功,但是有时候会报redis的错误:org.springframework.data.redis.Redi ...
- 记一次jedis并发使用问题JedisException: Could not return the resource to the pool
今天线上突然发现个奇怪的问题项目第一次启动的时候redis报错JedisException: Could not return the resource to the pool 直接访问接口的时候不报 ...
- Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
七月 17, 2014 4:56:01 下午 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service( ...
- jdbc连接oracle时报错 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableC
错误: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; ...
- Spring 整合Mybatis 出现了Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create Poola
我出现的 报错信息如下: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionExc ...
- 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver
运行项目rds_web时,出现错误提示:Could not get JDBC Connection; nested exception is java.sql.SQLException: No sui ...
- Could not get JDBC Connection; nested exception is java.sql.SQLException: ${jdbc.driver}
在一个SSM分布式项目中一个服务报错: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnec ...
随机推荐
- 洛谷P1123取数游戏题解
题目 这是一道简单的搜索题,考查的还是比较基础的东西,其时搜索有时候并不难写,主要是要想到怎么搜.比如这个题,如果想二维四个方向搜则没有头绪,反之因为搜索是用递归实现的,所以我们可以使用递归的特性,把 ...
- CODEFORCES掉RATING记 #5
比赛:Codeforces Round #429 (Div. 2) 时间:2017.8.1晚 这次感觉状态不好,就去打div2了 A:有\(26\)种颜色的气球,每种的数量不一样,你要把这 ...
- 【HDU 4343】Interval query(倍增)
BUPT2017 wintertraining(15) #8D 题意 给你x轴上的N个线段,M次查询,每次问你[l,r]区间里最多有多少个不相交的线段.(0<N, M<=100000) 限 ...
- dll 修复....
之前在安装时总是会碰到缺少什么dll文件,总是头疼的要命,这次很幸运的在网上搜到了这个神奇的小玩意,只需要运行就能够修复缺少的所有的dll文件,所以在这小小的分享一下. 链接:https://pan. ...
- 【洛谷2252&HDU1527】取石子游戏(博弈论)
题面 HDU1527 取石子游戏 洛谷2252 取石子游戏 题解 裸的威佐夫博弈 #include<iostream> #include<cmath> using namesp ...
- BUG关闭原因
已解决:缺陷已经修复. 重复缺陷:是指在系统里相同原因的缺陷已经被其他人报告.在此缺陷被作为重复缺陷返回时,先不要立即取消.必须等到核查修复后,才在系统里取消.这是因为有些缺陷被误认为是重复缺陷,实际 ...
- docker-compose.yml(1)
docker-compose 常用命令 Commands: build Build or rebuild services bundle Generate a Docker bundle from t ...
- [POI2008]KLO-Building blocks
题目描述 N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖,放到另一柱.仓库无限大. 现在希望用最小次数的动作完成任 ...
- A1144. The Missing Number
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- (转)每天一个linux命令(44):top命令
背景:在面试时候面试官问到关于linux服务器下内存优化的问题.自己之前可能接触过也没有深入总结过. top命令 每天一个linux命令(44):top命令