diff --git a/examples/lpush_benchmark.cpp b/examples/lpush_benchmark.cpp index 3d20af7..b1dc626 100644 --- a/examples/lpush_benchmark.cpp +++ b/examples/lpush_benchmark.cpp @@ -45,5 +45,8 @@ int main(int argc, char* argv[]) { t1 = time_ms(); rdx.block_until_stopped(); + + cout << "Commands processed: " << rdx.num_commands_processed() << endl; + return 0; }; diff --git a/src/redisx.cpp b/src/redisx.cpp index 180b34a..373eec5 100644 --- a/src/redisx.cpp +++ b/src/redisx.cpp @@ -36,7 +36,7 @@ void disconnected(const redisAsyncContext *c, int status) { } Redis::Redis(const string& host, const int port) - : host(host), port(port), io_ops(0), to_exit(false) { + : host(host), port(port), cmd_count(0), to_exit(false) { lock_guard lg(queue_guard); connected_lock.lock(); @@ -134,9 +134,15 @@ void Redis::process_queued_commands() { else throw runtime_error("[FATAL] Command pointer not found in any queue!"); command_queue.pop(); + cmd_count++; } } +long Redis::num_commands_processed() { + lock_guard lg(queue_guard); + return cmd_count; +} + // ---------------------------- template<> unordered_map*>& Redis::get_command_map() { return commands_redis_reply; } diff --git a/src/redisx.hpp b/src/redisx.hpp index 8e7af95..b9bb11d 100644 --- a/src/redisx.hpp +++ b/src/redisx.hpp @@ -61,6 +61,8 @@ public: void command(const char* command); + long num_commands_processed(); + // struct event* command_loop(const char* command, long interval_s, long interval_us); // void get(const char* key, std::function callback); @@ -81,8 +83,8 @@ private: std::string host; int port; - // Number of IOs performed - long io_ops; + // Number of commands processed + long cmd_count; redisAsyncContext *c; @@ -137,7 +139,7 @@ void command_callback(redisAsyncContext *c, void *r, void *privdata) { } if(reply->type == REDIS_REPLY_NIL) { - std::cerr << "[ERROR] " << cmd_obj->cmd << ": Nil reply." << std::endl; + std::cerr << "[WARNING] " << cmd_obj->cmd << ": Nil reply." << std::endl; delete cmd_obj; return; // cmd_obj->invoke(NULL); }