@@ -78,6 +78,18 @@ void benchmark_log(int level, const char *fmt, ...)
7878 va_end (args);
7979}
8080
81+ bool is_redis_protocol (enum PROTOCOL_TYPE type) {
82+ return (type == PROTOCOL_REDIS_DEFAULT || type == PROTOCOL_RESP2 || type == PROTOCOL_RESP3);
83+ }
84+
85+ static const char * get_protocol_name (enum PROTOCOL_TYPE type) {
86+ if (type == PROTOCOL_REDIS_DEFAULT) return " redis" ;
87+ else if (type == PROTOCOL_RESP2) return " resp2" ;
88+ else if (type == PROTOCOL_RESP3) return " resp3" ;
89+ else if (type == PROTOCOL_MEMCACHE_TEXT) return " memcache_text" ;
90+ else if (type == PROTOCOL_MEMCACHE_BINARY) return " memcache_binary" ;
91+ else return " none" ;
92+ }
8193
8294static void config_print (FILE *file, struct benchmark_config *cfg)
8395{
@@ -135,7 +147,7 @@ static void config_print(FILE *file, struct benchmark_config *cfg)
135147 cfg->server ,
136148 cfg->port ,
137149 cfg->unix_socket ,
138- cfg->protocol ,
150+ get_protocol_name ( cfg->protocol ) ,
139151#ifdef USE_TLS
140152 cfg->tls ? " yes" : " no" ,
141153 cfg->tls_cert ,
@@ -191,7 +203,7 @@ static void config_print_to_json(json_handler * jsonhandler, struct benchmark_co
191203 jsonhandler->write_obj (" server" ," \" %s\" " , cfg->server );
192204 jsonhandler->write_obj (" port" ," %u" , cfg->port );
193205 jsonhandler->write_obj (" unix socket" ," \" %s\" " , cfg->unix_socket );
194- jsonhandler->write_obj (" protocol" ," \" %s\" " , cfg->protocol );
206+ jsonhandler->write_obj (" protocol" ," \" %s\" " , get_protocol_name ( cfg->protocol ) );
195207 jsonhandler->write_obj (" out_file" ," \" %s\" " , cfg->out_file );
196208#ifdef USE_TLS
197209 jsonhandler->write_obj (" tls" ," \" %s\" " , cfg->tls ? " true" : " false" );
@@ -245,8 +257,6 @@ static void config_init_defaults(struct benchmark_config *cfg)
245257 cfg->server = " localhost" ;
246258 if (!cfg->port && !cfg->unix_socket )
247259 cfg->port = 6379 ;
248- if (!cfg->protocol )
249- cfg->protocol = " redis" ;
250260 if (!cfg->run_count )
251261 cfg->run_count = 1 ;
252262 if (!cfg->clients )
@@ -307,7 +317,7 @@ static bool verify_cluster_option(struct benchmark_config *cfg) {
307317 } else if (cfg->wait_ratio .is_defined ()) {
308318 fprintf (stderr, " error: cluster mode dose not support wait-ratio option.\n " );
309319 return false ;
310- } else if (cfg-> protocol && strcmp (cfg->protocol , " redis " )) {
320+ } else if (! is_redis_protocol (cfg->protocol )) {
311321 fprintf (stderr, " error: cluster mode supported only in redis protocol.\n " );
312322 return false ;
313323 } else if (cfg->unix_socket ) {
@@ -492,13 +502,20 @@ static int config_parse_args(int argc, char *argv[], struct benchmark_config *cf
492502 }
493503 break ;
494504 case ' P' :
495- if (strcmp (optarg, " memcache_text" ) &&
496- strcmp (optarg, " memcache_binary" ) &&
497- strcmp (optarg, " redis" )) {
498- fprintf (stderr, " error: supported protocols are 'memcache_text', 'memcache_binary' and 'redis'.\n " );
499- return -1 ;
505+ if (strcmp (optarg, " redis" ) == 0 ) {
506+ cfg->protocol = PROTOCOL_REDIS_DEFAULT;
507+ } else if (strcmp (optarg, " resp2" ) == 0 ) {
508+ cfg->protocol = PROTOCOL_RESP2;
509+ } else if (strcmp (optarg, " resp3" ) == 0 ) {
510+ cfg->protocol = PROTOCOL_RESP3;
511+ } else if (strcmp (optarg, " memcache_text" ) == 0 ) {
512+ cfg->protocol = PROTOCOL_MEMCACHE_TEXT;
513+ } else if (strcmp (optarg, " memcache_binary" ) == 0 ) {
514+ cfg->protocol = PROTOCOL_MEMCACHE_BINARY;
515+ } else {
516+ fprintf (stderr, " error: supported protocols are 'memcache_text', 'memcache_binary', 'redis', 'resp2' and resp3'.\n " );
517+ return -1 ;
500518 }
501- cfg->protocol = optarg;
502519 break ;
503520 case ' o' :
504521 cfg->out_file = optarg;
@@ -857,9 +874,9 @@ void usage() {
857874 " -s, --server=ADDR Server address (default: localhost)\n "
858875 " -p, --port=PORT Server port (default: 6379)\n "
859876 " -S, --unix-socket=SOCKET UNIX Domain socket name (default: none)\n "
860- " -P, --protocol=PROTOCOL Protocol to use (default: redis). Other \n "
861- " supported protocols are memcache_text, \n "
862- " memcache_binary .\n "
877+ " -P, --protocol=PROTOCOL Protocol to use (default: redis).\n "
878+ " other supported protocols are resp2, resp3, memcache_text and memcache_binary. \n "
879+ " when using one of resp2 or resp3 the redis protocol version will be set via HELLO command .\n "
863880 " -a, --authenticate=CREDENTIALS Authenticate using specified credentials.\n "
864881 " A simple password is used for memcache_text\n "
865882 " and Redis <= 5.x. <USER>:<PASSWORD> can be\n "
@@ -1410,12 +1427,11 @@ int main(int argc, char *argv[])
14101427 }
14111428
14121429 if (cfg.authenticate ) {
1413- if (strcmp (cfg.protocol , " redis" ) != 0 &&
1414- strcmp (cfg.protocol , " memcache_binary" ) != 0 ) {
1430+ if (cfg.protocol == PROTOCOL_MEMCACHE_TEXT) {
14151431 fprintf (stderr, " error: authenticate can only be used with redis or memcache_binary.\n " );
14161432 usage ();
14171433 }
1418- if (strcmp ( cfg.protocol , " memcache_binary " ) == 0 &&
1434+ if (cfg.protocol == PROTOCOL_MEMCACHE_BINARY &&
14191435 strchr (cfg.authenticate , ' :' ) == NULL ) {
14201436 fprintf (stderr, " error: binary_memcache credentials must be in the form of USER:PASSWORD.\n " );
14211437 usage ();
@@ -1425,7 +1441,7 @@ int main(int argc, char *argv[])
14251441 obj_gen->set_random_data (cfg.random_data );
14261442 }
14271443
1428- if (cfg.select_db > 0 && strcmp (cfg.protocol , " redis " )) {
1444+ if (cfg.select_db > 0 && ! is_redis_protocol (cfg.protocol )) {
14291445 fprintf (stderr, " error: select-db can only be used with redis protocol.\n " );
14301446 usage ();
14311447 }
@@ -1434,7 +1450,7 @@ int main(int argc, char *argv[])
14341450 fprintf (stderr, " error: data-offset too long\n " );
14351451 usage ();
14361452 }
1437- if (cfg.expiry_range .min || cfg.expiry_range .max || strcmp (cfg.protocol , " redis " )) {
1453+ if (cfg.expiry_range .min || cfg.expiry_range .max || ! is_redis_protocol (cfg.protocol )) {
14381454 fprintf (stderr, " error: data-offset can only be used with redis protocol, and cannot be used with expiry\n " );
14391455 usage ();
14401456 }
0 commit comments