Last active
August 29, 2015 14:06
-
-
Save jesg/621ef344a8b0b3e31a0d to your computer and use it in GitHub Desktop.
pop all elements from a redis list
This file contains 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 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 |
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
Pop all elements from a list in redis