最近線上無緣無故出現了 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事務,這行代碼 對我們來說 經過查找發現 如果添加這行配置他不會手動釋放連接,所以注釋該行代碼,重新打包后得到了順利解決