package com.yuchen.saas.park.service.config;

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;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;

/**
 * @ClassName RedisListenerConfig
 * @Description
 * @author 吕海泉
 * @Date 2021/4/7 22:01
 * @Version 1.0
 **/
@Deprecated // modify by qianjiang 2022.9.24 功能不明确代码
@Configuration
public class RedisListenerConfig {
//
//    @Bean
//    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
//        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
//        container.setConnectionFactory(connectionFactory);
//        // //container.addMessageListener(new RedisExpiredListener(), new PatternTopic("__keyevent@0__:expired"));
//        return container;
//    }

    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Autowired
    private KeyExpiredListener keyExpiredListener;

    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer() {
        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
        redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
        // 配置监听器监听的主题关联
        Topic topic = new ChannelTopic("__keyevent@0__:expired");
        redisMessageListenerContainer.addMessageListener(keyExpiredListener, topic);
        return redisMessageListenerContainer;
    }

}


