简体   繁体   English

带列表的Redis发布/订阅

[英]Redis pub/sub with lists

I'm using Redis with Node.js. 我将Redis与Node.js一起使用。

client = redis.createClient();
client.subscribe("__keyspace@0__:url_set");
client.on("message",function(channel, message) {
    client.on('connect', function() {
        client.lrange('url_list',0,-1,function(err3, reply3) {
            console.log(reply3);
        });
        client.smembers('url_set',function(err4, reply4) {
            console.log(reply4);
        });
    });
});

Here reply3 and reply4 are undefined . 在这里, reply3reply4undefined Are lrange() and smembers() not allowed within a pub sub "on message" block? 是否在发布消息的“发布”块中不允许使用lrange()smembers()

Yes, regular commands are not allowed when a client is in subscriber mode. 是的,当客户端处于订户模式时,不允许使用常规命令。 Create a another client for regular commands. 为常规命令创建另一个客户端。

var client2 = redis.createClient();

use client2 for lrange() and smembers() . 使用client2lrange()smembers()

Refer node-redis doc : 请参阅node-redis doc

When a client issues a SUBSCRIBE or PSUBSCRIBE, that connection is put into a "subscriber" mode. 当客户端发出SUBSCRIBE或PSUBSCRIBE时,该连接将进入“订户”模式。 At that point, only commands that modify the subscription set are valid. 那时,只有修改订阅集的命令才有效。 When the subscription set is empty, the connection is put back into regular mode. 当订阅集为空时,连接将恢复为常规模式。

If you need to send regular commands to Redis while in subscriber mode, just open another connection. 如果需要在订阅者模式下向Redis发送常规命令,只需打开另一个连接即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM