From 6248635294828b65536e04c1e69d8a276e306da0 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Wed, 14 Jul 2021 15:26:05 +0300 Subject: [PATCH] NOMKSTREAM support for XADD Part of 7910 --- redis/client.py | 7 +++++-- tests/test_commands.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/redis/client.py b/redis/client.py index 59575cd835..0e16ac23c9 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2434,7 +2434,8 @@ def xack(self, name, groupname, *ids): """ return self.execute_command('XACK', name, groupname, *ids) - def xadd(self, name, fields, id='*', maxlen=None, approximate=True): + def xadd(self, name, fields, id='*', maxlen=None, approximate=True, + nomkstream=False): """ Add to a stream. name: name of the stream @@ -2442,7 +2443,7 @@ def xadd(self, name, fields, id='*', maxlen=None, approximate=True): id: Location to insert this record. By default it is appended. maxlen: truncate old stream members beyond this size approximate: actual stream length may be slightly more than maxlen - + nomkstream: When set to true, do not make a stream """ pieces = [] if maxlen is not None: @@ -2452,6 +2453,8 @@ def xadd(self, name, fields, id='*', maxlen=None, approximate=True): if approximate: pieces.append(b'~') pieces.append(str(maxlen)) + if nomkstream: + pieces.append(b'NOMKSTREAM') pieces.append(id) if not isinstance(fields, dict) or len(fields) == 0: raise DataError('XADD fields must be a non-empty dict') diff --git a/tests/test_commands.py b/tests/test_commands.py index d1f85b7306..58d8c71438 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -2191,6 +2191,16 @@ def test_xadd(self, r): r.xadd(stream, {'foo': 'bar'}, maxlen=2, approximate=False) assert r.xlen(stream) == 2 + @skip_if_server_version_lt('6.2.0') + def test_xadd_nomkstream(self, r): + # nomkstream option + stream = 'stream' + r.xadd(stream, {'foo': 'bar'}) + r.xadd(stream, {'some': 'other'}, nomkstream=False) + assert r.xlen(stream) == 2 + r.xadd(stream, {'some': 'other'}, nomkstream=True) + assert r.xlen(stream) == 3 + @skip_if_server_version_lt('5.0.0') def test_xclaim(self, r): stream = 'stream'