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
efcf948c
Commit
efcf948c
authored
Nov 29, 2010
by
antirez
Browse files
new redis-cli command connect
parent
5b761a33
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
efcf948c
...
@@ -273,6 +273,11 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -273,6 +273,11 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
size_t
*
argvlen
;
size_t
*
argvlen
;
int
j
;
int
j
;
if
(
context
==
NULL
)
{
printf
(
"Not connected, please use: connect <host> <port>
\n
"
);
return
REDIS_OK
;
}
config
.
raw_output
=
!
strcasecmp
(
command
,
"info"
);
config
.
raw_output
=
!
strcasecmp
(
command
,
"info"
);
if
(
!
strcasecmp
(
command
,
"help"
))
{
if
(
!
strcasecmp
(
command
,
"help"
))
{
showInteractiveHelp
();
showInteractiveHelp
();
...
@@ -319,7 +324,8 @@ static int parseOptions(int argc, char **argv) {
...
@@ -319,7 +324,8 @@ static int parseOptions(int argc, char **argv) {
int
lastarg
=
i
==
argc
-
1
;
int
lastarg
=
i
==
argc
-
1
;
if
(
!
strcmp
(
argv
[
i
],
"-h"
)
&&
!
lastarg
)
{
if
(
!
strcmp
(
argv
[
i
],
"-h"
)
&&
!
lastarg
)
{
config
.
hostip
=
argv
[
i
+
1
];
sdsfree
(
config
.
hostip
);
config
.
hostip
=
sdsnew
(
argv
[
i
+
1
]);
i
++
;
i
++
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-h"
)
&&
lastarg
)
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-h"
)
&&
lastarg
)
{
usage
();
usage
();
...
@@ -419,14 +425,16 @@ static void repl() {
...
@@ -419,14 +425,16 @@ static void repl() {
strcasecmp
(
argv
[
0
],
"exit"
)
==
0
)
strcasecmp
(
argv
[
0
],
"exit"
)
==
0
)
{
{
exit
(
0
);
exit
(
0
);
}
else
if
(
argc
==
3
&&
!
strcasecmp
(
argv
[
0
],
"connect"
))
{
sdsfree
(
config
.
hostip
);
config
.
hostip
=
sdsnew
(
argv
[
1
]);
config
.
hostport
=
atoi
(
argv
[
2
]);
cliConnect
(
1
);
}
else
{
}
else
{
long
long
start_time
=
mstime
(),
elapsed
;
long
long
start_time
=
mstime
(),
elapsed
;
if
(
cliSendCommand
(
argc
,
argv
,
1
)
!=
REDIS_OK
)
{
if
(
cliSendCommand
(
argc
,
argv
,
1
)
!=
REDIS_OK
)
{
printf
(
"Reconnecting... "
);
cliConnect
(
1
);
fflush
(
stdout
);
if
(
cliConnect
(
1
)
!=
REDIS_OK
)
exit
(
1
);
printf
(
"OK
\n
"
);
/* If we still cannot send the command,
/* If we still cannot send the command,
* print error and abort. */
* print error and abort. */
...
@@ -466,7 +474,7 @@ static int noninteractive(int argc, char **argv) {
...
@@ -466,7 +474,7 @@ static int noninteractive(int argc, char **argv) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
int
firstarg
;
int
firstarg
;
config
.
hostip
=
"127.0.0.1"
;
config
.
hostip
=
sdsnew
(
"127.0.0.1"
)
;
config
.
hostport
=
6379
;
config
.
hostport
=
6379
;
config
.
hostsocket
=
NULL
;
config
.
hostsocket
=
NULL
;
config
.
repeat
=
1
;
config
.
repeat
=
1
;
...
...
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