mirror of
https://github.com/redis/redis.git
synced 2026-04-21 03:01:35 -04:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user