Could not get a resource from the pool 异常定位和解决
最近在服务中经常看到以下错误,进行下定位和问题解决分析:
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-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
注:忽略上图的数据,截图时问题已经修复,截图只是为了查看命令返回的数据和格式