-
-
Save yhemanth/aff4b54d3f97d80873cc to your computer and use it in GitHub Desktop.
Lua script that can be embedded in Redis server for adding an element to a KMinHash set backed by a Redis sorted set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local count = redis.call('ZCARD', KEYS[1]); | |
if count == tonumber(ARGV[1]) then | |
local max_score = redis.call('ZRANGE', KEYS[1], -1, -1, 'WITHSCORES')[2] | |
if tonumber(ARGV[2]) >= tonumber(max_score) then | |
return | |
else | |
redis.call('ZREMRANGEBYRANK', KEYS[1], -1, -1) | |
end | |
end | |
redis.call('ZADD', KEYS[1], tonumber(ARGV[2]), tonumber(ARGV[3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment