From 538c2b2d8dad6a70faf99ba2494b5d561abd7ee0 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 4 May 2020 08:09:21 -0700 Subject: Add --user argument to redis-benchmark.c (ACL) --- src/redis-benchmark.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 2df41580b..77daf981c 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -94,6 +94,7 @@ static struct config { sds dbnumstr; char *tests; char *auth; + const char *user; int precision; int num_threads; struct benchmarkThread **threads; @@ -258,7 +259,10 @@ static redisConfig *getRedisConfig(const char *ip, int port, if(config.auth) { void *authReply = NULL; - redisAppendCommand(c, "AUTH %s", config.auth); + if (config.user == NULL) + redisAppendCommand(c, "AUTH %s", config.auth); + else + redisAppendCommand(c, "AUTH %s %s", config.user, config.auth); if (REDIS_OK != redisGetReply(c, &authReply)) goto fail; if (reply) freeReplyObject(reply); reply = ((redisReply *) authReply); @@ -628,7 +632,12 @@ static client createClient(char *cmd, size_t len, client from, int thread_id) { c->prefix_pending = 0; if (config.auth) { char *buf = NULL; - int len = redisFormatCommand(&buf, "AUTH %s", config.auth); + int len; + if (config.user == NULL) + len = redisFormatCommand(&buf, "AUTH %s", config.auth); + else + len = redisFormatCommand(&buf, "AUTH %s %s", + config.user, config.auth); c->obuf = sdscatlen(c->obuf, buf, len); free(buf); c->prefix_pending++; @@ -1299,6 +1308,9 @@ int parseOptions(int argc, const char **argv) { } else if (!strcmp(argv[i],"-a") ) { if (lastarg) goto invalid; config.auth = strdup(argv[++i]); + } else if (!strcmp(argv[i],"--user")) { + if (lastarg) goto invalid; + config.user = argv[++i]; } else if (!strcmp(argv[i],"-d")) { if (lastarg) goto invalid; config.datasize = atoi(argv[++i]); @@ -1385,6 +1397,7 @@ usage: " -p Server port (default 6379)\n" " -s Server socket (overrides host and port)\n" " -a Password for Redis Auth\n" +" --user Used to send ACL style 'AUTH username pass'. Needs -a.\n" " -c Number of parallel connections (default 50)\n" " -n Total number of requests (default 100000)\n" " -d Data size of SET/GET value in bytes (default 3)\n" -- cgit v1.2.1