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 RedisUpdateAndAddListener implements MessageListener {

    //监听的主题  现在只监听0号数据库
    private  final PatternTopic topic = new PatternTopic("__keyevent@0__:set");
    //直接订阅key
    private  final PatternTopic topic2 = new PatternTopic("__keyspace@0__: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;
    }
}
