-
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
Add multiple reactive keys exist checker #2918
Open
AnneMayor
wants to merge
2
commits into
spring-projects:main
Choose a base branch
from
AnneMayor:add-multiple-reactive-keys-exist-checker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,28 @@ void existsShouldReturnFalseForNonExistingKeys() { | |
connection.keyCommands().exists(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(false).verifyComplete(); | ||
} | ||
|
||
@ParameterizedRedisTest | ||
void existsShouldReturnTrueWhenKeysExist() { | ||
|
||
nativeCommands.set(KEY_1, VALUE_1); | ||
nativeCommands.set(KEY_2, VALUE_2); | ||
|
||
connection.keyCommands().exists(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).as(StepVerifier::create) | ||
.expectNext(true) | ||
.verifyComplete(); | ||
} | ||
|
||
@ParameterizedRedisTest | ||
void existsShouldReturnFalseWhenKeysDoNotExist() { | ||
|
||
nativeCommands.set(KEY_1, VALUE_1); | ||
|
||
connection.keyCommands().exists(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).as(StepVerifier::create) | ||
.expectNext(false) // | ||
.verifyComplete(); | ||
} | ||
|
||
|
||
@ParameterizedRedisTest // DATAREDIS-525 | ||
void typeShouldReturnTypeCorrectly() { | ||
|
||
|
@@ -164,7 +186,7 @@ void renameShouldAlterKeyNameCorrectly() { | |
connection.keyCommands().rename(KEY_1_BBUFFER, KEY_2_BBUFFER).as(StepVerifier::create).expectNext(true) | ||
.verifyComplete(); | ||
assertThat(nativeCommands.exists(KEY_2)).isEqualTo(1L); | ||
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L); | ||
assertThat(nativeCommands.exists(KEY_1)).isZero(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just changed the command to make better readability according to sonarlint rules. |
||
} | ||
|
||
@ParameterizedRedisTest // DATAREDIS-525 | ||
|
@@ -183,7 +205,7 @@ void renameNXShouldAlterKeyNameCorrectly() { | |
.verifyComplete(); | ||
|
||
assertThat(nativeCommands.exists(KEY_2)).isEqualTo(1L); | ||
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L); | ||
assertThat(nativeCommands.exists(KEY_1)).isZero(); | ||
} | ||
|
||
@ParameterizedRedisTest // DATAREDIS-525 | ||
|
@@ -395,7 +417,7 @@ void shouldMoveToDatabase() { | |
.expectNext(true) // | ||
.expectComplete() // | ||
.verify(); | ||
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L); | ||
assertThat(nativeCommands.exists(KEY_1)).isZero(); | ||
} | ||
|
||
@ParameterizedRedisTest // DATAREDIS-694 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I created a validation method which is for checking if parameterized all keys exist in redis cache. If one of them does not exist, it returns false.
@kutlueren , please check if this function is what you meant to use.
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.
Hey @AnneMayor
Awesome to see that you added the function which carries out what I suggested. It is actually more straight forward than I initially thought, maybe I got confused in the codebase but nice! I shall try it out as soon as it gets merged.
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.
This implementation calls
EXISTS
for each key issuing a command for each element in the list.Redis'
EXISTS
command accepts multiple arguments and returns how many of the keys exist. Our interface should use the existing functionality instead of putting another layer on top of commands with a worse performance behavior.The issue we have here is however that
exists(Publisher<KeyCommand> keys)
andexists(Publisher<List<KeyCommand>> keys)
orexists(Publisher<MultiKeyCommand>> keys)
erase to the same type and we cannot simply introduce such an override.I suggest to implement
Mono<Long> exists(List<ByteBuffer> keys)
directly instead of usingdefault
methods. Also,ReactiveRedisOperations
should be extended withcountExistingKeys(…)
similar toRedisTemplate.countExistingKeys(…)
.