node-redis-pubsub
node-redis-pubsub copied to clipboard
Unsubscribe function unsubscribes all the listeners for the same channel pattern
Just to point out a behavior of this library that is not obvious and that made me wrong. If you subscribe for the same channel pattern multiple times, and then you call just the first unsubscribe function, then all the other listeners will never receive a message, since the redis client has been unsubscribed from that channel pattern.
In code words:
var unsub1 = nrp.on('say hello', function(data){
console.log('First Hello ' + data.name);
});
var unsub2 = nrp.on('say hello', function(data){
console.log('Second Hello ' + data.name);
});
// then at next tick or later
// ...
nrp.emit('say hello', { name: 'Louis' }); // Outputs 'First Hello Louis' and 'Second Hello Louis'
// let's unsubscribe just the first handler.
unsub1();
nrp.emit('say hello', { name: 'Louis' }); // It should output 'Second Hello Louis', but it won't
After thinking about it, I realized that it should be considered as a bug. Therefore I created a pullrequest here: https://github.com/louischatriot/node-redis-pubsub/pull/41
@RangerMauve @louischatriot no news about this? Don't you think that it should be fixed with the PR I submitted? Thanks