redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream. at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:198) at redis.clients.util.RedisInputStream.read(RedisInputStream.java:180) at redis.clients.jedis.Protocol.processBulkReply(Protocol.java:158) at redis.clients.jedis.Protocol.process(Protocol.java:132) at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:183) at redis.clients.jedis.Protocol.process(Protocol.java:134) at redis.clients.jedis.Protocol.read(Protocol.java:192) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:282) at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:227) at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:108) at redis.clients.jedis.JedisPubSub.proceedWithPatterns(JedisPubSub.java:95) at redis.clients.jedis.Jedis.psubscribe(Jedis.java:2513) at BenchRedisConsumer$BenchRunner.run(BenchRedisConsumer.java:208) at java.lang.Thread.run(Thread.java:745)
在作一個項目的API時候 ,用redis來作一些驗證操做,操做是至關的頻繁,常常無故端地爆出上述的異常,最後在 https://github.com/xetorthio/jedis/issues/965 找到一個相對靠譜的答案java
Yes :) I guess my problem is solved. I'm gonna write what I did to solve it for those who would get this issue too: call close() to return the Jedis instance to the pool (do not call returnResource()) catch JedisConnectionException for each Jedis command, and retrieve a new Jedis instance from the pool for the next Jedis commands to work (in the catch clause) Change the timeout (in JedisPool constructor), because in my case, I retrieve a new Jedis instance at the beginning of the request and I return it at the end of the request. Because a request may last more than 2 seconds (not optimized code yet), the timeout needed to be greater Change the pool max clients, but it must be lower than the redis maxclients in redis configuration Change the pool max idle clients Set testOnBorrow, testOnReturn and testWhildIdle to true for the JedisPool so that the connection to redis is validated often enough to avoid connection issues (all of these test methods may not be necessary but I used all of them and it works) Thank you very much once again @marcosnils and @HeartSaVioR for your help, your patience and your time!git
其實這個項目rw操做的次數對redis應該是小菜一碟吧,可是可能在代碼層面上作得不夠好,暫且記錄下來,往後解決了再來完善github