jedis Unexpected end of stream. 错误

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 找到一个相对靠谱的答案

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!

 

其实这个项目rw操作的次数对redis应该是小菜一碟吧,但是可能在代码层面上做得不够好,暂且记录下来,日后解决了再来完善

转载于:https://my.oschina.net/u/1789379/blog/752965

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值