我正在尝试使用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
});
});