sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.6k stars 347 forks source link

[QUESTION] Is it possible to ask for the list of nodes in a cluster? #482

Closed mlanzuisi closed 1 year ago

mlanzuisi commented 1 year ago

I would like to understand if there is any specific command to use to ask for the list of nodes in a cluster, like to have "redis-cli cluster nodes" output, or if it done via the generic command() interface.

sewenew commented 1 year ago

Yes, you need to use generic command interface to send cluster related command, e.g. cluster slots, to get the nodes info. Check this issue for an example on how to parse the reply.

Regards

mlanzuisi commented 1 year ago

I don't know why, but I have an error in compilation for this line

auto slots = r.command<std::vector>("CLUSTER", "SLOTS").get();

the error is

cache-lib.cc.o.d -o CMakeFiles/cache.dir/cache-lib.cc.o -c /home/mlanzuisi/redis-library/cache-lib/cache-lib.cc /home/mlanzuisi/redis-library/cache-lib/cache-lib.cc: In member function ‘std::unordered_set<std::basic_string > CacheConnection::Scan(const char*)’: /home/mlanzuisi/redis-library/cache-lib/cache-lib.cc:842:97: error: ‘class std::vector<std::tuple<long long int, long long int, std::tuple<std::basic_string<char, std::char_traits, std::allocator >, long long int, std::basic_string<char, std::char_traits, std::allocator > > > >’ has no member named ‘get’ auto slots = redis_connection.command<std::vector>("CLUSTER", "SLOTS").get();

This is the cmake output

Detected version: 1.1.0 -- redis-plus-plus version: 1.3.7 -- redis-plus-plus build type: Release -- redis-plus-plus build with CXX standard: c++11 -- redis-plus-plus TLS support: ON -- redis-plus-plus build static library: ON -- redis-plus-plus build static library with position independent code: ON -- redis-plus-plus build shared library: ON -- redis-plus-plus build test: ON -- Debian package name: .deb -- Configuring done -- Generating done -- Build files have been written to:

sewenew commented 1 year ago

That issue is related to async interface, which returns a future object, and you need to call future::get.

If you don't use async interface, you don't need to do the get call:

auto slots = r.command<std::vector>("CLUSTER", "SLOTS");

Regards

mlanzuisi commented 1 year ago

Thank you so much. It works

sewenew commented 1 year ago

I'll close this issue, since the problem has been solved. If you still have problem feel free to open a new one. If you like it, feel free to star it :)

Regards