Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 0c3d2ba

Browse files
NOMKSTREAM support for XADD (redis/redis-py#1507) Signed-off-by: Andrew-Chen-Wang <[email protected]>
1 parent e41b41c commit 0c3d2ba

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

aioredis/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,7 @@ def xadd(
27722772
id: StreamIdT = "*",
27732773
maxlen: Optional[int] = None,
27742774
approximate: bool = True,
2775+
nomkstream: bool = False,
27752776
) -> Awaitable:
27762777
"""
27772778
Add to a stream.
@@ -2780,7 +2781,7 @@ def xadd(
27802781
id: Location to insert this record. By default it is appended.
27812782
maxlen: truncate old stream members beyond this size
27822783
approximate: actual stream length may be slightly more than maxlen
2783-
2784+
nomkstream: When set to true, do not make a stream
27842785
"""
27852786
pieces: List[EncodableT] = []
27862787
if maxlen is not None:
@@ -2790,6 +2791,8 @@ def xadd(
27902791
if approximate:
27912792
pieces.append(b"~")
27922793
pieces.append(str(maxlen))
2794+
if nomkstream:
2795+
pieces.append(b"NOMKSTREAM")
27932796
pieces.append(id)
27942797
if not isinstance(fields, dict) or len(fields) == 0:
27952798
raise DataError("XADD fields must be a non-empty dict")

tests/test_commands.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ async def test_pttl_no_key(self, r: aioredis.Redis):
963963
assert await r.pttl("a") == -2
964964

965965
@skip_if_server_version_lt("6.2.0")
966-
def test_hrandfield(self, r):
966+
async def test_hrandfield(self, r: aioredis.Redis):
967967
assert await r.hrandfield("key") is None
968968
await r.hset("key", mapping={"a": 1, "b": 2, "c": 3, "d": 4, "e": 5})
969969
assert await r.hrandfield("key") is not None
@@ -2457,6 +2457,16 @@ async def test_xadd(self, r: aioredis.Redis):
24572457
await r.xadd(stream, {"foo": "bar"}, maxlen=2, approximate=False)
24582458
assert await r.xlen(stream) == 2
24592459

2460+
@skip_if_server_version_lt("6.2.0")
2461+
async def test_xadd_nomkstream(self, r: aioredis.Redis):
2462+
# nomkstream option
2463+
stream = "stream"
2464+
await r.xadd(stream, {"foo": "bar"})
2465+
await r.xadd(stream, {"some": "other"}, nomkstream=False)
2466+
assert await r.xlen(stream) == 2
2467+
await r.xadd(stream, {"some": "other"}, nomkstream=True)
2468+
assert await r.xlen(stream) == 3
2469+
24602470
@skip_if_server_version_lt("5.0.0")
24612471
async def test_xclaim(self, r: aioredis.Redis):
24622472
stream = "stream"

0 commit comments

Comments
 (0)