Created
September 22, 2017 15:14
-
-
Save sankalpjonn/c70536b3c8bad42a0f1df1ab4a0f5012 to your computer and use it in GitHub Desktop.
Golang redis example for targeting
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 m = redis.call("ZREVRANGE", ARGV[1], "0", "0", "WITHSCORES"); | |
if m ~= nil and m[2] ~= nil then | |
local max_priority = m[2] | |
local a = redis.call("ZRANGEBYSCORE", ARGV[1], max_priority, max_priority); | |
if a ~= nil and #a > 0 then | |
math.randomseed(ARGV[2]) | |
local ad_id = math.random(#a) | |
return redis.call("HGET", "ad:" .. a[ad_id] .. ":attrs", "ad_response"); | |
end | |
end | |
return nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment