Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
4ff365b3
Commit
4ff365b3
authored
Dec 11, 2014
by
Salvatore Sanfilippo
Browse files
Merge pull request #2114 from h0x91b/redis-cli-fix-cluster
Reconnect redis-cli when cluster return "moved"
parents
8b813834
7fcfbea0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
4ff365b3
...
@@ -904,6 +904,33 @@ static char **convertToSds(int count, char** args) {
...
@@ -904,6 +904,33 @@ static char **convertToSds(int count, char** args) {
return
sds
;
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
)
{
static
void
repl
(
void
)
{
sds
historyfile
=
NULL
;
sds
historyfile
=
NULL
;
int
history
=
0
;
int
history
=
0
;
...
@@ -959,26 +986,8 @@ static void repl(void) {
...
@@ -959,26 +986,8 @@ static void repl(void) {
repeat
=
1
;
repeat
=
1
;
}
}
while
(
1
)
{
issueCommandRepeat
(
argc
-
skipargs
,
argv
+
skipargs
,
repeat
);
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
;
}
}
elapsed
=
mstime
()
-
start_time
;
elapsed
=
mstime
()
-
start_time
;
if
(
elapsed
>=
500
)
{
if
(
elapsed
>=
500
)
{
printf
(
"(%.2fs)
\n
"
,(
double
)
elapsed
/
1000
);
printf
(
"(%.2fs)
\n
"
,(
double
)
elapsed
/
1000
);
...
@@ -999,10 +1008,9 @@ static int noninteractive(int argc, char **argv) {
...
@@ -999,10 +1008,9 @@ static int noninteractive(int argc, char **argv) {
if
(
config
.
stdinarg
)
{
if
(
config
.
stdinarg
)
{
argv
=
zrealloc
(
argv
,
(
argc
+
1
)
*
sizeof
(
char
*
));
argv
=
zrealloc
(
argv
,
(
argc
+
1
)
*
sizeof
(
char
*
));
argv
[
argc
]
=
readArgFromStdin
();
argv
[
argc
]
=
readArgFromStdin
();
retval
=
cliSend
Command
(
argc
+
1
,
argv
,
config
.
repeat
);
retval
=
issue
Command
(
argc
+
1
,
argv
);
}
else
{
}
else
{
/* stdin is probably a tty, can be tested with S_ISCHR(s.st_mode) */
retval
=
issueCommand
(
argc
,
argv
);
retval
=
cliSendCommand
(
argc
,
argv
,
config
.
repeat
);
}
}
return
retval
;
return
retval
;
}
}
...
@@ -1046,7 +1054,7 @@ static int evalMode(int argc, char **argv) {
...
@@ -1046,7 +1054,7 @@ static int evalMode(int argc, char **argv) {
argv2
[
2
]
=
sdscatprintf
(
sdsempty
(),
"%d"
,
keys
);
argv2
[
2
]
=
sdscatprintf
(
sdsempty
(),
"%d"
,
keys
);
/* Call it */
/* Call it */
return
cliSend
Command
(
argc
+
3
-
got_comma
,
argv2
,
config
.
repeat
);
return
issue
Command
(
argc
+
3
-
got_comma
,
argv2
);
}
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment