Created
December 26, 2015 13:02
-
-
Save seiflotfy/e57afde93c363bc99180 to your computer and use it in GitHub Desktop.
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 myset = ARGV[1] | |
local mykey = ARGV[3] | |
local set_length = tonumber(ARGV[2]) | |
if redis.call('ZRANK', myset, mykey) then | |
redis.call('ZINCRBY', myset, 1.0, mykey) | |
elseif redis.call('ZCARD', myset) < set_length then | |
redis.call('ZADD', myset, 1.0, mykey) | |
else | |
local value = redis.call('ZRANGE', myset,0,0, 'withscores') | |
redis.call('ZREM', myset, value[1]) | |
redis.call('ZADD', myset, value[2] + 1.0, mykey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment