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;
    }
}
posted @ 2022-11-04 10:41  yangruomao  阅读(586)  评论(0编辑  收藏  举报