From 2a1247309a63dc5a0e1593a3a89b78c0e17645d2 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 12 Jul 2016 11:22:41 +0200 Subject: [PATCH] redis-benchmark: new option to show server errors on stdout. Disabled by default, can be activated with -e. Maybe the reverse was more safe but departs from the past behavior. --- src/redis-benchmark.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 2829df91..50905c87 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -65,6 +65,7 @@ static struct config { int randomkeys_keyspacelen; int keepalive; int pipeline; + int showerrors; long long start; long long totlatency; long long *latency; @@ -212,6 +213,16 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { exit(1); } + if (config.showerrors) { + static time_t lasterr_time = 0; + time_t now = time(NULL); + redisReply *r = reply; + if (r->type == REDIS_REPLY_ERROR && lasterr_time != now) { + lasterr_time = now; + printf("Error from server: %s\n", r->str); + } + } + freeReplyObject(reply); /* This is an OK for prefix commands such as auth and select.*/ if (c->prefix_pending > 0) { @@ -227,7 +238,7 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { c->randptr[j] -= c->prefixlen; c->prefixlen = 0; } - continue; + continue; } if (config.requests_finished < config.requests) @@ -518,6 +529,8 @@ int parseOptions(int argc, const char **argv) { config.loop = 1; } else if (!strcmp(argv[i],"-I")) { config.idlemode = 1; + } else if (!strcmp(argv[i],"-e")) { + config.showerrors = 1; } else if (!strcmp(argv[i],"-t")) { if (lastarg) goto invalid; /* We get the list of tests to run as a string in the form @@ -569,6 +582,8 @@ usage: " is executed. Default tests use this to hit random keys in the\n" " specified range.\n" " -P Pipeline requests. Default 1 (no pipeline).\n" +" -e If server replies with errors, show them on stdout.\n" +" (no more than 1 error per second is displayed)\n" " -q Quiet. Just show query/sec values\n" " --csv Output in CSV format\n" " -l Loop. Run the tests forever\n" @@ -649,6 +664,7 @@ int main(int argc, const char **argv) { config.keepalive = 1; config.datasize = 3; config.pipeline = 1; + config.showerrors = 0; config.randomkeys = 0; config.randomkeys_keyspacelen = 0; config.quiet = 0;