Reputation: 839
How can I promisify redis
so that I could use then
?
I have tried to promisify client:
var redis = require('redis');
Promise.promisifyAll(redis.RedisClient.prototype);
var client = redis.createClient();
client.on('connect', function(){
console.log('Redis connection is up');
client.lrange('abc',0,3).then(function(result){
console.log(result);
res.send(200)
});
});
But it responds with error:
client.lrange(...).then is not a function
PS: The callback code works fine, so it means server is running perfectly.
Upvotes: 3
Views: 10525
Reputation: 203359
When using promisifyAll
, the promisified methods get an -Async
suffix:
client.lrangeAsync('abc',0,3).then(...);
As per the documentation:
Note that the original methods on the object are not overwritten but new methods are created with the
Async
-suffix. For example, if youpromisifyAll
the node.jsfs
object usefs.statAsync
to call the promisifiedstat
method.
Upvotes: 11