Commit 2833f2e8f1f091d5b6f55606fecf8876eaf7be7c
1 parent
bfa303d5
Implement method to return # commands processed
num_commands_processed(), trarcks using cmd_count and guarded with queue_guard.
Showing
3 changed files
with
15 additions
and
4 deletions
examples/lpush_benchmark.cpp
src/redisx.cpp
| ... | ... | @@ -36,7 +36,7 @@ void disconnected(const redisAsyncContext *c, int status) { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | Redis::Redis(const string& host, const int port) |
| 39 | - : host(host), port(port), io_ops(0), to_exit(false) { | |
| 39 | + : host(host), port(port), cmd_count(0), to_exit(false) { | |
| 40 | 40 | |
| 41 | 41 | lock_guard<mutex> lg(queue_guard); |
| 42 | 42 | connected_lock.lock(); |
| ... | ... | @@ -134,9 +134,15 @@ void Redis::process_queued_commands() { |
| 134 | 134 | else throw runtime_error("[FATAL] Command pointer not found in any queue!"); |
| 135 | 135 | |
| 136 | 136 | command_queue.pop(); |
| 137 | + cmd_count++; | |
| 137 | 138 | } |
| 138 | 139 | } |
| 139 | 140 | |
| 141 | +long Redis::num_commands_processed() { | |
| 142 | + lock_guard<mutex> lg(queue_guard); | |
| 143 | + return cmd_count; | |
| 144 | +} | |
| 145 | + | |
| 140 | 146 | // ---------------------------- |
| 141 | 147 | |
| 142 | 148 | template<> unordered_map<void*, CommandAsync<const redisReply*>*>& Redis::get_command_map() { return commands_redis_reply; } | ... | ... |
src/redisx.hpp
| ... | ... | @@ -61,6 +61,8 @@ public: |
| 61 | 61 | |
| 62 | 62 | void command(const char* command); |
| 63 | 63 | |
| 64 | + long num_commands_processed(); | |
| 65 | + | |
| 64 | 66 | // struct event* command_loop(const char* command, long interval_s, long interval_us); |
| 65 | 67 | |
| 66 | 68 | // void get(const char* key, std::function<void(const std::string&, const char*)> callback); |
| ... | ... | @@ -81,8 +83,8 @@ private: |
| 81 | 83 | std::string host; |
| 82 | 84 | int port; |
| 83 | 85 | |
| 84 | - // Number of IOs performed | |
| 85 | - long io_ops; | |
| 86 | + // Number of commands processed | |
| 87 | + long cmd_count; | |
| 86 | 88 | |
| 87 | 89 | redisAsyncContext *c; |
| 88 | 90 | |
| ... | ... | @@ -137,7 +139,7 @@ void command_callback(redisAsyncContext *c, void *r, void *privdata) { |
| 137 | 139 | } |
| 138 | 140 | |
| 139 | 141 | if(reply->type == REDIS_REPLY_NIL) { |
| 140 | - std::cerr << "[ERROR] " << cmd_obj->cmd << ": Nil reply." << std::endl; | |
| 142 | + std::cerr << "[WARNING] " << cmd_obj->cmd << ": Nil reply." << std::endl; | |
| 141 | 143 | delete cmd_obj; |
| 142 | 144 | return; // cmd_obj->invoke(NULL); |
| 143 | 145 | } | ... | ... |