redis-benchmark - add the support for binary strings (#9414)

Recently, the option of sending an argument from stdin using `-x` flag
was added to redis-benchmark (this option is available in redis-cli as well).
However, using the `-x` option for sending a blobs that contains null-characters
doesn't work as expected - the argument is trimmed in the first occurrence of
`\X00` (unlike in redis-cli).  
This PR aims to fix this issue and add the support for every binary string input,
by sending arguments length to `redisFormatCommandArgv` when processing
redis-benchmark command, so we won't treat the arguments as C-strings.

Additionally, we add a simple test coverage for `-x` (without binary strings, and
also remove an excessive server started in tests, and make sure to select db 0
so that `r` and the benchmark work on the same db.

Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
alonre24 2023-09-02 15:37:04 +03:00 committed by GitHub
parent 4ba144a4eb
commit 044e29dd34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -1888,8 +1888,12 @@ int main(int argc, char **argv) {
sds_args[argc] = readArgFromStdin();
argc++;
}
/* Setup argument length */
size_t *argvlen = zmalloc(argc*sizeof(size_t));
for (i = 0; i < argc; i++)
argvlen[i] = sdslen(sds_args[i]);
do {
len = redisFormatCommandArgv(&cmd,argc,(const char**)sds_args,NULL);
len = redisFormatCommandArgv(&cmd,argc,(const char**)sds_args,argvlen);
// adjust the datasize to the parsed command
config.datasize = len;
benchmark(title,cmd,len);
@ -1899,6 +1903,7 @@ int main(int argc, char **argv) {
sdsfree(title);
if (config.redis_config != NULL) freeRedisConfig(config.redis_config);
zfree(argvlen);
return 0;
}

View File

@ -1,5 +1,5 @@
source tests/support/benchmark.tcl
source tests/support/cli.tcl
proc cmdstat {cmd} {
return [cmdrstat $cmd r]
@ -25,10 +25,11 @@ proc default_set_get_checks {} {
assert_match {} [cmdstat lrange]
}
start_server {tags {"benchmark network external:skip logreqres:skip"}} {
tags {"benchmark network external:skip logreqres:skip"} {
start_server {} {
set master_host [srv 0 host]
set master_port [srv 0 port]
r select 0
test {benchmark: set,get} {
set cmd [redisbenchmark $master_host $master_port "-c 5 -n 10 -t set,get"]
@ -126,6 +127,13 @@ start_server {tags {"benchmark network external:skip logreqres:skip"}} {
r config set maxclients $original_maxclients
}
test {benchmark: read last argument from stdin} {
set base_cmd [redisbenchmark $master_host $master_port "-x -n 10 set key"]
set cmd "printf arg | $base_cmd"
common_bench_setup $cmd
r get key
} {arg}
# tls specific tests
if {$::tls} {
test {benchmark: specific tls-ciphers} {