Skip to content

Provide a way to iterate the nodes in a cluster shard so people can implement key scans on clusters #527

Open
@masariello

Description

@masariello

I would like to be able to SCAN keys in a cluster as in the below example code.

std::unordered_set<std::string> scan(std::string const& glob_expr)
{
  std::unordered_set<std::string> result;
  auto scan_node = [&](Redis& redis)
  {
    auto cursor = 0LL;
    do {
      cursor = redis.scan(cursor, glob_expr, [&](std::string const& k) { result.insert(k); });
    } while (cursor != 0);
  };

  ShardsPool shards_pool(...);
  for(auto const& slot : shards_pool->shards())
  {
    auto pool = shards_pool->fetch(slot.second());
    auto node = Redis(std::make_shared<GuardedConnection>(pool));
    scan_node(node));
  }
  return result;
}

The above uses the Redis::Redis(const GuardedConnectionSPtr &) which is private, so obviously not the cleanest approach.

A better way would be to add the following RedisCluster methods, please.

Shards RedisCluster::shards() const
{
  return pool_.shards();
}

ConnectionPoolSPtr RedisCluster::fetch(const Node & node)
{
  return pool_.fetch(node);
}

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions