Skip to content

Instantly share code, notes, and snippets.

@amirbehzad
Last active September 28, 2020 16:34
Show Gist options
  • Save amirbehzad/5fc8487fd357a5a2efbd to your computer and use it in GitHub Desktop.
Save amirbehzad/5fc8487fd357a5a2efbd to your computer and use it in GitHub Desktop.
How to LPOP multiple items from a Redis LIST in Python
# function to return multiple items (n) from a redis list (q) in an atomic manner
# as seen in: http://redis.io/commands/lpop#comment-431677622
def multi_pop(r, q, n):
p = r.pipeline()
p.multi()
p.lrange(q, 0, n - 1)
p.ltrim(q, n, -1)
return p.execute()
@DeoLeung
Copy link

thanks

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