好的,我知道了。我很难解决这个问题,一直在寻找时间…
这是我的代码:
io.on('connection', function(client){ console.log('Client id #'+client.id); if (client.handshake.session) { var user_socket_channel = client.handshake.session['user_socket_channel']; } var redis_listener = function(redis_channel, rawdata) { console.log('Redis connection on '+redis_channel); var data = JSON.parse(rawdata); if (data.channel) { var socket_channel = data.channel; } else { if (user_socket_channel) { var socket_channel = user_socket_channel; } else { var socket_channel = 'public' } } var rails_data = data.data; console.log('Socket.io emiting on ['+socket_channel+']'); client.emit(socket_channel, rails_data); }; redis_subs.on('message', redis_listener); client.on('disconnect', function(){ console.log('Client disconnect, removing redis listener..'); redis_subs.removeListener('message', redis_listener); });});根据上下文,您需要在io.client.disconnect事件上调用redis.removeListener。
这是一个可能的选择:
https://github.com/LearnBoost/Socket.IO/wiki/Configuring-
Socket.IO



