jedis 的 Unexpected end of stream 解决方案
来源:互联网 发布:js正则表达式校验邮箱 编辑:程序博客网 时间:2024/05/23 20:07
jedis 的 Unexpected end of stream 解决方案
- redis 服务端版本号:2.8.X
- Jedis 客户端版本号:2.8.1
- 单线程、无并发操作
Jedis单链接、JedisPool、ShardedJedisPool,无论使用哪一种方式对 redis 服务进行操作,均出现了 Unexpected end of stream
的问题。
通过查看源码发现,报错具体位置是:RedisInputStream 类的 ensureFill() 方法
private void ensureFill() throws JedisConnectionException { if (count >= limit) { try { limit = in.read(buf); count = 0; if (limit == -1) { throw new JedisConnectionException("Unexpected end of stream."); } } catch (IOException e) { throw new JedisConnectionException(e); } } }
解决方案:
第一步,检查 redis config 中的 client-output-buffer-limit
配置
client-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 0 0 0client-output-buffer-limit pubsub 0 0 0
请根据实际情况合理设置Redis输出缓冲区限制,确定不是因为缓冲区太小,导致链接关闭,进而引起 Unexpected end of stream
,可以临时都设置成 “0(关闭缓冲区限制)” 来验证此种场景
第二步,检查 redis config 中的 timeout
配置
当此时间设置过短时,同一个 jedis 链接,两次访问 redis 服务的时间间隔 > ${timeout} , 服务端会单方关闭这个jedis链接,第二次使用这个jedis对象 操作 redis 时,会发生 Unexpected end of stream
, 可以将其设置成“0(无过期)”来验证此种场景
第三步,优化客户端代码,增加重试机制
经过前两步的调试,根据业务实际情况,调整配置,但这样并不能完全杜绝 Unexpected end of stream
的发生,比如 “网络抖动”之类的场景下,依然会发生此问题(实际生产环境中,此种情况发生概率极低),
但是为了防止此异常引起 jvm宕机,建议在代码层面上增加加重试机制。
话外篇:
使用 redis 做存储层时,有可能出现数数据不一致的情况( redis 无事务)
参考:
https://github.com/xetorthio/jedis/issues/932
https://github.com/xetorthio/jedis/issues/1029
2 0
- jedis 的 Unexpected end of stream 解决方案
- redis报错:jedis connection exception unexpected end of stream
- Unexpected end of stream.
- android: unexpected end of stream
- onFailure unexpected end of stream
- Unexpected end of ZLIB input stream的解决办法
- okhttp的坑坑坑 unexpected end of stream on Connection
- Android Download: unexpected end of stream
- JAVA_SAE_Fatal_error: Unexpected end of ZLIB input stream
- Unexpected end of ZLIB input stream
- java.io.IOException: unexpected end of stream
- java.net.ProtocolException: unexpected end of stream
- unexpected end of stream on okhttp3.
- 总结okhttp的错误IOException: unexpected end of stream on okhttp3的解决办法
- 使用GZIPOutputStream解压byte[]出现Unexpected end of ZLIB input stream的解决方法
- java.io.EOFException: Unexpected end of ZLIB input stream
- unexpected end of stream on okhttp3.Address 错误原因
- java.io.EOFException: Unexpected end of input stream
- java代码:new 类名(){方法定义}应该如何理解?
- 丢失控制文件恢复
- trie树的实现和应用及测试
- maven安装总结
- Statistical learning Week 1 什么是统计学习?
- jedis 的 Unexpected end of stream 解决方案
- 第8章 Spring Boot的数据访问
- JavaScript基础系列8---BOM操作
- eclipse git 报 git: 401 Unauthorized 解决办法
- 三国轶事--巴蜀之危 排列组合
- ubuntu常用软件包deb的安装与卸载
- 【POJ 2396】 Budget 带上下界网络流 解题报告
- 让你快速学习python基础笔记002(一起动手实践)
- Redis