We are using RedisTemplate to get all the keys from a Redis cache. We are using "scan" to get all the keys. We don't use directly Lettuce or Jedis, we let RedisTemplate to do it.
When we configure RedisTemplate to use Lettuce, the scan command returns all the keys. When we configure RedisTemplate to use Jedis, something is wrong and we are seeing the following Exception:
05-20@22:40:01 ERROR ( MyCache.java:58) - Exception
org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:82)
at test.MyCache.deserializeKeys(MyCache.java:70)
at test.MyCache.getKeys(MyCache.java:52)
at test.RedisApp.main(RedisApp.java:54)
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:78)
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:36)
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:80)
... 3 more
Caused by: java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301)
at org.springframework.core.ConfigurableObjectInputStream.<init>(ConfigurableObjectInputStream.java:63)
at org.springframework.core.ConfigurableObjectInputStream.<init>(ConfigurableObjectInputStream.java:49)
at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:68)
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:73)
... 5 more
We wanted to ilustrate the problem with a complete example, so we have created a sample project on GitHub https://github.com/michaelweber2/redis-app . This project is using Java 8, Maven (3+), Spring Data Redis (1.8.3.RELEASE), Lettuce (4.3.1.Final) and Jedis (2.9.0). This project was tested with Redis server 3.2.9.
So the question is why do we get this Exception only when we configure RedisTemplate to use Jedis and what can we do to make Jedis work?