How to remove Redis on 'message' listeners

后端 未结 1 454
无人共我
无人共我 2020-12-13 15:18

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

相关标签:
1条回答
  • 2020-12-13 15:46

    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);    
    })
    
    0 讨论(0)
提交回复
热议问题