diff --git a/src/redis-cli.c b/src/redis-cli.c index c46c707f83a4e46b1c391308f25515477df064a4..be9485756a2b3e7fc0a4e45e870f092939cd9fe5 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -673,16 +673,17 @@ static int cliSendCommand(int argc, char **argv, int repeat) { return REDIS_OK; } -/* Send the INFO command, reconnecting the link if needed. */ -static redisReply *reconnectingInfo(void) { - redisContext *c = context; +/* Send a command reconnecting the link if needed. */ +static redisReply *reconnectingRedisCommand(redisContext *c, const char *fmt, ...) { redisReply *reply = NULL; int tries = 0; + va_list ap; assert(!c->err); while(reply == NULL) { while (c->err & (REDIS_ERR_IO | REDIS_ERR_EOF)) { - printf("Reconnecting (%d)...\r", ++tries); + printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ + printf("Reconnecting... %d\r", ++tries); fflush(stdout); redisFree(c); @@ -690,12 +691,15 @@ static redisReply *reconnectingInfo(void) { usleep(1000000); } - reply = redisCommand(c,"INFO"); + va_start(ap,fmt); + reply = redisvCommand(c,fmt,ap); + va_end(ap); + if (c->err && !(c->err & (REDIS_ERR_IO | REDIS_ERR_EOF))) { fprintf(stderr, "Error: %s\n", c->errstr); exit(1); } else if (tries > 0) { - printf("\n"); + printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */ } } @@ -1047,7 +1051,7 @@ static void latencyMode(void) { if (!context) exit(1); while(1) { start = mstime(); - reply = redisCommand(context,"PING"); + reply = reconnectingRedisCommand(context,"PING"); if (reply == NULL) { fprintf(stderr,"\nI/O error\n"); exit(1); @@ -1197,7 +1201,7 @@ static void latencyDistMode(void) { if (!context) exit(1); while(1) { start = ustime(); - reply = redisCommand(context,"PING"); + reply = reconnectingRedisCommand(context,"PING"); if (reply == NULL) { fprintf(stderr,"\nI/O error\n"); exit(1); @@ -1845,7 +1849,7 @@ static void statMode(void) { char buf[64]; int j; - reply = reconnectingInfo(); + reply = reconnectingRedisCommand(context,"INFO"); if (reply->type == REDIS_REPLY_ERROR) { printf("ERROR: %s\n", reply->str); exit(1);