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
83 stars 41 forks source link

Does hiredis-cluster support SCAN #216

Open throwbear opened 2 months ago

throwbear commented 2 months ago

I call redisClusterCommand func to execute SCAN operation but got err:No keys in command(must have keys for redis cluster mode)

the code is as follows:

  cluster_ctx = redisClusterContextInit();
  redisClusterSetOptionAddNodes(cluster_ctx, rdbhosts);
  redisClusterConnect2(cluster_ctx);
  if (cluster_ctx == NULL || cluster_ctx->err)
  {
    printf("Error connect cluster: %s\n", cluster_ctx->errstr);
  }
  int cursor = 0;
  char *pattern = "key*";
  redisReply *reply = redisClusterCommand(cluster_ctx, "SCAN %d MATCH %s", cursor, pattern);
  if (reply == NULL)
  {
    printf("scan cluster reply null: %s\n", cluster_ctx->errstr);
  }
  redisClusterFree(cluster_ctx);
bjosv commented 2 months ago

The suggestion is to use the low-level API, see this issue https://github.com/Nordix/hiredis-cluster/issues/50#issuecomment-880626616 with similar topic.

Unfortunately there are no examples of SCAN, but maybe you can get some ideas from https://github.com/Nordix/hiredis-cluster/blob/master/tests/ct_specific_nodes.c#L46 ?