sewenew / redis-plus-plus

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

[QUESTION] How can I user hset() with multiple fields together? #483

Closed mlanzuisi closed 1 year ago

mlanzuisi commented 1 year ago

I'm using the hset() function as described in the readme file examples. Is it possible to use it to match the

HSET key field value [field value ...]

syntax (with multiple fields/values)?

sewenew commented 1 year ago

You can try the following code:

std::unordered_map<std::string, std::string> m = {{"f1", "v1"}, {"f2", "v2"}};
redis.hset("hash", m.begin(), m.end());

redis.hset("hash", {std::make_pair("f1", "v1"), std::make_pair("f2", "v2")});

Also check redis.h for more info.

Regrads

mlanzuisi commented 1 year ago

Thank you for the support, I will check better redis.h in the future