node-redis-pubsub icon indicating copy to clipboard operation
node-redis-pubsub copied to clipboard

Unsubscribe function unsubscribes all the listeners for the same channel pattern

Open godness84 opened this issue 7 years ago • 2 comments

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

godness84 avatar May 22 '17 17:05 godness84

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

godness84 avatar May 24 '17 10:05 godness84

@RangerMauve @louischatriot no news about this? Don't you think that it should be fixed with the PR I submitted? Thanks

godness84 avatar Jul 20 '17 14:07 godness84