I use the library 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);
}
I expect that method blpopAsync will be blocked until a element is popped. And in this time, event loop will run other async functions. However, my program is blocked at await blpopAsync forever.
Could you tell me how to use this function correctly to not block event-loop?
I find that blpop blocks other non-blocking methods of redis client, so other functions which use redis will wait forever. The event loop is still running.
As @AnonyMouze mentioned, doing client.duplicate().blpop(...) is the trick to freeing the connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With