Skip to content

Allow non-negative MAXLEN including 0 on XADD command #2742

Closed
@aciddust

Description

@aciddust

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.

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions