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

Negative maxlen for XAddOptions is ignored #2982

Closed
jinkshower opened this issue Sep 3, 2024 · 3 comments
Closed

Negative maxlen for XAddOptions is ignored #2982

jinkshower opened this issue Sep 3, 2024 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@jinkshower
Copy link
Contributor

jinkshower commented Sep 3, 2024

This issue refers to a comment in #2936

As we now can use XAddOptions in streamOperations,

XAddOptions options = XAddOptions.maxlen(-1);
redisTemplate.opsForStream("myStream", Map.of("key", "value"), options);

This executes without throwing an error or warning the client. Instead, the result is that the maxlen option is not applied.

IMO, this is because the XAddOptions hasMaxlen() method gets called before every time XAddOptions is used, and it checks maxlen > 0, which results in ignoring negative values for maxlen.

  • Reproducible code
@ParameterizedRedisTest
void addMinusMaxlenDoesNotThrowsException() {
	K key = keyFactory.instance();
	HV value = hashValueFactory.instance();
	XAddOptions options = XAddOptions.maxlen(-1).approximateTrimming(false);
	assertDoesNotThrow(() -> redisTemplate.opsForStream().add(StreamRecords.objectBacked(value).withStreamKey(key), options));
	assertThat(redisTemplate.opsForStream().range(key, Range.unbounded())).hasSize(1);
}

image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 3, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 3, 2024
@mp911de
Copy link
Member

mp911de commented Sep 3, 2024

We have a similar case with XPendingOptions while StreamReadOptions perform assertions on count.

@mp911de mp911de self-assigned this Sep 3, 2024
@jinkshower
Copy link
Contributor Author

@mp911de,
I’d like to continue and finish what I started for this issue. Would you mind if I handle this issue? Also, do you want the PR to cover the XPendingOptions count as well?

@mp911de
Copy link
Member

mp911de commented Sep 4, 2024

Sounds good, feel free to address both concerns within a single pull request.

@mp911de mp911de assigned jinkshower and unassigned mp911de Sep 4, 2024
@mp911de mp911de added the status: ideal-for-contribution An issue that a contributor can help us with label Sep 4, 2024
jinkshower added a commit to jinkshower/spring-data-redis that referenced this issue Sep 8, 2024
@mp911de mp911de removed the status: ideal-for-contribution An issue that a contributor can help us with label Sep 10, 2024
mp911de pushed a commit that referenced this issue Sep 10, 2024
mp911de added a commit that referenced this issue Sep 10, 2024
Refine assertions usage.

Original pull request: #2985
Closes #2982
mp911de added a commit that referenced this issue Sep 10, 2024
Refine assertions usage.

Original pull request: #2985
Closes #2982
mp911de pushed a commit that referenced this issue Sep 10, 2024
mp911de added a commit that referenced this issue Sep 10, 2024
Refine assertions usage.

Original pull request: #2985
Closes #2982
@mp911de mp911de added this to the 3.2.10 (2023.1.10) milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants