如何在实时添加对象时从 Redis 弹出对象? [英] How can I pop objects from Redis as they are added realtime?
问题描述
我想让一个 Node.js 进程运行,因为它正在检查 Redis 服务器是否有任何新的弹出.
I want to get a Node.js process running as it's checking a Redis server for anything new to pop.
另一个进程将偶尔进行推送,Node 进程将尝试弹出任何传入的内容.Node 进程将保持运行.
Another process will be doing the pushing sporadically, and the Node process will be trying to pop whatever that comes in. The Node process will stay running.
谁能给我指出一个好的方向?
Can anyone point me to a good direction?
我正在尝试弄清楚如何侦听此类事件.当然,我可以弹出一次,但是如何让 Node 进程继续监听 Redis 服务器的任何添加?
I'm trying to figure out how to listen for such event. Sure, I can pop it once, but how do I get Node process to keep listening for any addition to Redis server?
推荐答案
你会想要使用阻塞弹出:http://redis.io/commands/brpop
You'll want to use a blocking pop: http://redis.io/commands/brpop
function waitForPush () {
client.brpop(['list','otherlist',0], function (listName, item) {
// do stuff
waitForPush();
});
}
这篇关于如何在实时添加对象时从 Redis 弹出对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!