-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix XAddOptions maxlen handling and XPendingOptions validation #2985
Fix XAddOptions maxlen handling and XPendingOptions validation #2985
Conversation
@@ -96,7 +96,7 @@ public StreamReadOptions block(Duration timeout) { | |||
*/ | |||
public StreamReadOptions count(long count) { | |||
|
|||
Assert.isTrue(count > 0, "Count must be greater or equal to zero"); | |||
Assert.isTrue(count > 0, "Count must be greater than zero"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix description to represent assertion
@@ -337,7 +337,7 @@ public Long getMaxlen() { | |||
* @since 2.3 | |||
*/ | |||
public boolean hasMaxlen() { | |||
return maxlen != null && maxlen > 0; | |||
return maxlen != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, Lettuce and Jedis treat maxlen
edge case differently. XAddArgs
in Lettuce asserts maxlen > 0
whereas Jedis doesn't check on maxlen
so it follows default redis behaviour which asserts maxlen >=0
.
My best choice was just let the user know. So I didn't put any assertion on maxlen
. If we validate against negative values (maxlen < 0
), it could be confusing since maxlen
is validated differently across multiple layers.
java.lang.IllegalArgumentException: Maxlen must be greater 0
at io.lettuce.core.internal.LettuceAssert.isTrue(LettuceAssert.java:193)
at io.lettuce.core.XAddArgs.maxlen(XAddArgs.java:121)
at org.springframework.data.redis.connection.lettuce.LettuceStreamCommands.xAdd(LettuceStreamCommands.java:84)
at org.springframework.data.redis.connection.DefaultedRedisConnection.xAdd(DefaultedRedisConnection.java:489)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.xAdd(DefaultStringRedisConnection.java:2918)
at org.springframework.data.redis.core.DefaultStreamOperations.lambda$add$2(DefaultStreamOperations.java:153)
127.0.0.1:6379> xadd mystream maxlen -1 * test "value"
(error) ERR The MAXLEN argument must be >= 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine to resort to driver defaults.
@@ -337,7 +337,7 @@ public Long getMaxlen() { | |||
* @since 2.3 | |||
*/ | |||
public boolean hasMaxlen() { | |||
return maxlen != null && maxlen > 0; | |||
return maxlen != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine to resort to driver defaults.
|
||
XAddOptions options = XAddOptions.maxlen(-1).approximateTrimming(false); | ||
|
||
assertThatThrownBy(() -> streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key), options)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing Redis/Driver behavior exceeds the scope of what we want to test. We will remove these tests during the merge.
Thank you for your contribution. That's merged, polished, and backported now. |
Thank you for the quick review! I’ve learned so much from this and the previous PR by understanding and reading the source code! |
Closes #2982