Skip to content

Commit

Permalink
Replace db factory and do not promisify the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Nov 2, 2017
1 parent b26ebfb commit 708d87e
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const logger = require('./logger').db;
const redisCommands = require('redis-commands');
require('util.promisify/shim')(); // NOTE: shim for native node 8.0 uril.promisify
const util = require('util');
let db;

module.exports = function () {
Expand All @@ -15,19 +12,9 @@ module.exports = function () {
// designed for demo and test scenarious to avoid having real Redis instance
const emulate = process.argv[2] === 'emulate' || redisOptions.emulate;

const redis = require(emulate ? 'fakeredis' : 'redis');
promisify(redis.RedisClient.prototype, redisCommands.list);
promisify(redis.Multi.prototype, ['exec', 'execAtomic']);
const Redis = require(emulate ? 'ioredis-mock' : 'ioredis');

function promisify (obj, methods) {
methods.forEach((method) => {
if (obj[method]) {
obj[method + 'Async'] = util.promisify(obj[method]);
}
});
}

db = redis.createClient(redisOptions);
db = new Redis(redisOptions);

db.on('ready', function () {
logger.debug('Redis is ready');
Expand Down

0 comments on commit 708d87e

Please sign in to comment.