创建Redis键空间通知JAVA的侦听器

时间:2019-11-01 11:45:35

标签: java redis

我正在创建一个侦听器,以捕获使用以下命令从Redis触发的通知:zrem senderId“ 33330”。 所以在redis中触发此命令.....我应该在我的Java应用程序中收到一条通知……但是我什么也没收到。

我在redis-cli中设置了以下内容:set notify-keyspace-events zE

这是我在Java中的代码:

StatefulRedisPubSubConnection<String, String> newConnecPubSub = redisClient.connectPubSub();

    RedisPubSubListener<String, String> listener = new RedisPubSubListener<String, String>() {

        @Override
        public void message(String arg0, String arg1) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----Message");
        }

        @Override
        public void message(String arg0, String arg1, String arg2) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----Message2");
        }

        @Override
        public void psubscribed(String arg0, long arg1) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----psubscribed");
        }

        @Override
        public void punsubscribed(String arg0, long arg1) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----punsubscribed");
        }

        @Override
        public void subscribed(String arg0, long arg1) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----subscribed");
        }

        @Override
        public void unsubscribed(String arg0, long arg1) {
            // TODO Auto-generated method stub
            MapRoutingSbb.log.error("onRedis-----unsubscribed");
        }
    };

    newConnecPubSub.addListener(listener);
    RedisPubSubAsyncCommands<String, String> asyncPubSub = newConnecPubSub.async();
    asyncPubSub.psubscribe("__keyevent@*__:*");

0 个答案:

没有答案