Promisify Redis 客户端
Promisify Redis client
我怎样才能 promisify redis
才能使用 then
?
我已尝试向客户承诺:
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)
});
});
但它响应错误:
client.lrange(...).then is not a function
PS: 回调代码工作正常,所以这意味着服务器 运行 完美。
当使用 promisifyAll
时,promisified 方法得到一个 -Async
后缀:
client.lrangeAsync('abc',0,3).then(...);
Note that the original methods on the object are not overwritten but new methods are created with the Async
-suffix. For example, if you promisifyAll
the node.js fs
object use fs.statAsync
to call the promisified stat
method.
我怎样才能 promisify redis
才能使用 then
?
我已尝试向客户承诺:
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)
});
});
但它响应错误:
client.lrange(...).then is not a function
PS: 回调代码工作正常,所以这意味着服务器 运行 完美。
当使用 promisifyAll
时,promisified 方法得到一个 -Async
后缀:
client.lrangeAsync('abc',0,3).then(...);
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.