A typical Redis chat example will go something like this (see https://github.com/emrahayanoglu/Socket.io-Redis-RealTime-Chat-Example/blob/master/chatServer.js for just one s
The only solution that I've found by playing around in the node REPL is to not use the redis.on()
function to subscribe. Instead, one should use the redis.addListener()
and redis.removeListener()
functions. In addition, one must not use anonymous functions as event callbacks.
One could do something like this:
var callback = function(channel, message){
};
redis1.addListener('message', callback);
client.on('disconnect', function(){
redis1.removeListener('message', callback);
})