When using hiredis, use redisAppendCommand to put multiple hincrby commands, the reply->type result of redisGetReply is REDIS_REPLY_INTEGER, and only one of the results is returned.
But when I use hmget, the result of reply->type is REDIS_REPLY_ARRAY.
[hiredis]Multiple hincrbys only return one result(REDIS_REPLY_INTEGER)
176 views Asked by Stream_ At
2
There are 2 answers
1
On
Thank you very much for answering my question.
And the official reply from HIREDIS is here.
https://github.com/redis/hiredis/issues/1143
This is correct given the specifications of both commands.
The hmget command returns an array reply, while hincrby returns an. integer.
Here is a small example that appends several HINCRBY commands and then prints each of the replies.
Since you call
redisAppendCommandmultiple times, you should callredisGetReplythe same number of times to get all replies. For each reply, it's of typeREDIS_REPLY_INTEGER. Because the reply type ofhincrbyis integer type, or array type.The reply type of
hmgetis array reply, and that's why you getREDIS_REPLY_ARRAY.Since you tag the question with
c++, you can try redis-plus-plus, which is a user-friendly C++ client for Redis and you don't need to parse the reply manually:Disclaimer: I'm the author of redis-plus-plus.