Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could you please add pub/sub support? #27

Open
sddongxh opened this issue Jan 26, 2021 · 2 comments
Open

could you please add pub/sub support? #27

sddongxh opened this issue Jan 26, 2021 · 2 comments

Comments

@sddongxh
Copy link

Thanks.

@andreasgerstmayr
Copy link
Contributor

Reading https://redis.io/commands/pubsub you can send PUBLISH/SUBSCRIBE to any node in the cluster. You can use redisClusterAsyncCommandToNode() to send a command directly to a specific node.

Should hiredis-cluster send the command a specific node by hashing the channel (as it does for regular Redis keys)?

@zuiderkwast
Copy link
Collaborator

zuiderkwast commented Apr 13, 2021

Should hiredis-cluster send the command a specific node by hashing the channel (as it does for regular Redis keys)?

No, pubsub channels are not sharded like keys. They are forwarded between the Redis nodes in a cluster, so you can subscribe to any node and publish to any node. (Pubsub doesn't scale that well in a large cluster since all messages are forwarded to all nodes, but that's different topic.)

I'm not sure what is the best way to implement this in hiredis-cluster but it can be good to know that when using pubsub, you typically need a dedicated connection to receive published messages. The documentation of SUBSCRIBE says:

Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING, RESET and QUIT commands.

[Edit] For commands like PUBSUB CHANNELS and PUBSUB NUMSUB, you need to send the command to all nodes and then combine the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants