使用spring-data-redis2.x版本时,@Cacheable缓存key值时默认会给vlue或cacheNames后加上双引号
通过配置进行修改即可满足项目需求
@Configuration
public class SpringCacheConfig{
@Bean
public CacheManager cacheManager(LettuceConnectionFactory lettuceConnectionFactory){
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofHour(1)
//变双冒号为单冒号
.computePrefixWith(name - >":")
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
.disableCachingNullValues();
RedisCacheManager cacheManager = RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(lettuceConnectionFactory)
.cacheDefaults(config)
.transactionAware()
.build();
return cacheManager;
}
...其他配置
}