我应该使用单独的连接Pub和Sub与Redis? [英] Should I use separate connections for Pub and Sub with Redis?

查看:243
本文介绍了我应该使用单独的连接Pub和Sub与Redis?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,Socket.io 正在使用Pub和Sub到Redis 服务器的两个单独的连接。这可以提高性能吗?还是只是纯粹是为了更有条理的事件处理程序和代码?两个单独的连接的好处和缺点是什么,一个单独的连接用于发布和订阅。

I have noticed that Socket.io is using two separate connections for Pub and Sub to Redis server. Is it something that could improve the performance? Or is it just purely a move towards more organized event handlers and code? What are the benefits and drawbacks of the two separate connections and one single connections for publishing and subscribing.

PS 系统正在推动平等它接收的消息数。它将更新推送到层次结构中位于同一级别的服务器,因此没有主服务器,推送所有更新或从服务器,消耗消息。一个服务器将有大约4-8个订阅,它会将消息发送回这些服务器。

P.S. The system is pushing about an equal number of messages that it is receiving. It pushes updates to the servers, which are on the same level in the hierarchy, so there is no master, pushing all of the updates, or slave, consuming the messages. One server would have about 4-8 subscriptions and it will send the messages back to these servers.

PSS 这是一个更好的工作专用工作队列?我在找Redis的原因。是我已经保留了一些共享的对象,它被所有服务器使用。消息队列是否添加另一个网络连接?

P.S.S. Is this more of a job for a purpose-built job queue? The reason I am looking at Redis. is that I am already keeping some shared objects in it, which are used by all servers. Is message queue worth adding yet another network connection?

推荐答案

您需要 使用两个连接酒吧和小酒吧订阅者连接无法发出订阅以外的任何命令 psubscribe 取消订阅 punsubscribe (虽然@Antirez暗示了一个订阅者安全 ping 在将来)。如果您尝试执行其他操作,redis会告诉您:

You are required to use two connections for pub and sub. A subscriber connection cannot issue any commands other than subscribe, psubscribe, unsubscribe, punsubscribe (although @Antirez has hinted of a subscriber-safe ping in the future). If you try to do anything else, redis tells you:

-ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context

(请注意,您无法使用redis-cli,因为它了解协议足够好,以防止您在订阅后发出命令 - 但任何其他基本的套接字工具都应该正常工作)

(note that you can't test this with redis-cli, since that understands the protocol well enough to prevent you from issuing commands once you have subscribed - but any other basic socket tool should work fine)

这是因为订户连接的工作方式大不相同,而不是按照请求/响应方式工作,所以现在可以随时收到新的消息。主动请求。

This is because subscriber connections work very differently - rather than working on a request/response basis, incoming messages can now come in at any time, unsolicited.

发布是一个常规的请求/响应命令,因此必须在常规连接上发送,而不是用户连接。

publish is a regular request/response command, so must be sent on a regular connection, not a subscriber connection.

这篇关于我应该使用单独的连接Pub和Sub与Redis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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