From ecea917d11df07308fcf4df79112d454d48b9f26 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 23 Sep 2014 17:18:20 -0400 Subject: [PATCH] closed #2097 -- NodeBB will prefer using Redis as session store if at all possible --- src/database/mongo.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index d173693451..e67419d3e4 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -43,8 +43,14 @@ module.init = function(callback) { try { + var sessionStore; mongoClient = require('mongodb').MongoClient; - mongoStore = require('connect-mongo')({session: session}); + + if (!nconf.get('redis')) { + sessionStore = require('connect-mongo')({session: session}); + } else { + sessionStore = require('connect-redis')(session); + } } catch (err) { winston.error('Unable to initialize MongoDB! Is MongoDB installed? Error :' + err.message); process.exit(); @@ -60,9 +66,16 @@ module.client = db; - module.sessionStore = new mongoStore({ - db: db - }); + if (!nconf.get('redis')) { + module.sessionStore = new sessionStore({ + db: db + }); + } else { + module.sessionStore = new sessionStore({ + client: require('./redis').connect(), + ttl: 60 * 60 * 24 * 14 + }); + } require('./mongo/main')(db, module); require('./mongo/hash')(db, module);