You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.8 KiB
JavaScript

11 years ago
'use strict';
11 years ago
11 years ago
(function(module) {
11 years ago
11 years ago
var winston = require('winston'),
11 years ago
nconf = require('nconf'),
11 years ago
path = require('path'),
express = require('express'),
11 years ago
utils = require('./../../public/src/utils.js'),
redis,
connectRedis,
reds,
11 years ago
redisClient,
postSearch,
topicSearch;
11 years ago
module.questions = [
{
name: 'redis:host',
description: 'Host IP or address of your Redis instance',
'default': nconf.get('redis:host') || '127.0.0.1'
},
{
name: 'redis:port',
description: 'Host port of your Redis instance',
'default': nconf.get('redis:port') || 6379
},
{
name: 'redis:password',
description: 'Password of your Redis database',
hidden: true
},
{
name: "redis:database",
description: "Which database to use (0..n)",
'default': nconf.get('redis:database') || 0
}
];
11 years ago
11 years ago
module.init = function(callback) {
try {
redis = require('redis');
connectRedis = require('connect-redis')(express);
reds = require('reds');
} catch (err) {
winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message);
process.exit();
}
var redis_socket_or_host = nconf.get('redis:host');
11 years ago
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
redisClient = redis.createClient(nconf.get('redis:host'));
} else {
/* Else, connect over tcp/ip */
redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
}
11 years ago
if (nconf.get('redis:password')) {
redisClient.auth(nconf.get('redis:password'));
} else {
winston.warn('You have no redis password setup!');
}
11 years ago
11 years ago
redisClient.on('error', function (err) {
winston.error(err.stack);
process.exit(1);
11 years ago
});
11 years ago
11 years ago
module.client = redisClient;
11 years ago
module.sessionStore = new connectRedis({
client: redisClient,
ttl: 60 * 60 * 24 * 14
});
11 years ago
reds.createClient = function () {
return reds.client || (reds.client = redisClient);
};
module.postSearch = reds.createSearch('nodebbpostsearch');
module.topicSearch = reds.createSearch('nodebbtopicsearch');
11 years ago
var db = parseInt(nconf.get('redis:database'), 10);
11 years ago
11 years ago
if (db) {
redisClient.select(db, function(error) {
if(error) {
winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message);
process.exit();
}
});
}
11 years ago
require('./redis/main')(redisClient, module);
require('./redis/hash')(redisClient, module);
require('./redis/sets')(redisClient, module);
require('./redis/sorted')(redisClient, module);
require('./redis/list')(redisClient, module);
if(typeof callback === 'function') {
11 years ago
callback();
}
11 years ago
};
module.close = function() {
redisClient.quit();
};
module.helpers = module.helpers || {};
11 years ago
module.helpers.redis = require('./redis/helpers');
11 years ago
}(exports));
11 years ago