redis不能获取连接,Could not get a resource from the pool

最近线上无缘无故出现了 redis不能获取连接,整理了具体的排查思路

1.首先线上报错信息如下:

Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool

 

 二..定位问题

首先我们看了一下redis服务器的连接信息

1.执行 redis-cli -h 127.0.0.1 -p 6379 连接redis客户端

2.info

查询redis的相关信息

3.CONFIG GET maxclients

获取当前redis的最大客户端连接

4.info clients

获取redis当前客户

 

 

 

此时我们看到这个客户端连接607数据明显是不在正常范围内的

5.我们去服务器端服务器执行 netstat -nat  |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20  查询根据ip排序查询当前的连接数,此时发现redis这个ip的连接有600条

 

 至此我们大概能猜出大概率是我们内部redis连接配置有问题导致的 这个时候我们回到代码本身去查看redis相关配置信息

 

 这个配置更加的验证了是我们代码执行连接没有正常释放导致的这个问题

经过代码排查后定位到了redis配置有这一行代码

 

 开启redis事务,这行代码 对我们来说 经过查找发现 如果添加这行配置他不会手动释放连接,所以注释该行代码,重新打包后得到了顺利解决

 

posted @ 2021-09-08 10:45  未来有熊  阅读(10295)  评论(0编辑  收藏  举报