|
|
@ -1,9 +1,8 @@
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
const async = require('async');
|
|
|
|
|
|
|
|
const winston = require('winston');
|
|
|
|
|
|
|
|
const nconf = require('nconf');
|
|
|
|
const nconf = require('nconf');
|
|
|
|
const semver = require('semver');
|
|
|
|
const semver = require('semver');
|
|
|
|
|
|
|
|
const util = require('util');
|
|
|
|
const session = require('express-session');
|
|
|
|
const session = require('express-session');
|
|
|
|
|
|
|
|
|
|
|
|
const connection = require('./redis/connection');
|
|
|
|
const connection = require('./redis/connection');
|
|
|
@ -36,112 +35,77 @@ redisModule.questions = [
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.init = function (callback) {
|
|
|
|
redisModule.init = async function () {
|
|
|
|
callback = callback || function () { };
|
|
|
|
redisModule.client = await connection.connect(nconf.get('redis'));
|
|
|
|
redisModule.client = connection.connect(nconf.get('redis'), function (err) {
|
|
|
|
require('./redis/promisify')(redisModule.client);
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
winston.error('NodeBB could not connect to your Redis database. Redis returned the following error\n' + err.stack);
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
require('./redis/promisify')(redisModule.client);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.createSessionStore = function (options, callback) {
|
|
|
|
redisModule.createSessionStore = async function (options) {
|
|
|
|
const meta = require('../meta');
|
|
|
|
const meta = require('../meta');
|
|
|
|
const sessionStore = require('connect-redis')(session);
|
|
|
|
const sessionStore = require('connect-redis')(session);
|
|
|
|
const client = connection.connect(options);
|
|
|
|
const client = await connection.connect(options);
|
|
|
|
const store = new sessionStore({
|
|
|
|
const store = new sessionStore({
|
|
|
|
client: client,
|
|
|
|
client: client,
|
|
|
|
ttl: meta.getSessionTTLSeconds(),
|
|
|
|
ttl: meta.getSessionTTLSeconds(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return store;
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
|
|
|
callback(null, store);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.createIndices = function (callback) {
|
|
|
|
|
|
|
|
setImmediate(callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.checkCompatibility = function (callback) {
|
|
|
|
redisModule.checkCompatibility = async function () {
|
|
|
|
async.waterfall([
|
|
|
|
const info = await redisModule.info(redisModule.client);
|
|
|
|
function (next) {
|
|
|
|
redisModule.checkCompatibilityVersion(info.redis_version);
|
|
|
|
redisModule.info(redisModule.client, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (info, next) {
|
|
|
|
|
|
|
|
redisModule.checkCompatibilityVersion(info.redis_version, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.checkCompatibilityVersion = function (version, callback) {
|
|
|
|
redisModule.checkCompatibilityVersion = function (version) {
|
|
|
|
if (semver.lt(version, '2.8.9')) {
|
|
|
|
if (semver.lt(version, '2.8.9')) {
|
|
|
|
return callback(new Error('Your Redis version is not new enough to support NodeBB, please upgrade Redis to v2.8.9 or higher.'));
|
|
|
|
throw new Error('Your Redis version is not new enough to support NodeBB, please upgrade Redis to v2.8.9 or higher.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.close = function (callback) {
|
|
|
|
redisModule.close = async function () {
|
|
|
|
callback = callback || function () {};
|
|
|
|
await redisModule.client.async.quit();
|
|
|
|
redisModule.client.quit(function (err) {
|
|
|
|
|
|
|
|
callback(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.info = function (cxn, callback) {
|
|
|
|
redisModule.info = async function (cxn) {
|
|
|
|
async.waterfall([
|
|
|
|
if (!cxn) {
|
|
|
|
function (next) {
|
|
|
|
cxn = await connection.connect(nconf.get('redis'));
|
|
|
|
if (cxn) {
|
|
|
|
}
|
|
|
|
return setImmediate(next, null, cxn);
|
|
|
|
redisModule.client = redisModule.client || cxn;
|
|
|
|
}
|
|
|
|
const infoAsync = util.promisify(cb => cxn.info(cb));
|
|
|
|
connection.connect(nconf.get('redis'), next);
|
|
|
|
const data = await infoAsync();
|
|
|
|
},
|
|
|
|
const lines = data.toString().split('\r\n').sort();
|
|
|
|
function (cxn, next) {
|
|
|
|
const redisData = {};
|
|
|
|
redisModule.client = redisModule.client || cxn;
|
|
|
|
lines.forEach(function (line) {
|
|
|
|
|
|
|
|
const parts = line.split(':');
|
|
|
|
cxn.info(next);
|
|
|
|
if (parts[1]) {
|
|
|
|
},
|
|
|
|
redisData[parts[0]] = parts[1];
|
|
|
|
function (data, next) {
|
|
|
|
}
|
|
|
|
var lines = data.toString().split('\r\n').sort();
|
|
|
|
});
|
|
|
|
var redisData = {};
|
|
|
|
|
|
|
|
lines.forEach(function (line) {
|
|
|
|
const keyInfo = redisData['db' + nconf.get('redis:database')];
|
|
|
|
var parts = line.split(':');
|
|
|
|
if (keyInfo) {
|
|
|
|
if (parts[1]) {
|
|
|
|
const split = keyInfo.split(',');
|
|
|
|
redisData[parts[0]] = parts[1];
|
|
|
|
redisData.keys = (split[0] || '').replace('keys=', '');
|
|
|
|
}
|
|
|
|
redisData.expires = (split[1] || '').replace('expires=', '');
|
|
|
|
});
|
|
|
|
redisData.avg_ttl = (split[2] || '').replace('avg_ttl=', '');
|
|
|
|
|
|
|
|
}
|
|
|
|
const keyInfo = redisData['db' + nconf.get('redis:database')];
|
|
|
|
|
|
|
|
if (keyInfo) {
|
|
|
|
redisData.instantaneous_input = (redisData.instantaneous_input_kbps / 1024).toFixed(3);
|
|
|
|
const split = keyInfo.split(',');
|
|
|
|
redisData.instantaneous_output = (redisData.instantaneous_output_kbps / 1024).toFixed(3);
|
|
|
|
redisData.keys = (split[0] || '').replace('keys=', '');
|
|
|
|
|
|
|
|
redisData.expires = (split[1] || '').replace('expires=', '');
|
|
|
|
redisData.total_net_input = (redisData.total_net_input_bytes / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
redisData.avg_ttl = (split[2] || '').replace('avg_ttl=', '');
|
|
|
|
redisData.total_net_output = (redisData.total_net_output_bytes / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
redisData.used_memory_human = (redisData.used_memory / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
redisData.instantaneous_input = (redisData.instantaneous_input_kbps / 1024).toFixed(3);
|
|
|
|
redisData.raw = JSON.stringify(redisData, null, 4);
|
|
|
|
redisData.instantaneous_output = (redisData.instantaneous_output_kbps / 1024).toFixed(3);
|
|
|
|
redisData.redis = true;
|
|
|
|
|
|
|
|
return redisData;
|
|
|
|
redisData.total_net_input = (redisData.total_net_input_bytes / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
|
|
|
|
redisData.total_net_output = (redisData.total_net_output_bytes / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redisData.used_memory_human = (redisData.used_memory / (1024 * 1024 * 1024)).toFixed(3);
|
|
|
|
|
|
|
|
redisData.raw = JSON.stringify(redisData, null, 4);
|
|
|
|
|
|
|
|
redisData.redis = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next(null, redisData);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
redisModule.socketAdapter = function () {
|
|
|
|
redisModule.socketAdapter = function () {
|
|
|
|
var redisAdapter = require('socket.io-redis');
|
|
|
|
const redisAdapter = require('socket.io-redis');
|
|
|
|
var pub = connection.connect(nconf.get('redis'));
|
|
|
|
const pub = connection.connect(nconf.get('redis'));
|
|
|
|
var sub = connection.connect(nconf.get('redis'));
|
|
|
|
const sub = connection.connect(nconf.get('redis'));
|
|
|
|
return redisAdapter({
|
|
|
|
return redisAdapter({
|
|
|
|
key: 'db:' + nconf.get('redis:database') + ':adapter_key',
|
|
|
|
key: 'db:' + nconf.get('redis:database') + ':adapter_key',
|
|
|
|
pubClient: pub,
|
|
|
|
pubClient: pub,
|
|
|
|