Last active
April 19, 2017 20:54
-
-
Save mitallast/b401c5a95db3716226b1 to your computer and use it in GitHub Desktop.
Average metrics using redis operations
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
# retrieve_metric_avg.lua $operation_type | |
local operation_type = ARGV[1]; | |
local count = redis.call("HGET", "operations_count", operation_type) | |
local total = redis.call("HGET", "operations_total", operation_type) | |
if not count or not total then | |
return 0 | |
else | |
local avg = tonumber(total)/tonumber(count) | |
return tostring(avg) | |
end |
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
# update_metric_avg.lua $operation_type $uuid | |
local operation_type = ARGV[1] | |
local uuid = ARGV[2] | |
redis.call("HINCRBY", "operations_count", operation_type, 1) | |
local not_exists = redis.call("HSETNX", "operations_" .. operation_type .. "_users", uuid, 1) | |
if not_exists == 1 then | |
redis.call("HINCRBY", "operations_total", operation_type, 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment