Redis,主题(发布/订阅)是否总是至少交付给一个订阅者? [英] Redis, will a topic (pub/sub) always be delivered to at least one subscriber?

查看:76
本文介绍了Redis,主题(发布/订阅)是否总是至少交付给一个订阅者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果发生键/val 上的到期事件并且发送了一个主题,但所有客户端都关闭了,那么即使 一个 客户端上线并且在一年后该主题也将被传送并且订阅该主题?

If for instance an expiry event on a key / val occurs and a topic is sent out but all clients are down, will even in one years time that topic be delivered when one client comes online and subscribes to that topic?

如果两个客户稍后同时上网怎么办?

What if two clients go online later around the same time?

如果两个客户上网但中间有很大的延迟怎么办?

What if two clients go online but with a huge delay in between them?

这些主题稍后会广播,但我注意到如果我掉线并重新连接,我可以在重新上线时获得这些主题.

The topics are broadcasted later on, but I am noticing that if I am down and reconnect I can get the topics delivered when I go back online.

当我重新启动时,尽管它是新客户",但我没有得到旧的.

When I restart, I do not get the old one despite it being "a new client".

这是怎么回事?这个东西的内部规则是什么?

What is going on? What are the internal rules for this stuff?

推荐答案

Pub/Sub 是同步通信.各方需要同时处于活动状态才能进行通信.这里 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.

前三个问题的答案是否定的.消息没有持久性,不在磁盘中,不在内存中.当一条消息被发布时,它被发送到当时订阅的客户端连接.PUBLISH 命令将立即返回收到消息的客户端数量:O(N+M)其中 N 是订阅接收频道的客户端数量,M 是订阅模式的总数(任何客户端).

The answer to your first three questions is no. There is no persistence of the messages, not in disk, not in memory. When a message is published, it is sent to the client connections subscribed at the moment. The PUBLISH command will return the number of clients that received the message, immediately: O(N+M) where N is the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).

...但我注意到,如果我掉线并重新连接,我可以在重新上线时获得主题

... but I am noticing that if I am down and reconnect I can get the topics delivered when I go back online

R/我想这取决于你对我很失望"的意思.该消息必须缓存在您的客户端中的某处.或者也许 Redis 服务器中的客户端连接仍然有效,并且消息在客户端输出缓冲区中.

R/ I guess it depends on what you mean with "I am down". The message must have being cached somewhere in your client. Or maybe the client connection in Redis Server was still alive and the message was there in the Client Output Buffer.

您可能会发现这些资源很有用:

You may find this resources useful:

什么Redis Pub/Sub 和Redis Stream 之间的主要区别是什么?

发布/订阅

这篇关于Redis,主题(发布/订阅)是否总是至少交付给一个订阅者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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