summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2014-12-11 14:58:37 +0100
committerSalvatore Sanfilippo <antirez@gmail.com>2014-12-11 14:58:37 +0100
commit4ff365b34a756e221abf0474ccfc941663e3a073 (patch)
tree477f5e04470ae34c41b3a391a9552ad71c020a7b
parent8b81383401842ea30f6df9be695cc786300f15cd (diff)
parent7fcfbea0f53744f81f46d209dee0f5f70803f773 (diff)
downloadredis-4ff365b34a756e221abf0474ccfc941663e3a073.tar.gz
Merge pull request #2114 from h0x91b/redis-cli-fix-cluster
Reconnect redis-cli when cluster return "moved"
-rw-r--r--src/redis-cli.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 67730bb3e..dd6268faf 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -904,6 +904,33 @@ static char **convertToSds(int count, char** args) {
return sds;
}
+static int issueCommandRepeat(int argc, char **argv, long repeat) {
+ while (1) {
+ config.cluster_reissue_command = 0;
+ if (cliSendCommand(argc,argv,repeat) != REDIS_OK) {
+ cliConnect(1);
+
+ /* If we still cannot send the command print error.
+ * We'll try to reconnect the next time. */
+ if (cliSendCommand(argc,argv,repeat) != REDIS_OK) {
+ cliPrintContextError();
+ return REDIS_ERR;
+ }
+ }
+ /* Issue the command again if we got redirected in cluster mode */
+ if (config.cluster_mode && config.cluster_reissue_command) {
+ cliConnect(1);
+ } else {
+ break;
+ }
+ }
+ return REDIS_OK;
+}
+
+static int issueCommand(int argc, char **argv) {
+ return issueCommandRepeat(argc, argv, config.repeat);
+}
+
static void repl(void) {
sds historyfile = NULL;
int history = 0;
@@ -959,26 +986,8 @@ static void repl(void) {
repeat = 1;
}
- while (1) {
- config.cluster_reissue_command = 0;
- if (cliSendCommand(argc-skipargs,argv+skipargs,repeat)
- != REDIS_OK)
- {
- cliConnect(1);
-
- /* If we still cannot send the command print error.
- * We'll try to reconnect the next time. */
- if (cliSendCommand(argc-skipargs,argv+skipargs,repeat)
- != REDIS_OK)
- cliPrintContextError();
- }
- /* Issue the command again if we got redirected in cluster mode */
- if (config.cluster_mode && config.cluster_reissue_command) {
- cliConnect(1);
- } else {
- break;
- }
- }
+ issueCommandRepeat(argc-skipargs, argv+skipargs, repeat);
+
elapsed = mstime()-start_time;
if (elapsed >= 500) {
printf("(%.2fs)\n",(double)elapsed/1000);
@@ -999,10 +1008,9 @@ static int noninteractive(int argc, char **argv) {
if (config.stdinarg) {
argv = zrealloc(argv, (argc+1)*sizeof(char*));
argv[argc] = readArgFromStdin();
- retval = cliSendCommand(argc+1, argv, config.repeat);
+ retval = issueCommand(argc+1, argv);
} else {
- /* stdin is probably a tty, can be tested with S_ISCHR(s.st_mode) */
- retval = cliSendCommand(argc, argv, config.repeat);
+ retval = issueCommand(argc, argv);
}
return retval;
}
@@ -1046,7 +1054,7 @@ static int evalMode(int argc, char **argv) {
argv2[2] = sdscatprintf(sdsempty(),"%d",keys);
/* Call it */
- return cliSendCommand(argc+3-got_comma, argv2, config.repeat);
+ return issueCommand(argc+3-got_comma, argv2);
}
/*------------------------------------------------------------------------------