Skip to content

Instantly share code, notes, and snippets.

@robraux
Created January 22, 2013 16:04
Show Gist options
  • Save robraux/4595824 to your computer and use it in GitHub Desktop.
Save robraux/4595824 to your computer and use it in GitHub Desktop.
-- lua has no split string, so we need to write our own
-- explode(seperator, string)
local explode = function(d,p)
local t, ll, l
t={}
ll=0
if(#p == 1) then return {p} end
while true do
l=string.find(p,d,ll,true) -- find the next d in the string
if l~=nil then -- if "not not" found then..
table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array.
ll=l+1 -- save just after where we found it for searching next time.
else
table.insert(t, string.sub(p,ll)) -- Save what's left in our array.
break
end
end
return t
end
-- fetch all keys, explode them on :, and do some fake action
res = redis.call('keys', '*')
for key, value in pairs(res)
do
-- assume key is something like 'some name:123'
local keyPieces = explode(':', value)
local num = tonumber(keyPieces[2])
if(num == nil or (keyPieces[1] == 'some name' and num < 500)) then
-- take some action if the format matches, the key is named, and the integer is below 500
end
end
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment