BLPOP在多个运行队列中使用Redis连接时会阻止它

ncgqoxb0  于 4个月前  发布在  Redis
关注(0)|答案(1)|浏览(67)

我有8个队列运行,我想弹出,如果队列有一个推。应用程序有多个用户和队列几乎总是有数据。
我想用BLPOP替换LPOP,但在所有队列中使用它不会弹出数据
下面是我代码示例

async function queuePop(queue) {
    const value = await redis.blpop(queue, 0);
    if (value) {
        const data = JSON.parse(value[1]);
        return data;
    }
}

async function processQueue(queue) {
    while (true) {
        try {
            const data = await popFromQueue(queue);
        } catch (err) {
            console.error('Error processing job', err);
        }
    }
}

function ProcessingFunction(data) {
    const data = await processQueue('queueName')
    console.log(`Processing data: ${data}`);
}

calling ProcessingFunction() in a setTimeout

字符串

bjg7j2ky

bjg7j2ky1#

为了实现多队列的BLPOP,我们需要多个Redis Client示例。例如:

const queues = { name: 'queue1', client: null, ... }
// assigning the instance of the Redis client to all the queues in the queues

字符串
因此,当数据库1中没有数据时,该示例的连接将断开,Redis客户端的所有示例也是如此。
BLPOP有一个限制,因为我们不能像在LPOP中那样使用Limit

相关问题