记一次redis客户端连接redis报错
Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
报错连接已满,进入发现实际连接只有十几个
查看redis服务器发现内存占用一直很高
跟开发同学沟通后,发现早期有写入redis的数据没有设置ttl
数据释放不出去导致redis占用内存越来越多 然后虚拟机上面内存占满了从而导致redis连接报错
解决办法:将以前的写入redis的数据清理掉,然后给开发的同学规范代码,写入redis中的数据必须设置ttl
// 模糊删除以import开头的key
// xargs后面必须接-r -n1 否则会清理失败
/usr/local/bin/redis-cli -c -h 10.0.0.1 -p 7000 -a test keys "import*"|xargs -r -n1 /usr/local/bin/redis-cli -c -h 10.0.0.1 -p 7000 -a test del