Commit 7ae1d4d6 authored by antirez's avatar antirez
Browse files

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.
parent 55e8d4cf
...@@ -293,13 +293,17 @@ void delCommand(redisClient *c) { ...@@ -293,13 +293,17 @@ void delCommand(redisClient *c) {
addReplyLongLong(c,deleted); addReplyLongLong(c,deleted);
} }
/* EXISTS key1 key2 ... key_N.
* Return value is the number of keys existing. */
void existsCommand(redisClient *c) { void existsCommand(redisClient *c) {
expireIfNeeded(c->db,c->argv[1]); long long count = 0;
if (dbExists(c->db,c->argv[1])) { int j;
addReply(c, shared.cone);
} else { for (j = 1; j < c->argc; j++) {
addReply(c, shared.czero); expireIfNeeded(c->db,c->argv[j]);
if (dbExists(c->db,c->argv[j])) count++;
} }
addReplyLongLong(c,count);
} }
void selectCommand(redisClient *c) { void selectCommand(redisClient *c) {
......
...@@ -129,7 +129,7 @@ struct redisCommand redisCommandTable[] = { ...@@ -129,7 +129,7 @@ struct redisCommand redisCommandTable[] = {
{"append",appendCommand,3,"wm",0,NULL,1,1,1,0,0}, {"append",appendCommand,3,"wm",0,NULL,1,1,1,0,0},
{"strlen",strlenCommand,2,"rF",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}, {"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}, {"setbit",setbitCommand,4,"wm",0,NULL,1,1,1,0,0},
{"getbit",getbitCommand,3,"rF",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}, {"setrange",setrangeCommand,4,"wm",0,NULL,1,1,1,0,0},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment