Skip to content

Commit

Permalink
Add mset Callback interface (#551)
Browse files Browse the repository at this point in the history
Co-authored-by: jasonxie <jasonxie@intranet.123u.com>
  • Loading branch information
reneetse and jasonxie authored Mar 9, 2024
1 parent f779c71 commit eb3b2a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sw/redis++/async_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ class AsyncRedis {
Future<void> mset(std::initializer_list<T> il) {
return mset(il.begin(), il.end());
}

template <typename Input, typename Callback>
auto mset(Input first, Input last, Callback &&cb)
-> typename std::enable_if<IsInvocable<typename std::decay<Callback>::type, Future<void> &&>::value, void>::type {
range_check("MSET", first, last);

_callback_fmt_command<void>(std::forward<Callback>(cb), fmt::mset<Input>, first, last);
}

template <typename Input>
Future<bool> msetnx(Input first, Input last) {
Expand Down
8 changes: 8 additions & 0 deletions src/sw/redis++/async_redis_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ class AsyncRedisCluster {
return mset(il.begin(), il.end());
}

template <typename Input, typename Callback>
auto mset(Input first, Input last, Callback &&cb)
-> typename std::enable_if<IsInvocable<typename std::decay<Callback>::type, Future<void> &&>::value, void>::type {
range_check("MSET", first, last);

_callback_fmt_command<void>(std::forward<Callback>(cb), fmt::mset<Input>, first, last);
}

template <typename Input>
Future<bool> msetnx(Input first, Input last) {
range_check("MSETNX", first, last);
Expand Down
7 changes: 7 additions & 0 deletions test/src/sw/redis++/async_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ void AsyncTest<RedisInstance>::_test_hash() {
this->set_ready();
});
_wait();

set_ready(false);
std::map<std::string, std::string> mkeys = {{test_key("str")+"1", "val1"}, {test_key("str")+"2", "val2"}};
_redis.mset(mkeys.begin(), mkeys.end(), [this](Future<void> &&fut) {
this->set_ready();
});
_wait();
}

template <typename RedisInstance>
Expand Down

0 comments on commit eb3b2a4

Please sign in to comment.