package com.mortals.xhx.base.framework.config;

import com.mortals.xhx.base.framework.listener.CustomerKeyExpirationListener;
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.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * 监听所有expire事件
 * @author: zxfei
 * @date: 2022/6/22 16:51
 * @description:
 **/
@Configuration
public class RedisConfig {
    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory
            , CustomerKeyExpirationListener customerKeyExpirationListener) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(customerKeyExpirationListener,new PatternTopic("__keyevent@*__:expired"));
        return container;
    }

}