redis 使用 jackson | fastjson 序列化
redis 使用 jackson | fastjson 序列化
我默认提供了fastjson序列化,jackson看看注释就好了,很简单
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
// 如果要是用jackson序列化,把下面两行改成 new GenericJacksonxxxxx() 即可
template.setValueSerializer(new GenericFastJsonRedisSerializer());
template.setKeySerializer(new GenericFastJsonRedisSerializer());
template.afterPropertiesSet();
return template;
}
}