drop.chapril.org-firefoxsend/server/storage/redis.js

32 lines
987 B
JavaScript
Raw Normal View History

2018-02-06 23:31:18 +01:00
const promisify = require('util').promisify;
module.exports = function(config) {
const redis_lib =
2020-07-27 20:18:52 +02:00
config.env === 'development' && config.redis_host === 'mock'
2018-02-06 23:31:18 +01:00
? '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,
retry_strategy: options => {
2020-04-21 22:30:39 +02: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 22:30:39 +02:00
return config.redis_retry_delay;
}
2018-02-06 23:31:18 +01:00
});
client.ttlAsync = promisify(client.ttl);
client.hgetallAsync = promisify(client.hgetall);
client.hgetAsync = promisify(client.hget);
2020-07-27 20:18:52 +02:00
client.hincrbyAsync = promisify(client.hincrby);
client.hmgetAsync = promisify(client.hmget);
2018-02-06 23:31:18 +01:00
client.pingAsync = promisify(client.ping);
client.existsAsync = promisify(client.exists);
2018-02-06 23:31:18 +01:00
return client;
};