Skip to content

Instantly share code, notes, and snippets.

@jarcoal
Created May 14, 2013 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarcoal/5574012 to your computer and use it in GitHub Desktop.
Save jarcoal/5574012 to your computer and use it in GitHub Desktop.
Misc Lua Scripts for Redis
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
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