diff options
author | Chayim <chayim@users.noreply.github.com> | 2021-08-15 13:46:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 13:46:01 +0300 |
commit | e498182b8e208911ea2454838109fb1249b83c5c (patch) | |
tree | c894384c8029d098ea5dfcf30e08f797c3fd7693 /redis/client.py | |
parent | 37e7c093cbeaf7133d5dd7189563d5c15da8d12b (diff) | |
download | redis-py-e498182b8e208911ea2454838109fb1249b83c5c.tar.gz |
MINID and LIMIT support for xtrim (#1508)
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/redis/client.py b/redis/client.py index a80012a..2d47574 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2979,17 +2979,35 @@ class Redis: return self.execute_command('XREVRANGE', name, *pieces) - def xtrim(self, name, maxlen, approximate=True): + def xtrim(self, name, maxlen=None, approximate=True, minid=None, + limit=None): """ Trims old messages from a stream. name: name of the stream. maxlen: truncate old stream messages beyond this size approximate: actual stream length may be slightly more than maxlen + minin: the minimum id in the stream to query + limit: specifies the maximum number of entries to retrieve """ - pieces = [b'MAXLEN'] + pieces = [] + if maxlen is not None and minid is not None: + raise DataError("Only one of ```maxlen``` or ```minid```", + "may be specified") + + if maxlen is not None: + pieces.append(b'MAXLEN') + if minid is not None: + pieces.append(b'MINID') if approximate: pieces.append(b'~') - pieces.append(maxlen) + if maxlen is not None: + pieces.append(maxlen) + if minid is not None: + pieces.append(minid) + if limit is not None: + pieces.append(b"LIMIT") + pieces.append(limit) + return self.execute_command('XTRIM', name, *pieces) # SORTED SET COMMANDS |