| | |
| | | import org.redisson.Redisson; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.redisson.config.Config; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.autoconfigure.AutoConfigureBefore; |
| | | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | |
| | | @AutoConfigureBefore(RedisAutoConfiguration.class) |
| | | public class RedisConfig extends CachingConfigurerSupport |
| | | { |
| | | |
| | | @Value("${spring.profiles.active:dev}") |
| | | private String env; |
| | | |
| | | @Bean |
| | | @SuppressWarnings(value = { "unchecked", "rawtypes" }) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) |
| | |
| | | // 集群模式 |
| | | // config.useClusterServers().addNodeAddress("192.168.110.188:7004", "192.168.110.188:7001"); |
| | | // 2.根据 Config 创建出 RedissonClient 示例。 |
| | | config.useSingleServer().setAddress("redis://192.168.110.188:6379").setPassword("123456"); |
| | | // 根据当前环境设置address |
| | | if (env.equals("dev")) { |
| | | config.useSingleServer().setAddress("redis://192.168.110.188:6379") |
| | | .setPassword("123456"); |
| | | } else if (env.equals("prod")) { |
| | | config.useSingleServer().setAddress("redis://127.0.0.1:6379") |
| | | .setPassword("DZaDDhN6tp"); |
| | | } |
| | | return Redisson.create(config); |
| | | } |
| | | |