12月6號 解決redis亂碼問題
阿新 • • 發佈:2018-12-06
import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; importorg.springframework.data.redis.core.*; import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; @Configuration @Slf4j public class RedisConfig { @Autowiredprivate RedisConnectionFactory factory; @SuppressWarnings({ "rawtypes", "unused" }) private RedisTemplate redisTemplate; @SuppressWarnings({ "rawtypes", "unchecked" }) @Autowired(required = false) public void setRedisTemplate(RedisTemplate redisTemplate) { RedisSerializer stringSerializer= new StringRedisSerializer(); redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setValueSerializer(stringSerializer); redisTemplate.setHashKeySerializer(stringSerializer); redisTemplate.setHashValueSerializer(stringSerializer); this.redisTemplate = redisTemplate; }
這樣配置後 redis ok