Created
May 14, 2013 06:02
-
-
Save jarcoal/5574012 to your computer and use it in GitHub Desktop.
Misc Lua Scripts 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
local radius, x, y = unpack(ARGV) | |
local locations = redis.call('HGETALL', KEYS[1]) | |
local nearby = {} | |
for i = 1, #locations, 2 do | |
local cid, cloc = locations[i], locations[i+1] | |
local cx, cy = string.sub(cloc, 1, 2), string.sub(cloc, 3, 4) | |
if (cx - x)^2 + (cy - y)^2 <= radius^2 then | |
table.insert(nearby, cid) | |
end | |
end | |
return nearby |
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 radius, x, y, z = unpack(ARGV) | |
local locations = redis.call('HGETALL', KEYS[1]) | |
local nearby = {} | |
for i = 1, #locations, 2 do | |
local cid, cloc = locations[i], locations[i+1] | |
local cx, cy, cz = string.sub(cloc, 1, 2), string.sub(cloc, 3, 4), string.sub(cloc, 5, 6) | |
if (cx - x)^2 + (cy - y)^2 + (cz - z)^2 <= radius^2 then | |
table.insert(nearby, cid) | |
end | |
end | |
return nearby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment