exposed redis' "connect" method, so socket.io can call it from outside database/redis.js, fixed NodeBB requiring Redis as a socket.io store. It will now go back to using in-memory store per process, if no redis config is found in the NodeBB configuration. re: #2097

This commit is contained in:
Julian Lam
2014-09-23 17:08:30 -04:00
parent b1f492dec3
commit f41be4ae8b
2 changed files with 54 additions and 36 deletions

View File

@@ -47,26 +47,7 @@
process.exit();
}
var redis_socket_or_host = nconf.get('redis:host');
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'));
}
if (nconf.get('redis:password')) {
redisClient.auth(nconf.get('redis:password'));
} else {
winston.warn('You have no redis password setup!');
}
redisClient.on('error', function (err) {
winston.error(err.stack);
process.exit(1);
});
redisClient = module.connect();
module.client = redisClient;
@@ -104,6 +85,34 @@
}
};
module.connect = function() {
var redis_socket_or_host = nconf.get('redis:host'),
cxn;
if (!redis) redis = require('redis');
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 */
cxn = redis.createClient(nconf.get('redis:host'));
} else {
/* Else, connect over tcp/ip */
cxn = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
}
if (nconf.get('redis:password')) {
cxn.auth(nconf.get('redis:password'));
} else {
winston.warn('You have no redis password setup!');
}
cxn.on('error', function (err) {
winston.error(err.stack);
process.exit(1);
});
return cxn;
};
module.close = function() {
redisClient.quit();
};