| | |
| | | package com.ruoyi.common.redis.configure; |
| | | |
| | | 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.PatternTopic; |
| | | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| | | import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * redis配置 |
| | |
| | | @AutoConfigureBefore(RedisAutoConfiguration.class) |
| | | public class RedisConfig extends CachingConfigurerSupport |
| | | { |
| | | |
| | | |
| | | @Bean |
| | | RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { |
| | | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| | | container.setConnectionFactory(connectionFactory); |
| | | container.addMessageListener(listenerAdapter, new PatternTopic("__keyevent@"+"0"+"__:expired")); |
| | | return container; |
| | | } |
| | | |
| | | @Bean |
| | | MessageListenerAdapter listenerAdapter(MessageReceiver receiver) { |
| | | return new MessageListenerAdapter(receiver, "receiveMessage"); |
| | | } |
| | | |
| | | @Bean |
| | | MessageReceiver receiver() { |
| | | return new MessageReceiver(); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | @SuppressWarnings(value = { "unchecked", "rawtypes" }) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) |
| | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | @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://47.109.78.184:10020").setPassword("hrt123456"); |
| | | return Redisson.create(config); |
| | | } |
| | | |
| | | } |