听取与节点redis上的模式匹配的频道?

时间:2014-04-28 16:55:35

标签: node.js redis node-redis

我正在使用node-redis。一切正常。我只订阅specific频道。但我收到来自各个渠道的消息:

服务器代码:

socket.on('connection', function(client) {
        const subscribe = redis.createClient(6379, '127.0.0.1')
        subscribe.psubscribe('tracking_*');

        subscribe.on("error", function (err) {
            console.log("Error " + err);
        });

        subscribe.on("pmessage", function(pattern, channel, message) {
            client.send(message);
            log('msg', "received from channel #" + channel + " : " + message);
        });

        client.on('message', function(msg) {
            log('debug', msg);
        });

        client.on('disconnect', function() {
            log('warn', 'disconnecting from redis');
            subscribe.quit();
        })

客户代码:

socket.on('connect', function(data){
        setStatus('connected');
        socket.emit('subscribe', {channel:'tracking_hi'});
      });

正如您所看到的,我只订阅了tracking_hi频道,但我收到了来自所有频道的消息。有什么问题?

0 个答案:

没有答案