Skip to content

Instantly share code, notes, and snippets.

@seiflotfy
Created December 26, 2015 13:02
Show Gist options
  • Save seiflotfy/e57afde93c363bc99180 to your computer and use it in GitHub Desktop.
Save seiflotfy/e57afde93c363bc99180 to your computer and use it in GitHub Desktop.
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