部分代码 // connect Redis 多进程/多服务器 共享数据
var _sRCfg = require('./cfg').ShareRedisCfg,
_redis = require(moduleAddr + 'redis').createClient,
_pub = _redis(_sRCfg.port, _sRCfg.host),
_sub = _redis(_sRCfg.port, _sRCfg.host, {
detect_buffers: true
}),
_adapter = require(moduleAddr + 'socket.io-redis');
io.adapter(_adapter({
// host: _sRCfg.host,
// port: _sRCfg.port,
pubClient: _pub,
subClient: _sub
}));
一对一聊天代码
socketObj = io.sockets.connected[xxx]; // xxx socket.id 在redis存储
if (socketObj) {
socketObj.emit(eventName, msg);
}