| | |
| | | package com.ruoyi.common.redis.configure; |
| | | |
| | | import java.io.IOException; |
| | | import org.redisson.Redisson; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.redisson.config.Config; |
| | | import org.springframework.boot.autoconfigure.AutoConfigureBefore; |
| | | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | |
| | | 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.listener.RedisMessageListenerContainer; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | /** |
| | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | //Redis监听容器 |
| | | @Bean |
| | | public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) { |
| | | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| | | container.setConnectionFactory(connectionFactory); |
| | | return container; |
| | | } |
| | | |
| | | @Bean(destroyMethod = "shutdown") // 服务停止后调用 shutdown 方法。 |
| | | public RedissonClient redisson() throws IOException { |
| | | // 1.创建配置 |
| | | Config config = new Config(); |
| | | // 集群模式 |
| | | // config.useClusterServers().addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001"); |
| | | // 2.根据 Config 创建出 RedissonClient 示例。 |
| | | config.useSingleServer().setAddress("redis://192.168.110.188:6379").setPassword("123456"); |
| | | return Redisson.create(config); |
| | | } |
| | | |
| | | } |