package com.elab.redis.componts.config;

import com.elab.redis.componts.config.scope.RedisConfigRefreshCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

public class RedisMsgListener implements MessageListener {

    private Logger logger = LoggerFactory.getLogger(getClass());
    private final RedisConfigRefreshCallback refreshConfig;

    public RedisMsgListener(RedisConfigRefreshCallback refreshConfig) {
        this.refreshConfig = refreshConfig;
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        logger.debug("监听缓存发生变化:" + new String(message.getBody()) + "\t topic : " + new String(pattern));
        refreshConfig.refresh();
    }
}
