Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new commands ZDIFF and ZDIFFSTORE #7961

Merged
merged 25 commits into from Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
965ece1
Add new commands ZDIFF and ZDIFFSTORE
felipou Oct 25, 2020
ee7ca2f
Merge remote-tracking branch 'upstream/unstable' into zdiffstore
felipou Oct 25, 2020
c292f36
Add algorithm 2 option to zdiff
felipou Oct 25, 2020
b39b3be
Add sort step to algorithm 1 of zdiff
felipou Oct 28, 2020
64b561f
Add extra cardinality check to zdiff algorithm 2
felipou Oct 28, 2020
95c78ed
Use dict iteration directly to find max element length
felipou Oct 28, 2020
8ed99fd
Revert changes to help.h adding zdiff/zdiffstore
felipou Oct 28, 2020
d147091
Remove unused variables from zdiffAlgorithm2
felipou Oct 28, 2020
e7d226c
Adjusted the note about the error when lacking keys for eviction
felipou Oct 28, 2020
1efe956
Make all new internal functions static
felipou Oct 31, 2020
0abf6c8
Extract function zsetslDel from zsetDel and zdiffAlgorithm2
felipou Oct 31, 2020
72c51f8
Change eviction write commands note to text suggested by oranagra
felipou Oct 31, 2020
d521048
Fix leak by properly releasing dict iterator
felipou Oct 31, 2020
58d541b
Rename new zset internal functions
felipou Oct 31, 2020
fc05b83
Fix internal function call names after name change
felipou Oct 31, 2020
f7444fc
Fix zdiff algorithms complexity in code comments
felipou Oct 31, 2020
8d631da
Minor optimization to zdiff
felipou Oct 31, 2020
2e4b312
Add extra comment about algorithm cost in zdiff algorithm 2
felipou Oct 31, 2020
0472a32
Remove comment that became useless in zdiff algorithm 1
felipou Oct 31, 2020
714e08e
Add more tests for zdiff
felipou Oct 31, 2020
ac31448
Add back same set check with extra comments
felipou Nov 1, 2020
23a3c14
Rename function zsetslDel to zsetRemoveFromSkiplist
felipou Nov 1, 2020
c7132a0
Remove check for nan
felipou Nov 11, 2020
dc119ed
Update algorithm complexities as per review suggestions
felipou Nov 13, 2020
540a78b
Syntax error for z(diff/inter/union)store if using WITHSCORES argument
felipou Nov 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions redis.conf
Expand Up @@ -891,14 +891,12 @@ acllog-max-len 128
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
#
# Note: with any of the above policies, Redis will return an error on write
# operations, when there are no suitable keys for eviction.
#
# At the date of writing these commands are: set setnx setex append
# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
# getset mset msetnx exec sort
# Note: with any of the above policies, when there are no suitable keys for
# eviction, Redis will return an error on write operations that require
# more memory. These are usually commands that create new keys, add data or
# modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,
# SORT (due to the STORE argument), and EXEC (if the transaction includes any
# command that requires memory).
#
# The default is:
#
Expand Down
4 changes: 2 additions & 2 deletions src/db.c
Expand Up @@ -1441,12 +1441,12 @@ int genericGetKeys(int storeKeyOfs, int keyCountOfs, int firstKeyOfs, int keySte
return result->numkeys;
}

int zunionInterStoreGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
int zunionInterDiffStoreGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
UNUSED(cmd);
return genericGetKeys(1, 2, 3, 1, argv, argc, result);
}

int zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
int zunionInterDiffGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
UNUSED(cmd);
return genericGetKeys(0, 1, 2, 1, argv, argc, result);
}
Expand Down
16 changes: 12 additions & 4 deletions src/server.c
Expand Up @@ -436,19 +436,27 @@ struct redisCommand redisCommandTable[] = {

{"zunionstore",zunionstoreCommand,-4,
"write use-memory @sortedset",
0,zunionInterStoreGetKeys,0,0,0,0,0,0},
0,zunionInterDiffStoreGetKeys,0,0,0,0,0,0},

{"zinterstore",zinterstoreCommand,-4,
"write use-memory @sortedset",
0,zunionInterStoreGetKeys,0,0,0,0,0,0},
0,zunionInterDiffStoreGetKeys,0,0,0,0,0,0},

{"zdiffstore",zdiffstoreCommand,-4,
"write use-memory @sortedset",
0,zunionInterDiffStoreGetKeys,0,0,0,0,0,0},

{"zunion",zunionCommand,-3,
"read-only @sortedset",
0,zunionInterGetKeys,0,0,0,0,0,0},
0,zunionInterDiffGetKeys,0,0,0,0,0,0},

{"zinter",zinterCommand,-3,
"read-only @sortedset",
0,zunionInterGetKeys,0,0,0,0,0,0},
0,zunionInterDiffGetKeys,0,0,0,0,0,0},

{"zdiff",zdiffCommand,-3,
"read-only @sortedset",
0,zunionInterDiffGetKeys,0,0,0,0,0,0},

{"zrange",zrangeCommand,-4,
"read-only @sortedset",
Expand Down
6 changes: 4 additions & 2 deletions src/server.h
Expand Up @@ -2197,8 +2197,8 @@ void freeObjAsync(robj *o);
int *getKeysPrepareResult(getKeysResult *result, int numkeys);
int getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
void getKeysFreeResult(getKeysResult *result);
int zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result);
int zunionInterStoreGetKeys(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result);
int zunionInterDiffGetKeys(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result);
int zunionInterDiffStoreGetKeys(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result);
int evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
int sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
int migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
Expand Down Expand Up @@ -2417,8 +2417,10 @@ void hstrlenCommand(client *c);
void zremrangebyrankCommand(client *c);
void zunionstoreCommand(client *c);
void zinterstoreCommand(client *c);
void zdiffstoreCommand(client *c);
void zunionCommand(client *c);
void zinterCommand(client *c);
void zdiffCommand(client *c);
void zscanCommand(client *c);
void hkeysCommand(client *c);
void hvalsCommand(client *c);
Expand Down