I'm trying to promisify the entire node_redis RedisClient object using Node 8's util.promisify in a manner similar to how Bluebird's promisifyAll() works, and not having much luck.
This is what I've tried thus far:
import * as _redis from 'redis';
import { promisify } from 'util';
const client = _redis.createClient();
const redis = Object.keys(client).reduce((c, key) => {
if (typeof c[key] === 'function') c[key] = promisify(c[key]).bind(c);
return c;
}, client);
This, however, works:
const redis = {
get: promisify(client.get).bind(client),
set: promisify(client.set).bind(client),
hget: promisify(client.hget).bind(client),
hmset: promisify(client.hmset).bind(client),
};
Any ideas?
edit: The main reason I'm wanting to use util.promisify instead of something like Bluebird is because I'm doing this all in TypeScript, and Bluebird's promisifyAll doesn't seem to work with that.