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
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;
}