Redis報錯:redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
問題描述:
在阿里雲linux服務器上(最便宜的那種。。。),使用redis緩存實現點贊功能報錯,由於對redis不夠深入以為是配置文件的問題,忽略了代碼。。
異常信息:
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out at redis.clients.jedis.Protocol.process(Protocol.java:79) at redis.clients.jedis.Protocol.read(Protocol.java:131) at redis.clients.jedis.Connection.getIntegerReply(Connection.java:188) at redis.clients.jedis.Jedis.sismember(Jedis.java:1266)
問題解決:
使用完jedis之后執行close()
事例:
public String set(String key, String value) { // TODO Auto-generated method stub Jedis jedis =jedisPool.getResource(); String result =jedis.set(key, value); jedis.close(); return result; } @Override public String get(String key) { // TODO Auto-generated method stub Jedis jedis =jedisPool.getResource(); String result =jedis.get(key); jedis.close(); return result; }
注:每次使用完就close掉,jedisPool不關閉,否則就會報錯,無法獲取資源
