Merge pull request #5743 from AngusP/forever-repeat-cli

Redis CLI: Fix broken interval and repeat behaviour (incluing in cluster mode)
This commit is contained in:
Salvatore Sanfilippo 2019-01-22 17:29:37 +01:00 committed by GitHub
commit 94460440b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1175,7 +1175,9 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
for (j = 0; j < argc; j++) for (j = 0; j < argc; j++)
argvlen[j] = sdslen(argv[j]); argvlen[j] = sdslen(argv[j]);
while(repeat-- > 0) { /* Negative repeat is allowed and causes infinite loop,
works well with the interval option. */
while(repeat < 0 || repeat-- > 0) {
redisAppendCommandArgv(context,argc,(const char**)argv,argvlen); redisAppendCommandArgv(context,argc,(const char**)argv,argvlen);
while (config.monitor_mode) { while (config.monitor_mode) {
if (cliReadReply(output_raw) != REDIS_OK) exit(1); if (cliReadReply(output_raw) != REDIS_OK) exit(1);
@ -1210,6 +1212,11 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
cliSelect(); cliSelect();
} }
} }
if (config.cluster_reissue_command){
/* If we need to reissue the command, break to prevent a
further 'repeat' number of dud interations */
break;
}
if (config.interval) usleep(config.interval); if (config.interval) usleep(config.interval);
fflush(stdout); /* Make it grep friendly */ fflush(stdout); /* Make it grep friendly */
} }
@ -1603,12 +1610,12 @@ static int issueCommandRepeat(int argc, char **argv, long repeat) {
cliPrintContextError(); cliPrintContextError();
return REDIS_ERR; return REDIS_ERR;
} }
} }
/* Issue the command again if we got redirected in cluster mode */ /* Issue the command again if we got redirected in cluster mode */
if (config.cluster_mode && config.cluster_reissue_command) { if (config.cluster_mode && config.cluster_reissue_command) {
cliConnect(CC_FORCE); cliConnect(CC_FORCE);
} else { } else {
break; break;
} }
} }
return REDIS_OK; return REDIS_OK;