Could not get a resource from the pool 异常定位和解决

发布时间 2023-12-17 16:57:57作者: 香吧香

  最近在服务中经常看到以下错误,进行下定位和问题解决分析:

2023-12-08 00:10:58.248  WARN [terra-sr-server,a9006fd27ccb81d0,a9006fd27ccb81d0,false] 52 --- [o-14009-exec-38] o.s.b.a.redis.RedisHealthIndicator       : Redis health check failed

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

  

  这个异常 org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool 表示应用程序无法从连接池中获取一个 Redis 连接。这可能是因为连接池已经耗尽,或者 Redis 服务器无法接受更多的连接。

  解决这个问题的方法是首先确定 Redis 服务器的状态,然后检查应用程序的 Redis 连接配置。

1.登录redis,并查看最大连接数:

redis-cli -h 127.0.0.1 -p 6379
config get maxclients

                   

 2.info 查询redis信息:

info

                           

 3.服务器端服务器执行以下命令,查看连接数

netstat -nat  |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20 

         

         注:忽略上图的数据,截图时问题已经修复,截图只是为了查看命令返回的数据和格式

4.最终解决结果

  在项目中配置的redis最大连接数是100,调整了项目中reids的最大连接数之后 异常便得以解决。