| | |
| | | import com.fasterxml.jackson.annotation.JsonAutoDetect; |
| | | import com.fasterxml.jackson.annotation.PropertyAccessor; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.boot.autoconfigure.data.redis.RedisProperties; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.connection.RedisPassword; |
| | | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; |
| | | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
| | | import org.springframework.data.redis.core.*; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | |
| | | * Redis配置类 |
| | | * Created by vincent on 2019-12-23 |
| | | */ |
| | | //@Configuration |
| | | @Configuration |
| | | //@EnableCaching // 开启数据缓存机制 |
| | | public class RedisConfig extends CachingConfigurerSupport { |
| | | |
| | | @Bean |
| | | @Primary |
| | | public LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) { |
| | | RedisStandaloneConfiguration standalone = new RedisStandaloneConfiguration(); |
| | | standalone.setHostName(redisProperties.getHost()); |
| | | standalone.setPort(redisProperties.getPort()); |
| | | standalone.setDatabase(redisProperties.getDatabase()); |
| | | if (StringUtils.hasText(redisProperties.getPassword())) { |
| | | standalone.setPassword(RedisPassword.of(redisProperties.getPassword())); |
| | | } |
| | | return new LettuceConnectionFactory(standalone); |
| | | } |
| | | |
| | | /** |
| | | * RedisTemplate相关配置 |