Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aciddust opened this issue May 4, 2023 · 1 comment
Closed

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

aciddust opened this issue May 4, 2023 · 1 comment

Comments

@aciddust
Copy link
Contributor

aciddust commented May 4, 2023

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")
@aciddust
Copy link
Contributor Author

aciddust commented May 8, 2023

#2739 merged

@aciddust aciddust closed this as completed May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant