exposed redis' "connect" method, so socket.io can call it from outside database/redis.js, fixed NodeBB requiring Redis as a socket.io store. It will now go back to using in-memory store per process, if no redis config is found in the NodeBB configuration. re: #2097

This commit is contained in:
Julian Lam
2014-09-23 17:08:30 -04:00
parent b1f492dec3
commit f41be4ae8b
2 changed files with 54 additions and 36 deletions

View File

@@ -66,23 +66,32 @@ function onUserDisconnect(uid, socketid, socketCount) {
}
Sockets.init = function(server) {
var RedisStore = require('socket.io/lib/stores/redis'),
redis = require('redis'),
pub = redis.createClient(),
sub = redis.createClient(),
client = redis.createClient();
// Default socket.io config
var config = {
log: false,
transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'],
'browser client minification': true,
resource: nconf.get('relative_path') + '/socket.io'
};
io = socketioWildcard(SocketIO).listen(server, {
log: false,
transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'],
'browser client minification': true,
resource: nconf.get('relative_path') + '/socket.io',
'store' : new RedisStore({
redisPub : pub,
redisSub : sub,
redisClient : client
}),
});
// If a redis server is configured, use it as a socket.io store, otherwise, fall back to in-memory store
if (nconf.get('redis')) {
var RedisStore = require('socket.io/lib/stores/redis'),
database = require('../database/redis'),
pub = database.connect(),
sub = database.connect(),
client = database.connect();
config.store = new RedisStore({
redisPub : pub,
redisSub : sub,
redisClient : client
});
} else if (nconf.get('cluster')) {
winston.warn('[socket.io] Clustering detected, you are advised to configure Redis as a websocket store.')
}
io = socketioWildcard(SocketIO).listen(server, config);
Sockets.server = io;