diff options
author | antirez <antirez@gmail.com> | 2015-07-13 18:06:24 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-07-13 18:09:41 +0200 |
commit | 4c7ee0d5848ab12b9d2b18bca62cffcbfac0e885 (patch) | |
tree | 9f76103d5a38ed7307fadb145b7a658bb369ef1e | |
parent | 5c4fcaf3fe448c5575a9911edbcd421c6dbebb54 (diff) | |
download | redis-4c7ee0d5848ab12b9d2b18bca62cffcbfac0e885.tar.gz |
EXISTS is now variadic.
The new return value is the number of keys existing, among the ones
specified in the command line, counting the same key multiple times if
given multiple times (and if it exists).
See PR #2667.
-rw-r--r-- | src/db.c | 14 | ||||
-rw-r--r-- | src/redis.c | 2 |
2 files changed, 10 insertions, 6 deletions
@@ -318,13 +318,17 @@ void delCommand(redisClient *c) { addReplyLongLong(c,deleted); } +/* EXISTS key1 key2 ... key_N. + * Return value is the number of keys existing. */ void existsCommand(redisClient *c) { - expireIfNeeded(c->db,c->argv[1]); - if (dbExists(c->db,c->argv[1])) { - addReply(c, shared.cone); - } else { - addReply(c, shared.czero); + long long count = 0; + int j; + + for (j = 1; j < c->argc; j++) { + expireIfNeeded(c->db,c->argv[j]); + if (dbExists(c->db,c->argv[j])) count++; } + addReplyLongLong(c,count); } void selectCommand(redisClient *c) { diff --git a/src/redis.c b/src/redis.c index 1bcd8375e..656c21ff2 100644 --- a/src/redis.c +++ b/src/redis.c @@ -132,7 +132,7 @@ struct redisCommand redisCommandTable[] = { {"append",appendCommand,3,"wm",0,NULL,1,1,1,0,0}, {"strlen",strlenCommand,2,"rF",0,NULL,1,1,1,0,0}, {"del",delCommand,-2,"w",0,NULL,1,-1,1,0,0}, - {"exists",existsCommand,2,"rF",0,NULL,1,1,1,0,0}, + {"exists",existsCommand,-2,"rF",0,NULL,1,-1,1,0,0}, {"setbit",setbitCommand,4,"wm",0,NULL,1,1,1,0,0}, {"getbit",getbitCommand,3,"rF",0,NULL,1,1,1,0,0}, {"setrange",setrangeCommand,4,"wm",0,NULL,1,1,1,0,0}, |