问题
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
分析
Redis: 2.8.21
App: Java
采用的是AWS的ElastiCache服务,在Cloudwatch上观察服务状态,没有异常。每天有几百次的报错量。
并且通过以下方式在应用的机器上检测网络状态,没有明显问题。
>nc -v -w 1 xxxxx 6379
>ping -c 10 xxxxx
>while true; do echo -e "\n" ; date; redis-cli -h xxxxx -p 6379 time; sleep 1; done > /tmp/elc-check.txt 2>&1
可以推断为数据库连接问题。
解决方案
修改数据库连接配置
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
pool=new JedisPool(config,bundle.getString("redis.ip"),Integer.valueOf(bundle.getString("redis.port"),600);
相关参考
http://www.cnblogs.com/liuling/p/2014-4-19-04.html #参数
http://www.csdn123.com/html/mycsdn20140110/2c/2c1c08b73539bf13cc5384542a864d59.html
http://m.oschina.net/blog/406807
http://huoding.com/2015/09/14/463 #关于操作setnx
http://coder.beitown.com/archives/1235 #否是硬件及网络问题造成的
Wait for your reward