Description
Version:
- redis/redis 5.0, 7.0.2, unstable build
- redis/redis-py latest version
Platform: Python 3.10.4 on macOS 12.2.1
Description:
r/ #2739
How about modify the limit of the maxlen parameter that can be passed when using the xadd command?
Some users may want to create an empty stream with xadd.
While using stream, I also felt the need to empty the contents of the stream once.
Since xadd's maxlen
did not allow 0 at the time,
I solved the problem using execute_command
,
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
# not working
# r.xadd("my-stream", {"hello": "world"}, maxlen=0)
# it works
r.execute_command("XADD", "my-stream", "MAXLEN", "0", "*", "data", "{}")
execute_command
is preety good.
but someone might want to implement these logic with XADD
.
redis 5.0 and unstable version as well
Since stream was added, it accepts integers up to and including 0.
-
from redis/redis
5.0
branch
https://github.com/redis/redis/blob/05827336b0efcb454bcc5fe77ceacc6f226b6bb2/src/t_stream.c#L1269 -
from redis/redis
unstable
branch
https://github.com/redis/redis/blob/5e3be1be09c947810732e7be2a4bb1b0ed75de4a/src/t_stream.c#LL941C30-L941C30
So, I suggest changing the MAXLEN
of the XADD
command to allow a positive number including 0.
AS-IS:
if maxlen is not None:
if not isinstance(maxlen, int) or maxlen < 1:
raise DataError("XADD maxlen must be a positive integer")
TO-BE:
if maxlen is not None:
if not isinstance(maxlen, int) or maxlen < 0:
raise DataError("XADD maxlen must be non-negative integer")