diff options
author | Chayim <chayim@users.noreply.github.com> | 2021-07-25 09:03:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-25 09:03:55 +0300 |
commit | 57cf7ffc1fbaca2f17d03de38ee19e8af48ac153 (patch) | |
tree | 4ccafcc6e8ff2a0324ea83b8cdb2bbf545a39a96 | |
parent | 627db540acd1f1f36db88290d74cbcd75f6bda0c (diff) | |
download | redis-py-57cf7ffc1fbaca2f17d03de38ee19e8af48ac153.tar.gz |
NOMKSTREAM support for XADD (#1507)
-rwxr-xr-x | redis/client.py | 7 | ||||
-rw-r--r-- | tests/test_commands.py | 10 |
2 files changed, 15 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py index 57932b9..f822926 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2531,7 +2531,8 @@ class Redis: """ 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 @@ -2539,7 +2540,7 @@ class Redis: 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: @@ -2549,6 +2550,8 @@ class Redis: 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 27117e3..c9fdeef 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -2247,6 +2247,16 @@ class TestRedisCommands: 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' |