Open arwace opened 1 year ago
Hi @arwace!
No, unfortunately hiredis-cluster does not support any kind of subscribe (SUBSCRIBE, PSUBSCRIBE, SSUBSCRIBE). See #27.
Regarding SSUBSCRIBE, not even the underlying hiredis
supports it. See https://github.com/redis/hiredis/pull/1066.
redis-cli
(which comes with redis) can support ssubscribe and it uses hiredis, but it does it's own handling. (It calls redisGetReply()
repeatedly and checks if each reply looks like a pushed pubsub message.)
If you have a blocking thread to consume messages, one possible workaround is to use hiredis
directly. You can get the hiredis context from hiredis-cluster like this:
redisClusterNode *node = redisClusterGetNodeByKey(cc, "channel");
redisContext *c = ctx_get_by_node(cc, node);
Then use hiredis functions with context c, for example to get all pubsub messages in a loop.
redisReply *reply = redisCommand(c, "SSUBSCRIBE channel");
freeReplyObject(reply);
while (redisGetReply(c, (void *)&reply) == REDIS_OK) {
// consume message
freeReplyObject(reply);
}
Neither synchronous nor asynchronous mode can handle SSUBSCRIBE.
Is there an example that handles SSUBSCRIBE?