Using the npm module 'redis', I've had no problem using utils promisify for single commands.
const { promisify } = require("util");
const redis = require("redis");
const client = redis.createClient();
const hmgetAsync = promisify(client.hmget).bind(client),
Now I want to be able to use the .multi and .batch methods.
Here is an example of one of my helper functions that uses .batch without promisify and non of the promisify versions of commands.
const getData = async (ids) => {
const batch = client.batch();
ids.forEach(id => {
batch.hgetall(id)
});
return new Promise((resolve, reject) => {
batch.exec((err, replies) => {
if (err) {
reject(err);
}
const data = replies
// missing keys require filtering
.filter(it => !!it)
.map(dataPoint => _toDataPoint(dataPoint));
resolve(data);
})
})
};
Works no problem, but I'm curious if it is possible to use promisify with either .multi or .batch
Many thanks,