Skip to content
New issue

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

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

Already on GitHub? # to your account

Problem to subscribe #143

Open
arwace opened this issue Feb 19, 2023 · 1 comment
Open

Problem to subscribe #143

arwace opened this issue Feb 19, 2023 · 1 comment

Comments

@arwace
Copy link

arwace commented Feb 19, 2023

Hello?

I'm having trouble subscribing.
When I use redisClusterCommand, I get an error saying that I don't have a key and shouldn't do it,
When using redisClusterCommandToNode, the SUBSCRIBE command works fine, but I can't get the publish data with redisClusterGetReply.
What should I do in this case?

@zuiderkwast
Copy link
Collaborator

Hi! Subscribe is not yet supported by hiredis-cluster. We want to fix it in the future. See #27.

One possibility to get the published data is to use hiredis directly. You can get the hiredis context from hiredis-cluster like this:

/* Get a node. */
nodeIterator iter;
initNodeIterator(&iter, cc);
redisClusterNode *node = nodeNext(&iter);
/* Another way is
 * node = redisClusterGetNodeByKey(cc, "some key");
 */

/* Get the hiredis context, connect if needed */
redisContext *c = ctx_get_by_node(cc, node);

/* Use hiredis functions with context c,
 * for example loop to get all pubsub messages */
redisReply *reply = redisCommand(c, "SUBSCRIBE foo");
freeReplyObject(reply);
while (redisGetReply(c, (void *)&reply) == REDIS_OK) {
    // consume message
    freeReplyObject(reply);
}

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

No branches or pull requests

2 participants