Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding auth to redis-benchmark #1097

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/redis-benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static struct config {
int loop;
int idlemode;
char *tests;
char *auth;
} config;

typedef struct _client {
Expand Down Expand Up @@ -271,6 +272,14 @@ static client createClient(char *cmd, size_t len) {
c->context->reader->maxbuf = 0;
/* Queue N requests accordingly to the pipeline size. */
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);
}

for (j = 0; j < config.pipeline; j++)
c->obuf = sdscatlen(c->obuf,cmd,len);
c->randlen = 0;
Expand All @@ -296,9 +305,19 @@ static client createClient(char *cmd, size_t len) {

static void createMissingClients(client c) {
int n = 0;
char *cmd = c->obuf;
int len = sdslen(c->obuf);

if (config.auth) {
char *buf = NULL;
int tmplen = redisFormatCommand(&buf, "AUTH %s", config.auth);
cmd += tmplen;
len -= tmplen;
free(buf);
}

while(config.liveclients < config.numclients) {
createClient(c->obuf,sdslen(c->obuf)/config.pipeline);
createClient(cmd,len/config.pipeline);

/* Listen backlog is quite limited on most systems */
if (++n > 64) {
Expand Down Expand Up @@ -387,6 +406,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 @@ -444,6 +466,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 @@ -535,6 +558,7 @@ int main(int argc, const char **argv) {
config.hostport = 6379;
config.hostsocket = NULL;
config.tests = NULL;
config.auth = NULL;

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