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; } }
标签:fastjson,redis,springframework,StringRedisSerializer,template,org,import,序列化 From: https://www.cnblogs.com/wangbiaohistory/p/16819787.html