Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

add zadd command #93

Merged
merged 3 commits into from
Jul 25, 2017
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
8 changes: 8 additions & 0 deletions examples/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ main(void) {
// do_something_with_string(reply.as_string())
});

client.zadd("zhello", {}, {{"1", "a"},
{"2", "b"},
{"3", "c"},
{"4", "d"}},
[](cpp_redis::reply& reply) {
std::cout << "zadd zhello 1 a 2 b 3 c 4 d: " << reply << std::endl;
});

// commands are pipelined and only sent when client.commit() is called
// client.commit();

Expand Down
2 changes: 1 addition & 1 deletion includes/cpp_redis/network/tcp_client_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#pragma once

#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include <cstdint>

namespace cpp_redis {

Expand Down
3 changes: 2 additions & 1 deletion includes/cpp_redis/redis_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <atomic>
#include <condition_variable>
#include <functional>
#include <map>
#include <mutex>
#include <queue>
#include <string>
Expand Down Expand Up @@ -261,7 +262,7 @@ class redis_client {
redis_client& unwatch(const reply_callback_t& reply_callback = nullptr);
redis_client& wait(int numslaves, int timeout, const reply_callback_t& reply_callback = nullptr);
redis_client& watch(const std::vector<std::string>& keys, const reply_callback_t& reply_callback = nullptr);
// redis_client& zadd(const reply_callback_t& reply_callback = nullptr) key [nx|xx] [ch] [incr] score member [score member ...]
redis_client& zadd(const std::string& key, const std::vector<std::string> options, const std::map<std::string, std::string> score_members, const reply_callback_t& reply_callback = nullptr);
redis_client& zcard(const std::string& key, const reply_callback_t& reply_callback = nullptr);
redis_client& zcount(const std::string& key, int min, int max, const reply_callback_t& reply_callback = nullptr);
redis_client& zcount(const std::string& key, double min, double max, const reply_callback_t& reply_callback = nullptr);
Expand Down
17 changes: 17 additions & 0 deletions sources/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,23 @@ redis_client::watch(const std::vector<std::string>& keys, const reply_callback_t
return *this;
}

redis_client&
redis_client::zadd(const std::string& key, const std::vector<std::string> options, const std::map<std::string, std::string> score_members, const reply_callback_t& reply_callback) {
std::vector<std::string> cmd = {"ZADD", key};

//! options
cmd.insert(cmd.end(), options.begin(), options.end());

//! score members
for (auto& sm : score_members) {
cmd.push_back(sm.first);
cmd.push_back(sm.second);
}

send(cmd, reply_callback);
return *this;
}

redis_client&
redis_client::zcard(const std::string& key, const reply_callback_t& reply_callback) {
send({"ZCARD", key}, reply_callback);
Expand Down