异常内容:
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.jedis.Protocol.process(Protocol.java:79) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Protocol.read(Protocol.java:131) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:182) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Connection.getBulkReply(Connection.java:171) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Jedis.lpop(Jedis.java:1090) ~[jedis-2.1.0.jar:na]
at zju.lzm.storm.spout.RedisReadSpout.nextTuple(RedisReadSpout.java:52) ~[bin/:na]
at backtype.storm.daemon.executor$eval5100$fn__5101$fn__5116$fn__5145.invoke(executor.clj:562) ~[na:na]
at backtype.storm.util$async_loop$fn__390.invoke(util.clj:433) ~[na:na]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.4.0.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_07]
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109) ~[jedis-2.1.0.jar:na]
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Protocol.process(Protocol.java:64) ~[jedis-2.1.0.jar:na]
... 9 common frames omitted
209206 [Thread-27-RedisReadSpout] ERROR backtype.storm.daemon.executor -
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.jedis.Protocol.process(Protocol.java:79) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Protocol.read(Protocol.java:131) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:182) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Connection.getBulkReply(Connection.java:171) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Jedis.lpop(Jedis.java:1090) ~[jedis-2.1.0.jar:na]
at zju.lzm.storm.spout.RedisReadSpout.nextTuple(RedisReadSpout.java:52) ~[bin/:na]
at backtype.storm.daemon.executor$eval5100$fn__5101$fn__5116$fn__5145.invoke(executor.clj:562) ~[na:na]
at backtype.storm.util$async_loop$fn__390.invoke(util.clj:433) ~[na:na]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.4.0.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_07]
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at java.net.SocketInputStream.read(Unknown Source) ~[na:1.7.0_07]
at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109) ~[jedis-2.1.0.jar:na]
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45) ~[jedis-2.1.0.jar:na]
at redis.clients.jedis.Protocol.process(Protocol.java:64) ~[jedis-2.1.0.jar:na]
... 9 common frames omitted
在java中使用Jedis进行Redis数据库的操作时,出现了这个超时的问题。
解决方法:在调用jedis的构造方法时,将超时时间设置的更大些。如:
Jedis jedis = new Jedis("127.0.0.1", 8371,100000);//将超时时间设置为100000毫秒这样足够大,便基本不会出现超时的问题了。
问题的剖析:
在jedis的默认构造方法中,超时的时间一般被默认设置为2000毫秒,也就是2秒。当然这个时间,对于Redis这种从内存中读取数据的数据库来说应该是相当大了,但是为什么还会超时?可能的原因是,当Redis的数据量很大时,可能在Redis server可能会出现超时。因为Redis在运行时,是单线程来处理所有的客户端的连接的。当连接数非常多或者数据量很大时,这也要遵循FIFO的调度策略。因此可能会出现超时的情况。
其他的误改:
jedis.configSet("timeout", "30");上面的方法是设置redis将会关闭超时超过30秒的空闲连接。而不是设置读取数据的超时时间。