我使用 spring-data-redis(2.1.5.RELEASE) 和 jedis(2.10.2) 客户端从作为 spring-boot 应用程序运行的不同服务连接到我的 azure redis 实例。
通过实现以下配置,两个服务具有相同的缓存方法并指向相同的缓存。我面临的问题是,当一个服务尝试读取另一服务创建的缓存值时,会发生反序列化异常。
例外:
org.springframework.data.redis.serializer.SerializationException:无法反序列化;嵌套异常是 org.springframework.core.serializer.support.SerializationFailedException:无法反序列化有效负载。字节数组是DefaultDeserializer相应序列化的结果吗?嵌套异常是 org.springframework.core.NestedIOException:无法反序列化对象类型;嵌套异常是 java.lang.ClassNotFoundException
注意:我仅使用 redis 来缓存从数据库读取的数据。
public RedisCacheWriter redisCacheWriter(RedisConnectionFactory connectionFactory) {
return RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
}
@Bean
public RedisCacheManager cacheManager() {
Map<String, RedisCacheConfiguration> cacheNamesConfigurationMap = new HashMap<>();
cacheNamesConfigurationMap.put("employers", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(90000)));
cacheNamesConfigurationMap.put("employees", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(90000)));
RedisCacheManager manager = new RedisCacheManager(redisCacheWriter(), RedisCacheConfiguration.defaultCacheConfig(), cacheNamesConfigurationMap);
manager.setTransactionAware(true);
manager.afterPropertiesSet();
return manager;
}
Run Code Online (Sandbox Code Playgroud)
public RedisCacheWriter redisCacheWriter(RedisConnectionFactory connectionFactory) {
return RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
}
@Bean
public RedisCacheManager cacheManager() {
Map<String, RedisCacheConfiguration> cacheNamesConfigurationMap = new HashMap<>();
cacheNamesConfigurationMap.put("employees", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(90000)));
RedisCacheManager manager …Run Code Online (Sandbox Code Playgroud)