sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[FEATURE] Provide ability to perform redis-node level operations with AsyncRedisCluster interface #459

Closed mrichmon closed 1 year ago

mrichmon commented 1 year ago

Is your feature request related to a problem? Please describe. In general, the async interfaces should mirror the synchronous interfaces. I have a need to perform operations such as INFO that require an instance of the Redis class or the AsyncRedis class. Unfortunately the AsyncRedisCluster class does not appear to provide a way to obtain an instance of a AsyncRedis class.

Describe the solution you'd like Provide the ability to obtain an instance of AsyncRedis from an AsyncRedisCluster instance. This should mirror the functionality provided by calling RedisCluster->redis(hashslot_id)

Alternate option: Provide a mechanism on AsyncRedisCluster to issue a generic command to a specific node. This could also be useful on RedisCluster to avoid the need to obtain an instance of Redis(). For example:

auto myAsyncCluster = AsyncRedisCluster(myConnectionOptions, myPoolOptions);
auto command = {"INFO"};
int nodeHashslot = 0;  // hashslot identifier for the desired node
auto futureResult = myAsyncCluster.command<sw::redis::OptionalString>(nodeHashslot, command.begin(), command.end());
...
auto infoString = futureResult.get();

Is there an existing way to perform redis node-specific operations starting from an AsyncRedisCluster() instance?

sewenew commented 1 year ago

I'll try to support AsyncRedisCluster::redis interface. It might not a good idea to expose hash slot number to client code, since it's implementation detail. Thanks for your suggestion!

Regards

sewenew commented 1 year ago

Finally finished! However, instead of slot number, you need to use a hash-tag to specify the node. The behavior is consistent with RedisCluster.

Please try the latest code on master branch. Sorry for the delay....

Regards

mrichmon commented 1 year ago

Confirmed working with:

std::string hashtag = "0";
auto myCommand = {"INFO"};
auto redis = myRedisCluster->redis(hashtag);
result = redis.command<sw::redis::OptionalString>(myCommand.begin(), myCommand.end()).get();
std::cout << (result.has_value() ? result.value() : "") << std::endl;