From 684e1e445e2cdb713fb03cdd9d6983272c18b70f Mon Sep 17 00:00:00 2001 From: zhengshuxin Date: Sat, 9 Jan 2021 10:48:53 +0800 Subject: [PATCH] test redis_pipeline --- .../redis/redis_pipeline/redis_pipeline.cpp | 23 ++++++++----------- .../redis/redis_pipeline2/redis_pipeline.cpp | 18 ++++++--------- .../src/redis/redis_client_pipeline.cpp | 2 +- lib_fiber/samples/redis_pipeline/valgrind.sh | 0 4 files changed, 18 insertions(+), 25 deletions(-) mode change 100644 => 100755 lib_fiber/samples/redis_pipeline/valgrind.sh diff --git a/lib_acl_cpp/samples/redis/redis_pipeline/redis_pipeline.cpp b/lib_acl_cpp/samples/redis/redis_pipeline/redis_pipeline.cpp index f82cb1e54..32561cf00 100644 --- a/lib_acl_cpp/samples/redis/redis_pipeline/redis_pipeline.cpp +++ b/lib_acl_cpp/samples/redis/redis_pipeline/redis_pipeline.cpp @@ -225,23 +225,21 @@ static void usage(const char* procname) printf("usage: %s -h[help]\r\n" "-s one_redis_addr[127.0.0.1:6379]\r\n" "-n count[default: 10]\r\n" - "-C connect_timeout[default: 10]\r\n" - "-I rw_timeout[default: 10]\r\n" - "-c max_threads[default: 10]\r\n" + "-t max_threads[default: 10]\r\n" "-w wait_for_cluster_resume[default: 500 ms]\r\n" "-r retry_for_cluster_resnum[default: 10]\r\n" - "-P password [set the password of redis cluster]\r\n" + "-p password [set the password of redis cluster]\r\n" "-a cmd[set|get|expire|ttl|exists|type|del]\r\n", procname); } int main(int argc, char* argv[]) { - int ch, n = 1, conn_timeout = 10, rw_timeout = 10; + int ch, n = 1; int max_threads = 10; - acl::string addr("127.0.0.1:6379"), cmd, passwd; + acl::string addr("127.0.0.1:6379"), cmd("del"), passwd; - while ((ch = getopt(argc, argv, "hs:n:C:I:c:a:p:")) > 0) { + while ((ch = getopt(argc, argv, "hs:n:c:a:p:")) > 0) { switch (ch) { case 'h': usage(argv[0]); @@ -252,12 +250,6 @@ int main(int argc, char* argv[]) case 'n': n = atoi(optarg); break; - case 'C': - conn_timeout = atoi(optarg); - break; - case 'I': - rw_timeout = atoi(optarg); - break; case 'c': max_threads = atoi(optarg); break; @@ -276,6 +268,9 @@ int main(int argc, char* argv[]) acl::log::stdout_open(true); acl::redis_client_pipeline pipeline(addr); + if (!passwd.empty()) { + pipeline.set_password(passwd); + } pipeline.start_thread(); struct timeval begin; @@ -320,6 +315,8 @@ int main(int argc, char* argv[]) printf("total %s: %lld, spent: %0.2f ms, speed: %0.2f\r\n", cmd.c_str(), total, inter, (total * 1000) /(inter > 0 ? inter : 1)); + pipeline.stop_thread(); + #ifdef WIN32 printf("enter any key to exit\r\n"); getchar(); diff --git a/lib_acl_cpp/samples/redis/redis_pipeline2/redis_pipeline.cpp b/lib_acl_cpp/samples/redis/redis_pipeline2/redis_pipeline.cpp index 2f49c997e..9e2e650c7 100644 --- a/lib_acl_cpp/samples/redis/redis_pipeline2/redis_pipeline.cpp +++ b/lib_acl_cpp/samples/redis/redis_pipeline2/redis_pipeline.cpp @@ -105,22 +105,20 @@ static void usage(const char* procname) { printf("usage: %s -h[help]\r\n" "-s one_redis_addr[127.0.0.1:6379]\r\n" "-n count[default: 10]\r\n" - "-C connect_timeout[default: 10]\r\n" - "-I rw_timeout[default: 10]\r\n" "-c max_threads[default: 10]\r\n" "-w wait_for_cluster_resume[default: 500 ms]\r\n" "-r retry_for_cluster_resnum[default: 10]\r\n" - "-P password [set the password of redis cluster]\r\n" + "-p password [set the password of redis cluster]\r\n" "-a cmd[set|get|expire|ttl|exists|type|del]\r\n", procname); } int main(int argc, char* argv[]) { - int ch, n = 1, conn_timeout = 10, rw_timeout = 10; + int ch, n = 1; int max_threads = 10; acl::string addr("127.0.0.1:6379"), cmd("del"), passwd; - while ((ch = getopt(argc, argv, "hs:n:C:I:c:a:p:")) > 0) { + while ((ch = getopt(argc, argv, "hs:n:c:a:p:")) > 0) { switch (ch) { case 'h': usage(argv[0]); @@ -131,12 +129,6 @@ int main(int argc, char* argv[]) { case 'n': n = atoi(optarg); break; - case 'C': - conn_timeout = atoi(optarg); - break; - case 'I': - rw_timeout = atoi(optarg); - break; case 'c': max_threads = atoi(optarg); break; @@ -155,6 +147,9 @@ int main(int argc, char* argv[]) { acl::log::stdout_open(true); acl::redis_client_pipeline pipeline(addr); + if (!passwd.empty()) { + pipeline.set_password(passwd); + } pipeline.start_thread(); struct timeval begin; @@ -199,6 +194,7 @@ int main(int argc, char* argv[]) { printf("total %s: %lld, spent: %0.2f ms, speed: %0.2f\r\n", cmd.c_str(), total, inter, (total * 1000) /(inter > 0 ? inter : 1)); + pipeline.stop_thread(); #ifdef WIN32 printf("enter any key to exit\r\n"); getchar(); diff --git a/lib_acl_cpp/src/redis/redis_client_pipeline.cpp b/lib_acl_cpp/src/redis/redis_client_pipeline.cpp index 96f3efe8d..db589476b 100644 --- a/lib_acl_cpp/src/redis/redis_client_pipeline.cpp +++ b/lib_acl_cpp/src/redis/redis_client_pipeline.cpp @@ -170,7 +170,7 @@ bool redis_pipeline_channel::wait_one(socket_stream& conn, // transfer to pipeline processs again pipeline_.push(&msg); } else { - logger_error("unknown error"); + logger_error("unknown error: %s", ptr); msg.push(result); } return true; diff --git a/lib_fiber/samples/redis_pipeline/valgrind.sh b/lib_fiber/samples/redis_pipeline/valgrind.sh old mode 100644 new mode 100755