Last active
December 5, 2019 02:33
-
-
Save Hidendra/cc573d1bb26899cb321e to your computer and use it in GitHub Desktop.
Aggregate values in a redis sorted set. Returns {count, sum, min, max}
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
local result = redis.call('zrange', KEYS[1], 0, -1, 'withscores') | |
local count = 0 | |
local sum = 0 | |
local min = 0 | |
local max = 0 | |
for i=1, #result, 2 do | |
local score = result[i + 1] | |
count = count + 1 | |
sum = sum + score | |
if i == 1 then | |
min = score | |
max = score | |
else | |
min = math.min(min, score) | |
max = math.max(max, score) | |
end | |
end | |
return { | |
count, sum, min, max | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try using zscan