Skip to content

Commit c7979a4

Browse files
committed
add zpopmin, zpopmax, bzpopmin, bzpopmax, client id, unblock
1 parent 2a94e4e commit c7979a4

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

includes/cpp_redis/core/client.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,18 @@ namespace cpp_redis {
513513

514514
std::future<reply> brpoplpush(const std::string &src, const std::string &dst, int timeout);
515515

516+
client& bzpopmin(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);
517+
518+
std::future<reply> bzpopmin(const std::vector<std::string>& keys, int timeout);
519+
520+
client& bzpopmax(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);
521+
522+
std::future<reply> bzpopmax(const std::vector<std::string>& keys, int timeout);
523+
524+
client& client_id(const reply_callback_t& reply_callback);
525+
526+
std::future<reply> client_id();
527+
516528
//<editor-fold desc="client">
517529
template<typename T, typename... Ts>
518530
client &client_kill(const std::string &host, int port, const T &arg, const Ts &... args);
@@ -549,6 +561,12 @@ namespace cpp_redis {
549561
std::future<reply> client_setname(const std::string &name);
550562
//</editor-fold>
551563

564+
client& client_unblock(int id, const reply_callback_t& reply_callback);
565+
566+
client& client_unblock(int id, bool witherror, const reply_callback_t& reply_callback);
567+
568+
std::future<reply> client_unblock(int id, bool witherror = false);
569+
552570
client &cluster_addslots(const std::vector<std::string> &p_slots, const reply_callback_t &reply_callback);
553571

554572
std::future<reply> cluster_addslots(const std::vector<std::string> &p_slots);
@@ -1690,6 +1708,14 @@ namespace cpp_redis {
16901708

16911709
std::future<reply> zlexcount(const std::string &key, const std::string &min, const std::string &max);
16921710

1711+
client& zpopmin(const std::string& key, int count, const reply_callback_t& reply_callback);
1712+
1713+
std::future<reply> zpopmin(const std::string& key, int count);
1714+
1715+
client& zpopmax(const std::string& key, int count, const reply_callback_t& reply_callback);
1716+
1717+
std::future<reply> zpopmax(const std::string& key, int count);
1718+
16931719
client &zrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback);
16941720

16951721
client &

sources/core/client.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,30 @@ namespace cpp_redis {
623623
return *this;
624624
}
625625

626+
client&
627+
client::bzpopmin(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback) {
628+
std::vector<std::string> cmd = {"BZPOPMIN"};
629+
cmd.insert(cmd.end(), keys.begin(), keys.end());
630+
cmd.push_back(std::to_string(timeout));
631+
send(cmd, reply_callback);
632+
return *this;
633+
}
634+
635+
client&
636+
client::bzpopmax(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback) {
637+
std::vector<std::string> cmd = {"BZPOPMAX"};
638+
cmd.insert(cmd.end(), keys.begin(), keys.end());
639+
cmd.push_back(std::to_string(timeout));
640+
send(cmd, reply_callback);
641+
return *this;
642+
}
643+
644+
client&
645+
client::client_id(const reply_callback_t& reply_callback) {
646+
send({"CLIENT", "ID"}, reply_callback);
647+
return *this;
648+
}
649+
626650
client &
627651
client::client_list(const reply_callback_t &reply_callback) {
628652
send({"CLIENT", "LIST"}, reply_callback);
@@ -653,6 +677,21 @@ namespace cpp_redis {
653677
return *this;
654678
}
655679

680+
client&
681+
client::client_unblock(int id, const reply_callback_t& reply_callback) {
682+
send({"CLIENT", "UNBLOCK", std::to_string(id)}, reply_callback);
683+
return *this;
684+
}
685+
686+
client&
687+
client::client_unblock(int id, bool witherror, const reply_callback_t& reply_callback) {
688+
if (witherror)
689+
send({"CLIENT", "UNBLOCK", std::to_string(id), "ERROR"}, reply_callback);
690+
else
691+
send({"CLIENT", "UNBLOCK", std::to_string(id)}, reply_callback);
692+
return *this;
693+
}
694+
656695
client &
657696
client::cluster_addslots(const std::vector<std::string> &p_slots, const reply_callback_t &reply_callback) {
658697
std::vector<std::string> cmd = {"CLUSTER", "ADDSLOTS"};
@@ -2529,6 +2568,18 @@ namespace cpp_redis {
25292568
return *this;
25302569
}
25312570

2571+
client&
2572+
client::zpopmin(const std::string& key, int count, const reply_callback_t& reply_callback) {
2573+
send({"ZPOPMIN", key, std::to_string(count)}, reply_callback);
2574+
return *this;
2575+
}
2576+
2577+
client&
2578+
client::zpopmax(const std::string& key, int count, const reply_callback_t& reply_callback) {
2579+
send({"ZPOPMAX", key, std::to_string(count)}, reply_callback);
2580+
return *this;
2581+
}
2582+
25322583
client &
25332584
client::zrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback) {
25342585
send({"ZRANGE", key, std::to_string(start), std::to_string(stop)}, reply_callback);
@@ -3239,6 +3290,21 @@ namespace cpp_redis {
32393290
return exec_cmd([=](const reply_callback_t &cb) -> client & { return brpoplpush(src, dst, timeout, cb); });
32403291
}
32413292

3293+
std::future<reply>
3294+
client::bzpopmin(const std::vector<std::string>& keys, int timeout) {
3295+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return bzpopmin(keys, timeout, cb); });
3296+
}
3297+
3298+
std::future<reply>
3299+
client::bzpopmax(const std::vector<std::string>& keys, int timeout) {
3300+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return bzpopmax(keys, timeout, cb); });
3301+
}
3302+
3303+
std::future<reply>
3304+
client::client_id() {
3305+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return client_id(cb); });
3306+
}
3307+
32423308
std::future<reply>
32433309
client::client_list() {
32443310
return exec_cmd([=](const reply_callback_t &cb) -> client & { return client_list(cb); });
@@ -3264,6 +3330,11 @@ namespace cpp_redis {
32643330
return exec_cmd([=](const reply_callback_t &cb) -> client & { return client_setname(name, cb); });
32653331
}
32663332

3333+
std::future<reply>
3334+
client::client_unblock(int id, bool witherror) {
3335+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return client_unblock(id, witherror, cb); });
3336+
}
3337+
32673338
std::future<reply>
32683339
client::cluster_addslots(const std::vector<std::string> &p_slots) {
32693340
return exec_cmd([=](const reply_callback_t &cb) -> client & { return cluster_addslots(p_slots, cb); });
@@ -4406,6 +4477,15 @@ namespace cpp_redis {
44064477
return exec_cmd([=](const reply_callback_t &cb) -> client & { return zlexcount(key, min, max, cb); });
44074478
}
44084479

4480+
std::future<reply>
4481+
client::zpopmin(const std::string& key, int count) {
4482+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return zpopmin(key, count, cb); });
4483+
}
4484+
std::future<reply>
4485+
client::zpopmax(const std::string& key, int count) {
4486+
return exec_cmd([=](const reply_callback_t& cb) -> client& { return zpopmax(key, count, cb); });
4487+
}
4488+
44094489
std::future<reply>
44104490
client::zrange(const std::string &key, int start, int stop, bool withscores) {
44114491
return exec_cmd([=](const reply_callback_t &cb) -> client & { return zrange(key, start, stop, withscores, cb); });

0 commit comments

Comments
 (0)