diff options
author | Gal Ben David <wavenator@gmail.com> | 2021-08-05 12:12:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 12:12:45 +0300 |
commit | 238f69e36e0ff5ac9b892706e3a5478b138069cd (patch) | |
tree | c8aba5b8abfb39e5bf698b2a5a097b44ef7e6a78 /redis/client.py | |
parent | 5240d60ff0636e7baaec2499c1c9018507578bf5 (diff) | |
download | redis-py-238f69e36e0ff5ac9b892706e3a5478b138069cd.tar.gz |
Add a count parameter to lpop/rpop for redis >= 6.2.0 (#1487)
Co-authored-by: Chayim <chayim@users.noreply.github.com>
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/redis/client.py b/redis/client.py index 514db53..e5cd647 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2148,9 +2148,18 @@ class Redis: "Return the length of the list ``name``" return self.execute_command('LLEN', name) - def lpop(self, name): - "Remove and return the first item of the list ``name``" - return self.execute_command('LPOP', name) + def lpop(self, name, count=None): + """ + Removes and returns the first elements of the list ``name``. + + By default, the command pops a single element from the beginning of + the list. When provided with the optional ``count`` argument, the reply + will consist of up to count elements, depending on the list's length. + """ + if count is not None: + return self.execute_command('LPOP', name, count) + else: + return self.execute_command('LPOP', name) def lpush(self, name, *values): "Push ``values`` onto the head of the list ``name``" @@ -2196,9 +2205,18 @@ class Redis: """ return self.execute_command('LTRIM', name, start, end) - def rpop(self, name): - "Remove and return the last item of the list ``name``" - return self.execute_command('RPOP', name) + def rpop(self, name, count=None): + """ + Removes and returns the last elements of the list ``name``. + + By default, the command pops a single element from the end of the list. + When provided with the optional ``count`` argument, the reply will + consist of up to count elements, depending on the list's length. + """ + if count is not None: + return self.execute_command('RPOP', name, count) + else: + return self.execute_command('RPOP', name) def rpoplpush(self, src, dst): """ |