且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Data Redis JedisConnectionException:流的意外结束

更新时间:2021-11-21 22:02:05

我们已经能够重现该问题,原因是Redis中的"timeout = 30"设置.

We have been able to reproduce the issue and the cause is "timeout=30" setting in Redis.

  1. 连接空闲30秒,Redis杀死该连接.
  2. 应用程序中的"Redis连接工厂"检测到损坏之前 连接,它将为读取或写入请求分配
  3. 代码 尝试使用此连接,但由于它已断开,因此无法 发送命令以进行读/写.因此,我们得到"JedisConnectionException: 流意外结束"异常
  1. Connection is idle for 30seconds and Redis kills the same.
  2. Before "Redis connection factory" in application detects the broken connection, it gets allocation for read or write request
  3. Code tries to use this connection but as it is broken, it is unable to send command for read/write. Thus we get "JedisConnectionException: Unexpected end of stream" exception

解决方案

  1. 将Redis超时设置为零
  2. 使用自定义JedisPoolConfig集 将minEvictableIdleTimeMillis设置为所需值.这将确保 空闲连接从Jedis连接池中释放
  1. set Redis timeout to Zero
  2. Using custom JedisPoolConfig set the minEvictableIdleTimeMillis to desired value. This will ensure idle connections are released from Jedis connection pool