Allow running as a cluster without Redis (#6233)

* [database/*] Allow databases other than Redis to provide pubsub for clustering if Redis is not present

* [pubsub] Delay messages sent before the database is ready until the database is ready.

* [pubsub] Restore old behavior of not using the database in non-clustered NodeBB instances.

See comment: https://github.com/NodeBB/NodeBB/pull/6233#issuecomment-357814968
This commit is contained in:
Ben Lubar
2018-01-18 12:02:56 -06:00
committed by Barış Soner Uşaklı
parent c20aca8933
commit e85aabbe74
8 changed files with 165 additions and 80 deletions

View File

@@ -26,7 +26,7 @@ Sockets.init = function (server) {
path: nconf.get('relative_path') + '/socket.io',
});
addRedisAdapter(io);
io.adapter(nconf.get('redis') ? require('../database/redis').socketAdapter() : db.socketAdapter());
io.use(socketioWildcard);
io.use(authorize);
@@ -212,22 +212,6 @@ function authorize(socket, callback) {
], callback);
}
function addRedisAdapter(io) {
if (nconf.get('redis')) {
var redisAdapter = require('socket.io-redis');
var redis = require('../database/redis');
var pub = redis.connect();
var sub = redis.connect();
io.adapter(redisAdapter({
key: 'db:' + nconf.get('redis:database') + ':adapter_key',
pubClient: pub,
subClient: sub,
}));
} else if (nconf.get('isCluster') === 'true') {
winston.warn('[socket.io] Clustering detected, you are advised to configure Redis as a websocket store.');
}
}
Sockets.in = function (room) {
return io.in(room);
};