Skip to content

add zpopmin, zpopmax, bzpopmin, bzpopmax, client id, unblock #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions includes/cpp_redis/core/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ namespace cpp_redis {

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

client& bzpopmin(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);

std::future<reply> bzpopmin(const std::vector<std::string>& keys, int timeout);

client& bzpopmax(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);

std::future<reply> bzpopmax(const std::vector<std::string>& keys, int timeout);

client& client_id(const reply_callback_t& reply_callback);

std::future<reply> client_id();

//<editor-fold desc="client">
template<typename T, typename... Ts>
client &client_kill(const std::string &host, int port, const T &arg, const Ts &... args);
Expand Down Expand Up @@ -549,6 +561,12 @@ namespace cpp_redis {
std::future<reply> client_setname(const std::string &name);
//</editor-fold>

client& client_unblock(int id, const reply_callback_t& reply_callback);

client& client_unblock(int id, bool witherror, const reply_callback_t& reply_callback);

std::future<reply> client_unblock(int id, bool witherror = false);

client &cluster_addslots(const std::vector<std::string> &p_slots, const reply_callback_t &reply_callback);

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

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

client& zpopmin(const std::string& key, int count, const reply_callback_t& reply_callback);

std::future<reply> zpopmin(const std::string& key, int count);

client& zpopmax(const std::string& key, int count, const reply_callback_t& reply_callback);

std::future<reply> zpopmax(const std::string& key, int count);

client &zrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback);

client &
Expand Down
80 changes: 80 additions & 0 deletions sources/core/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,30 @@ namespace cpp_redis {
return *this;
}

client&
client::bzpopmin(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback) {
std::vector<std::string> cmd = {"BZPOPMIN"};
cmd.insert(cmd.end(), keys.begin(), keys.end());
cmd.push_back(std::to_string(timeout));
send(cmd, reply_callback);
return *this;
}

client&
client::bzpopmax(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback) {
std::vector<std::string> cmd = {"BZPOPMAX"};
cmd.insert(cmd.end(), keys.begin(), keys.end());
cmd.push_back(std::to_string(timeout));
send(cmd, reply_callback);
return *this;
}

client&
client::client_id(const reply_callback_t& reply_callback) {
send({"CLIENT", "ID"}, reply_callback);
return *this;
}

client &
client::client_list(const reply_callback_t &reply_callback) {
send({"CLIENT", "LIST"}, reply_callback);
Expand Down Expand Up @@ -653,6 +677,21 @@ namespace cpp_redis {
return *this;
}

client&
client::client_unblock(int id, const reply_callback_t& reply_callback) {
send({"CLIENT", "UNBLOCK", std::to_string(id)}, reply_callback);
return *this;
}

client&
client::client_unblock(int id, bool witherror, const reply_callback_t& reply_callback) {
if (witherror)
send({"CLIENT", "UNBLOCK", std::to_string(id), "ERROR"}, reply_callback);
else
send({"CLIENT", "UNBLOCK", std::to_string(id)}, reply_callback);
return *this;
}

client &
client::cluster_addslots(const std::vector<std::string> &p_slots, const reply_callback_t &reply_callback) {
std::vector<std::string> cmd = {"CLUSTER", "ADDSLOTS"};
Expand Down Expand Up @@ -2529,6 +2568,18 @@ namespace cpp_redis {
return *this;
}

client&
client::zpopmin(const std::string& key, int count, const reply_callback_t& reply_callback) {
send({"ZPOPMIN", key, std::to_string(count)}, reply_callback);
return *this;
}

client&
client::zpopmax(const std::string& key, int count, const reply_callback_t& reply_callback) {
send({"ZPOPMAX", key, std::to_string(count)}, reply_callback);
return *this;
}

client &
client::zrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback) {
send({"ZRANGE", key, std::to_string(start), std::to_string(stop)}, reply_callback);
Expand Down Expand Up @@ -3239,6 +3290,21 @@ namespace cpp_redis {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return brpoplpush(src, dst, timeout, cb); });
}

std::future<reply>
client::bzpopmin(const std::vector<std::string>& keys, int timeout) {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return bzpopmin(keys, timeout, cb); });
}

std::future<reply>
client::bzpopmax(const std::vector<std::string>& keys, int timeout) {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return bzpopmax(keys, timeout, cb); });
}

std::future<reply>
client::client_id() {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return client_id(cb); });
}

std::future<reply>
client::client_list() {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return client_list(cb); });
Expand All @@ -3264,6 +3330,11 @@ namespace cpp_redis {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return client_setname(name, cb); });
}

std::future<reply>
client::client_unblock(int id, bool witherror) {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return client_unblock(id, witherror, cb); });
}

std::future<reply>
client::cluster_addslots(const std::vector<std::string> &p_slots) {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return cluster_addslots(p_slots, cb); });
Expand Down Expand Up @@ -4406,6 +4477,15 @@ namespace cpp_redis {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return zlexcount(key, min, max, cb); });
}

std::future<reply>
client::zpopmin(const std::string& key, int count) {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return zpopmin(key, count, cb); });
}
std::future<reply>
client::zpopmax(const std::string& key, int count) {
return exec_cmd([=](const reply_callback_t& cb) -> client& { return zpopmax(key, count, cb); });
}

std::future<reply>
client::zrange(const std::string &key, int start, int stop, bool withscores) {
return exec_cmd([=](const reply_callback_t &cb) -> client & { return zrange(key, start, stop, withscores, cb); });
Expand Down