您如何在Ioredis中使用punsubscribe

时间:2018-09-25 20:06:56

标签: node-redis ioredis

我正在尝试使用punsubscribe,但似乎匹配或我的理解是一个问题。如何取消订阅所有与foo:匹配的事件,如下所示:

let sub = new Redis(connection);
let pub = new Redis(connection);

sub.on('message', (event, message) => {
    console.info(event, message);
});

let subscriptions = [];
subscriptions.push(sub.subscribe('foo:create'));
subscriptions.push(sub.subscribe('foo:update'));
subscriptions.push(sub.subscribe('foo:delete'));
subscriptions.push(sub.subscribe('foo:list'));

Promise.all(subscriptions)
    .then(result => {
        sub.punsubscribe('foo*', (err, count) => {
            console.info(count); // still 4
        });
    });

0 个答案:

没有答案