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