package com.lyd.springsecurity1.config;
import com.lyd.springsecurity1.utils.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.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
//固定模板
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
//String序列化
StringRedisSerializer serializer = new StringRedisSerializer();
//Json序列化
FastJsonRedisSerializer Jsonserializer = new FastJsonRedisSerializer(Object.class);
template.setKeySerializer(serializer);
template.setValueSerializer(Jsonserializer);
template.setHashKeySerializer(serializer);
template.setHashValueSerializer(Jsonserializer);
template.afterPropertiesSet();
return template;
}
}