本文介绍了Redis Pub / Sub和Redis Stream之间的主要区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各自的优缺点是什么?
请建议何时使用一个而不是另一个。

What are the pros and cons of each?Please advice when to use one and not the other.

推荐答案

数据存储



Pub / Sub是发布者/订阅者平台,它不是数据存储。无论是否有订阅者,发布的消息都会消失。

Data storage

Pub/Sub is a Publisher/Subscriber platform, it's not data storage. Published messages evaporate, regardless if there was any subscriber.

在Redis Streams中,stream是一种数据类型,它本身就是一种数据结构。消息或条目存储在内存中,并保留在那里直到被命令删除。

In Redis Streams, stream is a data type, a data structure on its own right. Messages or entries are stored in memory and stay there until commanded to be deleted.

发布/订阅是同步通信。各方需要同时处于活动状态才能进行通信。 Redis在这里是纯同步消息代理。

Pub/Sub is synchronous communication. All parties need to be active at the same time to be able to communicate. Here Redis is a pure synchronous messaging broker.

Redis Streams允许两个同步( XREAD Block 和特殊的 $ ID)和异步通信。就像发布/订阅一样,但是能够在断开连接的情况下恢复而不丢失消息。

Redis Streams allows for both synchronous (XREAD with BLOCK and the special $ ID) and asynchronous communication. It is like Pub/Sub, but with the ability to resume on disconnection without losing messages.

Pub / Sub为最多一次,即开火即忘。

Pub/Sub is At-most-once, i.e. "fire and forget".

Redis Streams允许最多一次或最少一次(

Redis Streams allows for both At-most-once or At-least-once (explicit acknowledgement sent by the receiver)

Pub / Sub仅是阻止模式。订阅频道后,客户端将进入订阅者模式,并且无法发出命令( [P] SUBSCRIBE [P] UNSUBSCRIBE PING QUIT ),它已变为只读。

Pub/Sub is blocking-mode only. Once subscribed to a channel, the client is put into subscriber mode and it cannot issue commands (except for [P]SUBSCRIBE, [P]UNSUBSCRIBE, PING and QUIT), it has become read-only.

Redis Streams允许消费者是否以阻止模式阅读消息。

Redis Streams allows consumers to read messages in blocking mode or not.

Pub / Sub仅扇出。所有活动的客户端都会收到所有消息。

Pub/Sub is fan-out only. All active clients get all messages.

Redis Streams允许扇出(使用 XREAD ),还可以提供与相同的流向许多客户。这样就可以通过将不同的消息路由到不同的工作程序来扩展消息的处理,从而不可能将同一消息传递给多个使用者。最后一个场景是通过消费者组实现的。

Redis Streams allows fan-out (with XREAD), but also to provide a different subset of messages from the same stream to many clients. This allows scaling message processing, by routing different messages to different workers, in a way that it is not possible that the same message is delivered to multiple consumers. This last scenario is achieved with consumer groups.

Redis Streams提供了更多功能,例如时间戳,字段值对,范围等。这并不意味着您应该始终使用Streams。如果您的用例可以通过Pub / Sub实现,那么最好使用Pub / Sub。使用Streams,您必须关心内存使用情况。

Redis Streams provide many more features, like time-stamps, field-value pairs, ranges, etc. It doesn't mean you should always go for Streams. If your use-case can be achieved with Pub/Sub, it is better for you to use Pub/Sub then. With Streams, you have to care for memory usage.

这篇关于Redis Pub / Sub和Redis Stream之间的主要区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:29