Skip to content

Instantly share code, notes, and snippets.

@jesg
Last active August 29, 2015 14:06
Show Gist options
  • Save jesg/621ef344a8b0b3e31a0d to your computer and use it in GitHub Desktop.
Save jesg/621ef344a8b0b3e31a0d to your computer and use it in GitHub Desktop.
pop all elements from a redis list
local result = {}
local length = tonumber(redis.call('LLEN', KEYS[1]))
for i = 1 , length do
local val = redis.call('LPOP',KEYS[1])
if val then
table.insert(result,val)
end
end
return result
@jesg
Copy link
Author

jesg commented Sep 24, 2014

Pop all elements from a list in redis

@jesg
Copy link
Author

jesg commented Sep 24, 2014

For loops in lua are inclusive so start at 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment