当我们尝试使用Jedis客户端从扫描Redis缓存读取所有密钥时抛出异常

时间:2017-05-21 21:31:05

标签: java redis jedis spring-data-redis lettuce

我们正在使用RedisTemplate从Redis缓存中获取所有密钥。我们正在使用" scan"得到所有的钥匙。 我们不直接使用Lettuce或Jedis,我们让RedisTemplate来做。

当我们将RedisTemplate配置为使用Lettuce时,scan命令会返回所有键。 当我们将RedisTemplate配置为使用Jedis时,出现了问题,我们看到以下异常:

    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

我们希望通过一个完整的示例说明问题,因此我们在GitHub https://github.com/michaelweber2/redis-app上创建了一个示例项目。 该项目使用Java 8,Maven(3 +),Spring Data Redis(1.8.3.RELEASE),Lettuce(4.3.1.Final)和Jedis(2.9.0)。 该项目已使用Redis服务器3.2.9进行测试。

所以问题是为什么我们只有在配置RedisTemplate以使用Jedis时才能获得此异常,以及我们可以做些什么来使Jedis工作?

0 个答案:

没有答案