Closed mlanzuisi closed 1 year ago
The code you posted cannot compile, i.e. not specifying template type for std::vector
please give the exact code you used. Also please give the Redis server info, e.g. version. Since different version might return different shards info.
Regards
Sorry, I was making tests and I used the wrong copy/paste. This is the correct code:
std::vector\<OptionalString> val = m_redis_servers[0]->command\<std::vector\<OptionalString>>("CLUSTER", "SHARDS");
that returns the error. Here the redis server info
redis_version:7.0.9 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:a7db51f3965d7ff7 redis_mode:cluster os:Linux 3.10.0-1160.88.1.el7.x86_64 x86_64
CLUSTER SHARDS
returns a nested array reply, instead of an array of strings. So you need to call the command with a template parameter that can hold the nested array.
using SlotInfo = std::pair<std::string, std::string>;
using NodeInfo = std::unordered_map<std::string, std::variant<std::string, long long>>;
using Result = std::vector<std::variant<std::string, std::vector<NodeInfo>, SlotInfo>>;
auto result = r.command<std::vector<Result>>("CLUSTER", "SHARDS");
Check cluster shards doc, c++ std::variant, and redis-plus-plus doc for more info.
Regards
Since there's no update, I'll close the issue
Regards
I could not test it so far, so I didn't add anything, Thank you so much for the answer.
Hello,
I tried sending a generic command to a single server of a Redis Cluster (instance 0 of an array) with the following code:
std::vector val = m_redis_servers[0]->command<std::vector>("CLUSTER", "SHARDS");
copying from examples, but I receive this error:
terminate called after throwing an instance of 'sw::redis::ParseError' what(): expect STRING or STATUS or VERB or BIGNUM reply, but got ARRAY reply
and if I try using the std::array structure it is not compiling. Did I do something wrong?
Environment: