【发布时间】:2020-10-25 22:11:46
【问题描述】:
我使用库node-redis:https://github.com/NodeRedis/node-redis
let client = redis.createClient();
let blpopAsync = util.promisify(client.blpop).bind(client);
let rpushAsync = util.promisify(client.rpush).bind(client);
async function consume() {
let data = await blpopAsync('queue', 0); // the program is blocked at here
}
async function otherLongRunningTasks() {
// call some redis method
await rpushAsync('queue', data);
}
我希望方法 blpopAsync 将被阻止,直到弹出一个元素。而此时,事件循环将运行其他异步函数。但是,我的程序在 await blpopAsync 处被永久阻止。
你能告诉我如何正确使用这个函数来不阻塞事件循环吗?
我发现blpop阻塞了redis客户端的其他非阻塞方法,所以其他使用redis的函数会永远等待。事件循环仍在运行。
【问题讨论】: