Nordix / hiredis-cluster

C client library for Valkey/Redis Cluster. This project is used and sponsored by Ericsson. It is a fork of the now unmaintained hiredis-vip.
BSD 3-Clause "New" or "Revised" License
87 stars 42 forks source link

Example of pub/sub for keyspace notifications with async context #136

Closed SS-TruMinds closed 1 year ago

SS-TruMinds commented 1 year ago

Hello, do you have any examples of pub/sub for keyspace notifications with async contexts? Has this been tried before? Do you have any observations to share?

Thank you.

bjosv commented 1 year ago

Hi, there is currently no example of this in the repo, but it would be welcomed.

Due to the description in the "Events in a cluster" section (at the end of the page) I would guess the redisClusterAsyncCommandToNode() API should be used to subscribe to each nodes events. The given callback-function should then get the subscribe response, the pushed messages and the unsubscribe response (if triggered).

One caveat that I know of is that hiredis 1.1.0 should be used since 1.0.x had a bunch of issues regarding pubsub when using the async API.

SS-TruMinds commented 1 year ago

Hello,

Thank you for the response. We will try this out & try to provide an example.

I understand pub/sub would have to be on a separate async context, as this context cannot be used for other commands. I also understand that the same context can be used to subscribe to all the nodes of the cluster. Please could you confirm?

Thank you.

bjosv commented 1 year ago

Yes, I think you are right. If you are using RESP2 (the redis default) you would need a separate async context, and the same hiredis-cluster context can be used when subscribing to all nodes individually.