forked from openhab/openhab-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis-helper.js
34 lines (26 loc) · 919 Bytes
/
redis-helper.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
32
33
34
// This module handles shared redis client for all
var app = require('./app.js'),
logger = require('./logger.js'),
redis = require('redis'),
redisClient;
logger.info('Connecting to Redis at ' + app.config.redis.host + ':' + app.config.redis.port);
redisClient = redis.createClient(app.config.redis.port, app.config.redis.host);
if (typeof app.config.redis.password !== 'undefined') {
redisClient.auth(app.config.redis.password, function(error, data) {
if (error) {
logger.error(error);
} else {
logger.info('Redis connect response: ' + data);
}
});
}
redisClient.on('ready', function () {
logger.info('Redis is ready');
});
redisClient.on('end', function () {
logger.error('Redis error: connection is closed');
});
redisClient.on('error', function (error) {
logger.error('Redis error: ' + error);
});
module.exports = redisClient;