sewenew/redis-plus-plus

Async hgetall() - Is the result struct wrong?

mlanzuisi opened this issue · 5 comments

Hi,

I tried implementing the synchronous and asynchronous "hgetall()" function, but I have issues with the asynchronous part.
When trying to run the following code (as desribed in Readme):

std::future<std::vectorstd::string> future = m_async_redis_cluster->hgetall<std::vectorstd::string>(key_sw);
for (const auto &ele : future.get())
std::printf("HGetAll async string "%s"\n", ele.c_str());

or simply using

future.get()

I got the following error:

"expect ARRAY or SET reply, but got UNKNOWN reply"

Am I doing anything wrong here?

Sorry, but I cannot reproduce your problem with the latest redis-plus-plus code.

Please give version info of redis-plus-plus, hiredis, and Redis-server. Also give a smallest compilable code that can reproduce the problem.

Regards

By the way, the example given in README is not a good one, I'll fix it ASAP. Since hgetall returns key-value pairs, you'd better use an unordered_map as the template parameter.

auto res = m_async_redis_cluster->hgetall<std::unordered_map<std::string, std::string>>("hash");

Using your last comment solved my issue, now it works with the unordered map future

I know what the problem is. Looks like you used RESP3, in this case, HGETALL returns a map reply instead of an array reply. So when you try to parse it as a vector, it throws the exception. Instead, you need to parse it as a map or unordered_map.

Thanks for finding the corner case! I'll close this issue. If you still have problem, feel free to reopen it :)

Regards

Yes, you are right. I use RESP3.

Thank you and regards