mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
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:
committed by
Barış Soner Uşaklı
parent
c20aca8933
commit
e85aabbe74
@@ -61,11 +61,7 @@ mongoModule.questions = [
|
||||
mongoModule.helpers = mongoModule.helpers || {};
|
||||
mongoModule.helpers.mongo = require('./mongo/helpers');
|
||||
|
||||
mongoModule.init = function (callback) {
|
||||
callback = callback || function () { };
|
||||
|
||||
var mongoClient = require('mongodb').MongoClient;
|
||||
|
||||
function getConnectionString() {
|
||||
var usernamePassword = '';
|
||||
if (nconf.get('mongo:username') && nconf.get('mongo:password')) {
|
||||
usernamePassword = nconf.get('mongo:username') + ':' + encodeURIComponent(nconf.get('mongo:password')) + '@';
|
||||
@@ -92,7 +88,15 @@ mongoModule.init = function (callback) {
|
||||
servers.push(hosts[i] + ':' + ports[i]);
|
||||
}
|
||||
|
||||
var connString = nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database');
|
||||
return nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database');
|
||||
}
|
||||
|
||||
mongoModule.init = function (callback) {
|
||||
callback = callback || function () { };
|
||||
|
||||
var mongoClient = require('mongodb').MongoClient;
|
||||
|
||||
var connString = getConnectionString();
|
||||
|
||||
var connOptions = {
|
||||
poolSize: 10,
|
||||
@@ -118,6 +122,7 @@ mongoModule.init = function (callback) {
|
||||
require('./mongo/sets')(db, mongoModule);
|
||||
require('./mongo/sorted')(db, mongoModule);
|
||||
require('./mongo/list')(db, mongoModule);
|
||||
require('./mongo/pubsub')(db, mongoModule);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -262,3 +267,8 @@ mongoModule.close = function (callback) {
|
||||
callback = callback || function () {};
|
||||
db.close(callback);
|
||||
};
|
||||
|
||||
mongoModule.socketAdapter = function () {
|
||||
var mongoAdapter = require('socket.io-adapter-mongo');
|
||||
return mongoAdapter(getConnectionString());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user