@@ -78,6 +78,18 @@ void benchmark_log(int level, const char *fmt, ...)
78
78
va_end (args);
79
79
}
80
80
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
+ }
81
93
82
94
static void config_print (FILE *file, struct benchmark_config *cfg)
83
95
{
@@ -135,7 +147,7 @@ static void config_print(FILE *file, struct benchmark_config *cfg)
135
147
cfg->server ,
136
148
cfg->port ,
137
149
cfg->unix_socket ,
138
- cfg->protocol ,
150
+ get_protocol_name ( cfg->protocol ) ,
139
151
#ifdef USE_TLS
140
152
cfg->tls ? " yes" : " no" ,
141
153
cfg->tls_cert ,
@@ -191,7 +203,7 @@ static void config_print_to_json(json_handler * jsonhandler, struct benchmark_co
191
203
jsonhandler->write_obj (" server" ," \" %s\" " , cfg->server );
192
204
jsonhandler->write_obj (" port" ," %u" , cfg->port );
193
205
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 ) );
195
207
jsonhandler->write_obj (" out_file" ," \" %s\" " , cfg->out_file );
196
208
#ifdef USE_TLS
197
209
jsonhandler->write_obj (" tls" ," \" %s\" " , cfg->tls ? " true" : " false" );
@@ -245,8 +257,6 @@ static void config_init_defaults(struct benchmark_config *cfg)
245
257
cfg->server = " localhost" ;
246
258
if (!cfg->port && !cfg->unix_socket )
247
259
cfg->port = 6379 ;
248
- if (!cfg->protocol )
249
- cfg->protocol = " redis" ;
250
260
if (!cfg->run_count )
251
261
cfg->run_count = 1 ;
252
262
if (!cfg->clients )
@@ -307,7 +317,7 @@ static bool verify_cluster_option(struct benchmark_config *cfg) {
307
317
} else if (cfg->wait_ratio .is_defined ()) {
308
318
fprintf (stderr, " error: cluster mode dose not support wait-ratio option.\n " );
309
319
return false ;
310
- } else if (cfg-> protocol && strcmp (cfg->protocol , " redis " )) {
320
+ } else if (! is_redis_protocol (cfg->protocol )) {
311
321
fprintf (stderr, " error: cluster mode supported only in redis protocol.\n " );
312
322
return false ;
313
323
} else if (cfg->unix_socket ) {
@@ -492,13 +502,20 @@ static int config_parse_args(int argc, char *argv[], struct benchmark_config *cf
492
502
}
493
503
break ;
494
504
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 ;
500
518
}
501
- cfg->protocol = optarg;
502
519
break ;
503
520
case ' o' :
504
521
cfg->out_file = optarg;
@@ -857,9 +874,9 @@ void usage() {
857
874
" -s, --server=ADDR Server address (default: localhost)\n "
858
875
" -p, --port=PORT Server port (default: 6379)\n "
859
876
" -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 "
863
880
" -a, --authenticate=CREDENTIALS Authenticate using specified credentials.\n "
864
881
" A simple password is used for memcache_text\n "
865
882
" and Redis <= 5.x. <USER>:<PASSWORD> can be\n "
@@ -1410,12 +1427,11 @@ int main(int argc, char *argv[])
1410
1427
}
1411
1428
1412
1429
if (cfg.authenticate ) {
1413
- if (strcmp (cfg.protocol , " redis" ) != 0 &&
1414
- strcmp (cfg.protocol , " memcache_binary" ) != 0 ) {
1430
+ if (cfg.protocol == PROTOCOL_MEMCACHE_TEXT) {
1415
1431
fprintf (stderr, " error: authenticate can only be used with redis or memcache_binary.\n " );
1416
1432
usage ();
1417
1433
}
1418
- if (strcmp ( cfg.protocol , " memcache_binary " ) == 0 &&
1434
+ if (cfg.protocol == PROTOCOL_MEMCACHE_BINARY &&
1419
1435
strchr (cfg.authenticate , ' :' ) == NULL ) {
1420
1436
fprintf (stderr, " error: binary_memcache credentials must be in the form of USER:PASSWORD.\n " );
1421
1437
usage ();
@@ -1425,7 +1441,7 @@ int main(int argc, char *argv[])
1425
1441
obj_gen->set_random_data (cfg.random_data );
1426
1442
}
1427
1443
1428
- if (cfg.select_db > 0 && strcmp (cfg.protocol , " redis " )) {
1444
+ if (cfg.select_db > 0 && ! is_redis_protocol (cfg.protocol )) {
1429
1445
fprintf (stderr, " error: select-db can only be used with redis protocol.\n " );
1430
1446
usage ();
1431
1447
}
@@ -1434,7 +1450,7 @@ int main(int argc, char *argv[])
1434
1450
fprintf (stderr, " error: data-offset too long\n " );
1435
1451
usage ();
1436
1452
}
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 )) {
1438
1454
fprintf (stderr, " error: data-offset can only be used with redis protocol, and cannot be used with expiry\n " );
1439
1455
usage ();
1440
1456
}
0 commit comments