-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.js
31 lines (24 loc) · 820 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var fs = require('fs');
var REDIS_CONF = "redis.conf";
try {
// If we have a redis.conf file, read the port and host
fs.statSync(REDIS_CONF);
// convert redis keys to more verbose names
var conversion = {'port': 'redis_port', 'bind': 'redis_host'};
var match;
fs.readFileSync(REDIS_CONF).toString().split('\n').forEach(function(line) {
match = line.match(/^(port|bind)\s+(.*)$/);
if (match) {
module.exports[conversion[match[1]]] = match[2].trim();
}
});
} catch (redisConfDoesntExist) {
// If there's no redis.conf, set host and port manually
module.exports = {
redis_port: process.env['REDIS_PORT'] || 6379,
redis_host: '127.0.0.1'
};
}
if (typeof module.exports.redis_port !== 'number') {
module.exports.redis_port = parseInt(module.exports.redis_port, 10);
}