mirror of https://github.com/Requarks/wiki.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
748 B
41 lines
748 B
"use strict";
|
|
|
|
var Redis = require('ioredis'),
|
|
_ = require('lodash');
|
|
|
|
/**
|
|
* Redis module
|
|
*
|
|
* @param {Object} appconfig Application config
|
|
* @return {Redis} Redis instance
|
|
*/
|
|
module.exports = (appconfig) => {
|
|
|
|
let rd = null;
|
|
|
|
if(_.isArray(appconfig.redis)) {
|
|
rd = new Redis.Cluster(appconfig.redis, {
|
|
scaleReads: 'master',
|
|
redisOptions: {
|
|
lazyConnect: false
|
|
}
|
|
});
|
|
} else {
|
|
rd = new Redis(_.defaultsDeep(appconfig.redis), {
|
|
lazyConnect: false
|
|
});
|
|
}
|
|
|
|
// Handle connection errors
|
|
|
|
rd.on('error', (err) => {
|
|
winston.error('Failed to connect to Redis instance(s). [err-1]');
|
|
});
|
|
|
|
rd.on('node error', (err) => {
|
|
winston.error('Failed to connect to Redis instance(s). [err-2]');
|
|
});
|
|
|
|
return rd;
|
|
|
|
};
|