diff --git a/src/db.c b/src/db.c index 668a1193a..0a6481c8f 100644 --- a/src/db.c +++ b/src/db.c @@ -1388,7 +1388,7 @@ void getKeysFreeResult(int *result) { /* Helper function to extract keys from following commands: * ZUNIONSTORE ... * ZINTERSTORE ... */ -int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) { +int *zunionInterStoreGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) { int i, num, *keys; UNUSED(cmd); @@ -1416,6 +1416,31 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu return keys; } +/* Helper function to extract keys from following commands: + * ZUNION ... + * ZINTER ... */ +int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) { + int i, num, *keys; + UNUSED(cmd); + + num = atoi(argv[1]->ptr); + /* Sanity check. Don't return any key if the command is going to + * reply with syntax error. */ + if (num < 1 || num > (argc-2)) { + *numkeys = 0; + return NULL; + } + + keys = getKeysTempBuffer; + if (num>MAX_KEYS_BUFFER) + keys = zmalloc(sizeof(int)*(num)); + + /* Add all key positions for argv[2...n] to keys[] */ + for (i = 0; i < num; i++) keys[i] = 2+i; + *numkeys = num; + return keys; +} + /* Helper function to extract keys from the following commands: * EVAL