jedis连接集群报Could not get a resource from the pool错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jedis连接集群报Could not get a resource from the pool错误相关的知识,希望对你有一定的参考价值。

参考技术A Caused by: org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
at org.springframework.data.redis.connection.jedis.JedisClusterConnection.convertJedisAccessException(JedisClusterConnection.java:3999)
at org.springframework.data.redis.connection.jedis.JedisClusterConnection.setEx(JedisClusterConnection.java:717)
at org.springframework.data.redis.core.DefaultValueOperations 11.doInRedis(DefaultValueOperations.java:186)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:182)
at io.renren.common.utils.SuppleDataUtils.provideIcc(SuppleDataUtils.java:107)
at io.renren.modules.job.task.TaskIcc.taskFour(TaskIcc.java:242)
... 10 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
at redis.clients.jedis.JedisClusterCommand.runBinary(JedisClusterCommand.java:60)
at redis.clients.jedis.BinaryJedisCluster.setex(BinaryJedisCluster.java:268)
at org.springframework.data.redis.connection.jedis.JedisClusterConnection.setEx(JedisClusterConnection.java:715)
... 18 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 28 common frames omitted
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 35 common frames omitted

最近在本地测试通过springboot基础redis的方式连接redis集群,启动的时候没有报错。
到时当执行保存,查询到redis的操作的时候,报上面的错误。
首先看到错误信息,先是connect timed out后,再出现的Could not get a resource from the pool错误。一开始排查这个错误,由于使用的是默认连接池,debug的时候,也看到有装载连接池,为啥报错呢。本地通过redis-manger工具,连接集群地址也可以连接访问。从日志也看不出还有其他的错误信息。
于是自己写了main方法直接操作JedisCluster的方式来测试,出现的错误跟上面全文一样。用抓包工具wireshark过滤集群的地址,查看连接的消息也是正常的。

另外一个项目使用的reddison客户端,于是测试了deamo用reddison来连接集群地址,启动的时候,发现报如下错误

乖乖,恍然大悟;10.287.17.31地址是服务器的内网地址,本机是连不上内网地址的,只有通过外网地址连接。而我配置的是外网地址。然而,客户端在集群同步和心跳检查的时候,是拉取的集群信息,redis集群信息里面的节点的信息
配置的是内网地址。客户端就通过这个内网地址来同步信息了。

再次同wireshark过滤集群10.287.17.31,发现有大量的超时重传的包,也没有响应。

jedis 连接 redis:Could not get a resource from the pool——我的出错原因和解决办法

 windows 下安装的,本机使用

现象:刚装好开发使用好好的, 重启电脑后就报这个错

网上的所有可能都试过,没有用。

最后,放弃所有包装,用最原始的代码进行连接测试:

Jedis jedis=new Jedis("127.0.0.1");
jedis.auth("7777");//password
jedis.set("firstKey", "hello redis!");

ERR Client sent AUTH, but no password is set

于是,重新设置密码:

redis 127.0.0.1:6379> CONFIG SET requirepass "123456"
OK
redis 127.0.0.1:6379> AUTH 123456
Ok

问题解决!!!

可是,我之前明明设置了密码的,为什么一重启密码就不起作用了呢?

于是,关掉服务器,再打开,重新跑了一下测试代码,玛尼???这个错误又出来啦!!!

参见:

http://blog.csdn.net/rchm8519/article/details/48347797

 

以上是关于jedis连接集群报Could not get a resource from the pool错误的主要内容,如果未能解决你的问题,请参考以下文章

jedis 连接 redis:Could not get a resource from the pool——我的出错原因和解决办法

连接远程的redis 集群报Could not get a resource from the pool异常

JedisCluster连接redis集群一直报Could not get a resource from the pool

java 连接 redis集群时报错:Could not get a resource from the pool

redis.clients.jedis.exception.JedisConnectionException:Could not get a resource from the pool

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool(示例代码