Last active
September 28, 2020 16:34
-
-
Save amirbehzad/5fc8487fd357a5a2efbd to your computer and use it in GitHub Desktop.
How to LPOP multiple items from a Redis LIST in Python
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
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks