redis采用fastjson序列化方式
package com.wangbiao.security.config;
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @date 2022 年 10 15 日 21:33
* @description: redis配置Key value 序列化方式
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<Object,Object>redisTemplate(RedisConnectionFactory redisConnection){
RedisTemplate<Object,Object> template=new RedisTemplate();
template.setConnectionFactory(redisConnection);
FastJsonRedisSerializer fastJsonRedisSerializer=new FastJsonRedisSerializer(Object.class);
//key 采用StringRedisSerializer
template.setKeySerializer(new StringRedisSerializer());
//value采用 fastJsonRedisSerializer
template.setValueSerializer(fastJsonRedisSerializer);
//hashkey采用 StringRedisSerializer
template.setHashKeySerializer(new StringRedisSerializer());
//ashValue 采用fastJsonRedisSerializer
template.setHashValueSerializer(fastJsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}
本文来自博客园,作者:余生请多指教ANT,转载请注明原文链接:https://www.cnblogs.com/wangbiaohistory/p/16819787.html

浙公网安备 33010602011771号