Skip to content

Instantly share code, notes, and snippets.

@sankalpjonn
Created September 22, 2017 15:14
Show Gist options
  • Save sankalpjonn/c70536b3c8bad42a0f1df1ab4a0f5012 to your computer and use it in GitHub Desktop.
Save sankalpjonn/c70536b3c8bad42a0f1df1ab4a0f5012 to your computer and use it in GitHub Desktop.
Golang redis example for targeting
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