Skip to content

Commit 57cf7ff

Browse files
authored
NOMKSTREAM support for XADD (#1507)
1 parent 627db54 commit 57cf7ff

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

redis/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,15 +2531,16 @@ def xack(self, name, groupname, *ids):
25312531
"""
25322532
return self.execute_command('XACK', name, groupname, *ids)
25332533

2534-
def xadd(self, name, fields, id='*', maxlen=None, approximate=True):
2534+
def xadd(self, name, fields, id='*', maxlen=None, approximate=True,
2535+
nomkstream=False):
25352536
"""
25362537
Add to a stream.
25372538
name: name of the stream
25382539
fields: dict of field/value pairs to insert into the stream
25392540
id: Location to insert this record. By default it is appended.
25402541
maxlen: truncate old stream members beyond this size
25412542
approximate: actual stream length may be slightly more than maxlen
2542-
2543+
nomkstream: When set to true, do not make a stream
25432544
"""
25442545
pieces = []
25452546
if maxlen is not None:
@@ -2549,6 +2550,8 @@ def xadd(self, name, fields, id='*', maxlen=None, approximate=True):
25492550
if approximate:
25502551
pieces.append(b'~')
25512552
pieces.append(str(maxlen))
2553+
if nomkstream:
2554+
pieces.append(b'NOMKSTREAM')
25522555
pieces.append(id)
25532556
if not isinstance(fields, dict) or len(fields) == 0:
25542557
raise DataError('XADD fields must be a non-empty dict')

tests/test_commands.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,16 @@ def test_xadd(self, r):
22472247
r.xadd(stream, {'foo': 'bar'}, maxlen=2, approximate=False)
22482248
assert r.xlen(stream) == 2
22492249

2250+
@skip_if_server_version_lt('6.2.0')
2251+
def test_xadd_nomkstream(self, r):
2252+
# nomkstream option
2253+
stream = 'stream'
2254+
r.xadd(stream, {'foo': 'bar'})
2255+
r.xadd(stream, {'some': 'other'}, nomkstream=False)
2256+
assert r.xlen(stream) == 2
2257+
r.xadd(stream, {'some': 'other'}, nomkstream=True)
2258+
assert r.xlen(stream) == 3
2259+
22502260
@skip_if_server_version_lt('5.0.0')
22512261
def test_xclaim(self, r):
22522262
stream = 'stream'

0 commit comments

Comments
 (0)