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
8165a5f2
Commit
8165a5f2
authored
Oct 17, 2009
by
antirez
Browse files
added multi-bulk protocol support to redis-cli and support for MSET and MSETNX
parent
2ed22c8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis-cli.c
View file @
8165a5f2
...
...
@@ -42,6 +42,7 @@
#define REDIS_CMD_INLINE 1
#define REDIS_CMD_BULK 2
#define REDIS_CMD_MULTIBULK 3
#define REDIS_NOTUSED(V) ((void) V)
...
...
@@ -113,6 +114,8 @@ static struct redisCommand cmdTable[] = {
{
"ttl"
,
2
,
REDIS_CMD_INLINE
},
{
"slaveof"
,
3
,
REDIS_CMD_INLINE
},
{
"debug"
,
-
2
,
REDIS_CMD_INLINE
},
{
"mset"
,
-
3
,
REDIS_CMD_MULTIBULK
},
{
"msetnx"
,
-
3
,
REDIS_CMD_MULTIBULK
},
{
NULL
,
0
,
0
}
};
...
...
@@ -255,18 +258,27 @@ static int cliSendCommand(int argc, char **argv) {
if
((
fd
=
cliConnect
())
==
-
1
)
return
1
;
/* Build the command to send */
for
(
j
=
0
;
j
<
argc
;
j
++
)
{
if
(
j
!=
0
)
cmd
=
sdscat
(
cmd
,
" "
);
if
(
j
==
argc
-
1
&&
rc
->
flags
&
REDIS_CMD_BULK
)
{
cmd
=
sdscatprintf
(
cmd
,
"%d"
,
sdslen
(
argv
[
j
]));
}
else
{
if
(
rc
->
flags
&
REDIS_CMD_MULTIBULK
)
{
cmd
=
sdscatprintf
(
cmd
,
"*%d
\r\n
"
,
argc
);
for
(
j
=
0
;
j
<
argc
;
j
++
)
{
cmd
=
sdscatprintf
(
cmd
,
"$%d
\r\n
"
,
sdslen
(
argv
[
j
]));
cmd
=
sdscatlen
(
cmd
,
argv
[
j
],
sdslen
(
argv
[
j
]));
cmd
=
sdscatlen
(
cmd
,
"
\r\n
"
,
2
);
}
}
else
{
for
(
j
=
0
;
j
<
argc
;
j
++
)
{
if
(
j
!=
0
)
cmd
=
sdscat
(
cmd
,
" "
);
if
(
j
==
argc
-
1
&&
rc
->
flags
&
REDIS_CMD_BULK
)
{
cmd
=
sdscatprintf
(
cmd
,
"%d"
,
sdslen
(
argv
[
j
]));
}
else
{
cmd
=
sdscatlen
(
cmd
,
argv
[
j
],
sdslen
(
argv
[
j
]));
}
}
}
cmd
=
sdscat
(
cmd
,
"
\r\n
"
);
if
(
rc
->
flags
&
REDIS_CMD_BULK
)
{
cmd
=
sdscatlen
(
cmd
,
argv
[
argc
-
1
],
sdslen
(
argv
[
argc
-
1
]));
cmd
=
sdscat
(
cmd
,
"
\r\n
"
);
if
(
rc
->
flags
&
REDIS_CMD_BULK
)
{
cmd
=
sdscatlen
(
cmd
,
argv
[
argc
-
1
],
sdslen
(
argv
[
argc
-
1
]));
cmd
=
sdscatlen
(
cmd
,
"
\r\n
"
,
2
);
}
}
anetWrite
(
fd
,
cmd
,
sdslen
(
cmd
));
retval
=
cliReadReply
(
fd
);
...
...
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