diff options
author | antirez <antirez@gmail.com> | 2014-06-27 12:05:54 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-06-27 18:38:08 +0200 |
commit | 0a6649a7c0c63115fab98d5c811fc75690156f7e (patch) | |
tree | 83bb64ad02b37002145e46d5af5eab39e814b8bf /src/redis.c | |
parent | 53377f8c6da00f5bb2df265843dff73d1774fb32 (diff) | |
download | redis-0a6649a7c0c63115fab98d5c811fc75690156f7e.tar.gz |
COMMAND: fix argument parsing.
This fixes detection of wrong subcommand (that resulted in the default
all-commands output instead) and allows COMMAND INFO to be called
without arguments (resulting into an empty array) which is useful in
programmtically generated calls like the following (in Ruby):
redis.commands("command","info",*mycommands)
Note: mycommands may be empty.
Diffstat (limited to 'src/redis.c')
-rw-r--r-- | src/redis.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/redis.c b/src/redis.c index 3a57fd3bf..3dd468d45 100644 --- a/src/redis.c +++ b/src/redis.c @@ -2267,6 +2267,7 @@ void timeCommand(redisClient *c) { } +/* Helper function for addReplyCommand() to output flags. */ int addReplyCommandFlag(redisClient *c, struct redisCommand *cmd, int f, char *reply) { if (cmd->flags & f) { addReplyStatus(c, reply); @@ -2275,6 +2276,7 @@ int addReplyCommandFlag(redisClient *c, struct redisCommand *cmd, int f, char *r return 0; } +/* Output the representation of a Redis command. Used by the COMMAND command. */ void addReplyCommand(redisClient *c, struct redisCommand *cmd) { if (!cmd) { addReply(c, shared.nullbulk); @@ -2310,26 +2312,27 @@ void addReplyCommand(redisClient *c, struct redisCommand *cmd) { } } +/* COMMAND <subcommand> <args> */ void commandCommand(redisClient *c) { dictIterator *di; dictEntry *de; - if (c->argc > 2 && !strcasecmp(c->argv[1]->ptr, "info")) { + if (c->argc == 1) { + addReplyMultiBulkLen(c, dictSize(server.commands)); + di = dictGetIterator(server.commands); + while ((de = dictNext(di)) != NULL) { + addReplyCommand(c, dictGetVal(de)); + } + dictReleaseIterator(di); + } else if (!strcasecmp(c->argv[1]->ptr, "info")) { int i; addReplyMultiBulkLen(c, c->argc-2); for (i = 2; i < c->argc; i++) { addReplyCommand(c, dictFetchValue(server.commands, c->argv[i]->ptr)); } - } else if (c->argc > 2) { + } else { addReplyError(c, "Unknown subcommand."); return; - } else { - addReplyMultiBulkLen(c, dictSize(server.commands)); - di = dictGetIterator(server.commands); - while ((de = dictNext(di)) != NULL) { - addReplyCommand(c, dictGetVal(de)); - } - dictReleaseIterator(di); } } |