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
249c3a7d
Commit
249c3a7d
authored
Apr 27, 2010
by
antirez
Browse files
Minimal support for subscribe/psubscribe in redis-cli
parent
095e805e
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis-cli.c
View file @
249c3a7d
...
@@ -54,6 +54,8 @@ static struct config {
...
@@ -54,6 +54,8 @@ static struct config {
long
repeat
;
long
repeat
;
int
dbnum
;
int
dbnum
;
int
interactive
;
int
interactive
;
int
monitor_mode
;
int
pubsub_mode
;
char
*
auth
;
char
*
auth
;
}
config
;
}
config
;
...
@@ -165,6 +167,8 @@ static struct redisCommand cmdTable[] = {
...
@@ -165,6 +167,8 @@ static struct redisCommand cmdTable[] = {
{
"config"
,
-
2
,
REDIS_CMD_BULK
},
{
"config"
,
-
2
,
REDIS_CMD_BULK
},
{
"subscribe"
,
-
2
,
REDIS_CMD_INLINE
},
{
"subscribe"
,
-
2
,
REDIS_CMD_INLINE
},
{
"unsubscribe"
,
-
1
,
REDIS_CMD_INLINE
},
{
"unsubscribe"
,
-
1
,
REDIS_CMD_INLINE
},
{
"psubscribe"
,
-
2
,
REDIS_CMD_INLINE
},
{
"punsubscribe"
,
-
1
,
REDIS_CMD_INLINE
},
{
"publish"
,
3
,
REDIS_CMD_BULK
},
{
"publish"
,
3
,
REDIS_CMD_BULK
},
{
NULL
,
0
,
0
}
{
NULL
,
0
,
0
}
};
};
...
@@ -349,7 +353,6 @@ static int selectDb(int fd) {
...
@@ -349,7 +353,6 @@ static int selectDb(int fd) {
static
int
cliSendCommand
(
int
argc
,
char
**
argv
,
int
repeat
)
{
static
int
cliSendCommand
(
int
argc
,
char
**
argv
,
int
repeat
)
{
struct
redisCommand
*
rc
=
lookupCommand
(
argv
[
0
]);
struct
redisCommand
*
rc
=
lookupCommand
(
argv
[
0
]);
int
fd
,
j
,
retval
=
0
;
int
fd
,
j
,
retval
=
0
;
int
read_forever
=
0
;
sds
cmd
;
sds
cmd
;
if
(
!
rc
)
{
if
(
!
rc
)
{
...
@@ -362,7 +365,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -362,7 +365,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
fprintf
(
stderr
,
"Wrong number of arguments for '%s'
\n
"
,
rc
->
name
);
fprintf
(
stderr
,
"Wrong number of arguments for '%s'
\n
"
,
rc
->
name
);
return
1
;
return
1
;
}
}
if
(
!
strcasecmp
(
rc
->
name
,
"monitor"
))
read_forever
=
1
;
if
(
!
strcasecmp
(
rc
->
name
,
"monitor"
))
config
.
monitor_mode
=
1
;
if
(
!
strcasecmp
(
rc
->
name
,
"subscribe"
)
||
!
strcasecmp
(
rc
->
name
,
"psubscribe"
))
config
.
pubsub_mode
=
1
;
if
((
fd
=
cliConnect
())
==
-
1
)
return
1
;
if
((
fd
=
cliConnect
())
==
-
1
)
return
1
;
/* Select db number */
/* Select db number */
...
@@ -402,10 +407,18 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -402,10 +407,18 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
anetWrite
(
fd
,
cmd
,
sdslen
(
cmd
));
anetWrite
(
fd
,
cmd
,
sdslen
(
cmd
));
sdsfree
(
cmd
);
sdsfree
(
cmd
);
while
(
read_forever
)
{
while
(
config
.
monitor_mode
)
{
cliReadSingleLineReply
(
fd
,
0
);
cliReadSingleLineReply
(
fd
,
0
);
}
}
if
(
config
.
pubsub_mode
)
{
printf
(
"Reading messages... (press Ctrl-c to quit)
\n
"
);
while
(
1
)
{
cliReadReply
(
fd
);
printf
(
"
\n
"
);
}
}
retval
=
cliReadReply
(
fd
);
retval
=
cliReadReply
(
fd
);
if
(
retval
)
{
if
(
retval
)
{
return
retval
;
return
retval
;
...
@@ -592,6 +605,8 @@ int main(int argc, char **argv) {
...
@@ -592,6 +605,8 @@ int main(int argc, char **argv) {
config
.
repeat
=
1
;
config
.
repeat
=
1
;
config
.
dbnum
=
0
;
config
.
dbnum
=
0
;
config
.
interactive
=
0
;
config
.
interactive
=
0
;
config
.
monitor_mode
=
0
;
config
.
pubsub_mode
=
0
;
config
.
auth
=
NULL
;
config
.
auth
=
NULL
;
firstarg
=
parseOptions
(
argc
,
argv
);
firstarg
=
parseOptions
(
argc
,
argv
);
...
...
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