Redis,监听pubsub事件并将其转为流,以实现更可靠的消费 [英] Redis, listening to pubsub events and turning them into a stream for more reliable consumption

查看:36
本文介绍了Redis,监听pubsub事件并将其转为流,以实现更可靠的消费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Redis,很熟悉.现在,我面临的情况是,正常的 PUBSUB 机制并不是处理某些情况的好方法.

Using Redis, quite familiar. Now, I am facing a situation where the normal PUBSUB mechanism won't really be a great way to handle certain situations.

取一个哈希,我们说使用 HSET 存储对另一个哈希的引用.

Take a hash where we say store a reference to another hash using say HSET.

HSET "davids.trips" "trip1" "Stockholm"
HSET "davids.trips" "trip2" "London"

HSET "david" "age"   "12"
HSET "david" "trips" "davids.trips"       # Reference to the previous hash

现在,最后一个内部已知并作为引用哈希处理.

Now, the last one internally is known and handled as reference hash.

然而,我们现在面临的问题是,当 expire 现在发生在地图 david" 上时,我们希望能够使 davids 失效.旅行,所以它不会徘徊.

However, the problem we are facing now, is when expire now occurs on map "david" we would like the ability to invalidate the davids.trips as well so it does not linger along.

现在,我们可以在 HSETdavid"上发布订阅到期.说,但是如果我们的服务器宕机了,那么我们将无法恢复它,它就会丢失在我们身上.

Now, we can pubsub to expire on HSET "david" say, but if our server is down then we won't be able to pick it up and it will be lost on us.

从 Java 执行此操作,我们可能会丢失过期发布订阅消息.

Doing this from Java and we run into the possibility of missing the expire pubsub message.

相反,如果我们通过 stream 接收消息,则消息必须至少被一个人消费,我们才能确保它被清除.

Instead, if we where to receive the message over a stream instead, the message would have to be consumed by at least one and we could ensure it is cleared.

现在,我们该怎么做?

我们可以轻松地将发布订阅消息转换为类似流的行为吗?

Can we convert pubsub messages to stream like behaviour easily?

如果是这样,怎么办?我正在使用 Jedis,但我可以发送一些代码来执行此操作.理想情况下,转换将在 Redis 服务器内进行,以便发布订阅消息永远不会转换为 Streams.

If so, how? I am using Jedis but I can send some code to potentially do this. Ideally, the conversion would happen within Redis server so that pubsub messages are never not transformed into Streams.

顺便说一句:https://redis.io/topics/pubsub 我们可以找到:"请注意,一旦进入订阅模式,redis-cli 将不会接受任何命令,只能使用 Ctrl-C 退出该模式." 所以问题是,如果我们要订阅,它会阻塞在 Redis 中,然后尝试使用它们并将它们转换为流.

Btw on : https://redis.io/topics/pubsub we can find: "Please note that redis-cli will not accept any commands once in subscribed mode and can only quit the mode with Ctrl-C." So the problem is that it becomes blocking if we were to subscribe within Redis and then try to consume and turn them into streams.

必须有一种方法可以使用 lua 和 pubsub 创建线程吗?

There has to be a way to create a thread using lua and pubsub there?

推荐答案

Redis 7.0 将带来 key带有流的空间通知,也许这可以解决您的问题.

Redis 7.0 will bring key space notifications with stream, may be this can solve your problem.

这篇关于Redis,监听pubsub事件并将其转为流,以实现更可靠的消费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆