fox-send/server/storage/redis.js

31 lines
911 B
JavaScript
Raw Normal View History

2018-02-06 22:31:18 +00:00
const promisify = require('util').promisify;
module.exports = function(config) {
const redis_lib =
config.env === 'development' && config.redis_host === 'localhost'
? 'redis-mock'
: 'redis';
//eslint-disable-next-line security/detect-non-literal-require
const redis = require(redis_lib);
const client = redis.createClient({
host: config.redis_host,
2021-04-18 03:08:35 +00:00
port: config.redis_port,
password: config.redis_password,
retry_strategy: options => {
2020-04-21 20:30:39 +00:00
if (options.total_retry_time > config.redis_retry_time) {
client.emit('error', 'Retry time exhausted');
return new Error('Retry time exhausted');
}
2020-04-21 20:30:39 +00:00
return config.redis_retry_delay;
}
2018-02-06 22:31:18 +00:00
});
client.ttlAsync = promisify(client.ttl);
client.hgetallAsync = promisify(client.hgetall);
client.hgetAsync = promisify(client.hget);
client.pingAsync = promisify(client.ping);
return client;
};