package com.zd.laboratory.event;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.stereotype.Component;

/**
 * @Author: zhoupan
 * @Date: 2021/10/20/11:19
 * @Description:
 */
@Component
public class RedisDelAndAddListener implements MessageListener {

    //监听的主题  现在只监听0号数据库
    private  final PatternTopic topic = new PatternTopic("__keyevent@0__:del:sss:*");

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String topic = new String(bytes);
        String msg = new String(message.getBody());
        System.out.println("收到key删除，消息主题是："+ topic+",消息内容是："+msg);
    }


    public PatternTopic getTopic() {
        return topic;
    }
}
