Skip to content

Spring Data Redis JedisConnectionException: Unexpected end of stream

Redis 3.0.5
Spring Data Redis 1.3.6
jedis 2.6.3
– Our is web application which receives data from redis over pub/sub.
– Also performs read/write of data on redis as key/value pairs.
– read/write happens on listener thread, independent monitoring thread and http request threads.
– We have used a same connection factory for Listener and redis template
– Our redis server has “timeout=30” configured

<bean id="jedisConnectionFactory"
    <property name="hostName" value="nnnn"></property>
    <property name="port" value="nnnn"></property>
    <property name="password" value="****"></property>
<bean id="redisTemplate" class="">
    <property name="connectionFactory" ref="jedisConnectionFactory" />
<bean id="redisContainer"
    <property name="connectionFactory" ref="jedisConnectionFactory" />
    <property name="messageListeners">
            <entry key-ref="messageListener">
                <bean class="">
                    <constructor-arg value="topic_name" />
    <property name="taskExecutor" ref="redisTaskExecutor" />
    <property name="subscriptionExecutor" ref="redisSubTaskExecutor" />
<bean id="redisTaskExecutor"
    <property name="threadNamePrefix" value="RedisListenerThread"></property>
    <property name="corePoolSize" value="1" />
    <property name="maxPoolSize" value="1" />
<bean id="redisSubTaskExecutor"
    <property name="threadNamePrefix" value="RedisSubscribeThread"></property>
    <property name="corePoolSize" value="1" />
    <property name="maxPoolSize" value="1" />
<bean id="messageListener"
    <constructor-arg index="0">
        <bean class="" />
    <constructor-arg index="1"><value>receive</value></constructor-arg>

occasionally we face below problem on production during data read. Unexpected end of stream.; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream. at at at at at at at at$1.inRedis( at$ValueDeserializingRedisCallback.doInRedis( at at at at

I have read other threads talking of using single thread for read/write. But in our case it is difficult to use single thread. Also as per RedisTemplate documentation, it is thread safe. The problem is occasional and we are unable to reproduce in any of dev/testing/uat environment. Thus unable to find exact cause of the same. What have we done wrong?


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


  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. 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