Closed LazyHippogriff closed 5 years ago
after expansion your API will look like this, reply = (redisReply)(redisClusterCommand(cc,"hmget test_hash bin1_name bin3_name"); When you say it does not work. Means you are getting local error from the client library ? or you are getting rejection from the server ?
I meant that I'm not getting the values. Here's the code in bit more detail:
redisReply *reply;
reply = (redisReply*)(redisClusterCommand(cc,"hmget test_hash bin1_name bin3_name"));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY) {
for (int j = 0; j < reply->elements; j++) {
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
string set_name="test_hash";
string bin_names="bin1_name bin3_name";
reply = (redisReply*)(redisClusterCommand(cc,"hmget %s %s",set_name.c_str(),bin_names.c_str()));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY) {
for (int j = 0; j < reply->elements; j++) {
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
Output
reply type: 2
0)bin1_value
1)bin3_val
reply type: 2
0) (null)
I am not sure about the syntax you used, redisClusterCommand(cc,"hmget %s %s",set_name.c_str(),bin_names.c_str()) Can you please form the string first and then pass it like below string cmd = "hmget" + set_name + bin_names; redisClusterCommand(cc, cmd.c_str());
Thanks Ajay
redisReply *reply;
string set_name="test_hash";
string bin_names="bin1_name bin3_name";
string command = string("hmget ")+set_name+string(" ")+bin_names;
cout<<endl<<command<<endl;
reply = (redisReply*)(redisClusterCommand(cc,"%s",command.c_str()));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY) {
for (int j = 0; j < reply->elements; j++) {
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
Output
hmget test_hash bin1_name bin3_name
Error: Parse command error. Cmd type: 0, state: 5, break position: 44.
Sorry my code above is not exactly as per your suggestion. You're right. Your suggestion worked.
redisReply *reply;
string set_name="test_hash";
string bin_names="bin1_name bin3_name";
string command = string("hmget ")+set_name+string(" ")+bin_names;
cout<<endl<<command<<endl;
reply = (redisReply*)(redisClusterCommand(cc, command.c_str()));
if (cc != NULL && cc->err)
printf("Error: %s\n", cc->errstr);
else
{
cout<<endl<<"reply type: "<<reply->type<<endl;
if (reply->type == REDIS_REPLY_ARRAY) {
for (int j = 0; j < reply->elements; j++) {
printf("%u) %s\n", j, reply->element[j]->str);
}
}
}
freeReplyObject(reply);
Output
hmget test_hash bin1_name bin3_name
reply type: 2
0) bin1_value
1) bin3_val
The below code works fine. I can get the values back from the server: redisReply reply; reply = (redisReply)(redisClusterCommand(cc,"hmget test_hash bin1_name bin3_name"));
However, the below code doesn't work: redisReply reply; string set_name="test_hash"; string bin_names="bin1_name bin3_name"; reply = (redisReply)(redisClusterCommand(cc,"hmget %s %s",set_name.c_str(),bin_names.c_str()));
How can I make the above code work?