Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
redis-benchmark: add auth option
Browse files Browse the repository at this point in the history
Closes redis#1097
  • Loading branch information
charsyam authored and mattsta committed Aug 6, 2014
1 parent 080b043 commit eec73e7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/redis-benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static struct config {
int dbnum;
sds dbnumstr;
char *tests;
char *auth;
} config;

typedef struct _client {
Expand Down Expand Up @@ -325,6 +326,13 @@ static client createClient(char *cmd, size_t len, client from) {
* the example client buffer. */
c->obuf = sdsempty();

if (config.auth) {
char *buf = NULL;
int len = redisFormatCommand(&buf, "AUTH %s", config.auth);
c->obuf = sdscatlen(c->obuf, buf, len);
free(buf);
}

/* If a DB number different than zero is selected, prefix our request
* buffer with the SELECT command, that will be discarded the first
* time the replies are received, so if the client is reused the
Expand All @@ -346,6 +354,7 @@ static client createClient(char *cmd, size_t len, client from) {
for (j = 0; j < config.pipeline; j++)
c->obuf = sdscatlen(c->obuf,cmd,len);
}

c->written = 0;
c->pending = config.pipeline;
c->randptr = NULL;
Expand Down Expand Up @@ -489,6 +498,9 @@ int parseOptions(int argc, const char **argv) {
} else if (!strcmp(argv[i],"-s")) {
if (lastarg) goto invalid;
config.hostsocket = strdup(argv[++i]);
} else if (!strcmp(argv[i],"-a") ) {
if (lastarg) goto invalid;
config.auth = strdup(argv[++i]);
} else if (!strcmp(argv[i],"-d")) {
if (lastarg) goto invalid;
config.datasize = atoi(argv[++i]);
Expand Down Expand Up @@ -550,6 +562,7 @@ int parseOptions(int argc, const char **argv) {
" -h <hostname> Server hostname (default 127.0.0.1)\n"
" -p <port> Server port (default 6379)\n"
" -s <socket> Server socket (overrides host and port)\n"
" -a <password> Password for Redis Auth\n"
" -c <clients> Number of parallel connections (default 50)\n"
" -n <requests> Total number of requests (default 10000)\n"
" -d <size> Data size of SET/GET value in bytes (default 2)\n"
Expand Down Expand Up @@ -651,6 +664,7 @@ int main(int argc, const char **argv) {
config.hostsocket = NULL;
config.tests = NULL;
config.dbnum = 0;
config.auth = NULL;

i = parseOptions(argc,argv);
argc -= i;
Expand Down

0 comments on commit eec73e7

Please sign in to comment.