Created
January 21, 2014 17:32
-
-
Save holderbaum/8544380 to your computer and use it in GitHub Desktop.
Competiton ranking for redis
This file contains hidden or 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
ocal offset = ARGV[1] | |
local limit = ARGV[2] | |
local users = redis.call('zrevrange', KEYS[1], offset, offset + limit, 'WITHSCORES') | |
local result = {} | |
for i=1,#users,2 do | |
local user = users[i] | |
local score = users[i+1] | |
local min_score = score + 1 | |
local comp_rank = redis.call('zcount', KEYS[1] , min_score, '+inf') + 1 | |
local rank = redis.call('zrevrank', KEYS[1] , user) + 1 | |
-- tmp logging | |
redis.log(redis.LOG_WARNING, user .. ':' .. score .. ' ' .. rank .. ' ' .. comp_rank) | |
table.insert(result, user) | |
table.insert(result, score) | |
table.insert(result, rank) | |
table.insert(result, comp_rank) | |
end | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment