added redis socket support

In order to enable socket support I added another command line argument: `--sock` which can be true or false.
If set to true the script will try to connect via sockets to the redis host provided via the `--redis` flag. In
that case the port will be omitted.
This commit is contained in:
ivrrecht 2015-12-01 15:38:19 +01:00 committed by Per Guth
parent ac5d254d68
commit f6fa7d281a
2 changed files with 8 additions and 2 deletions

View file

@ -22,6 +22,7 @@ exports.googleanalytics = {
var redis_conf = argv.redis || '127.0.0.1:6379'; var redis_conf = argv.redis || '127.0.0.1:6379';
exports.database = { exports.database = {
sock: argv['sock'] || false,
type: 'redis', type: 'redis',
prefix: '#scrumblr#', prefix: '#scrumblr#',
host: redis_conf.split(':')[0] || '127.0.0.1', host: redis_conf.split(':')[0] || '127.0.0.1',

View file

@ -16,8 +16,13 @@ var REDIS_PREFIX = '#scrumblr#';
var db = function(callback) { var db = function(callback) {
if (conf.sock) {
console.log('Opening redis connection to socket ' + conf.host);
redisClient = redis.createClient(conf.host);
} else {
console.log('Opening redis connection to ' + conf.host + ':' + conf.port); console.log('Opening redis connection to ' + conf.host + ':' + conf.port);
redisClient = redis.createClient(conf.port, conf.host, {}); redisClient = redis.createClient(conf.port, conf.host, {});
}
redisClient.on("connect", function (err) { redisClient.on("connect", function (err) {
callback(); callback();
}); });