Skip to content

Commit

Permalink
Add multiple reactive keys exist checker
Browse files Browse the repository at this point in the history
  • Loading branch information
AnneMayor committed May 27, 2024
1 parent 3ab09fb commit cf160e7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ default Mono<Boolean> exists(ByteBuffer key) {

return exists(Mono.just(new KeyCommand(key))).next().map(BooleanResponse::getOutput);
}
/**
* Determine if given all {@literal keys} exist.
*
* @param keys must not be {@literal null} or {@literal empty}.
* @return {@link Mono} emitting {@literal true} if all keys exist.
* @see <a href="https://redis.io/commands/exists">Redis Documentation: EXISTS</a>
*/
default Mono<Boolean> exists(List<ByteBuffer> keys) {

Assert.notNull(keys, "Keys must not be null");
Assert.notEmpty(keys, "Keys must not be empty");

return exists(Flux.fromIterable(keys).map(KeyCommand::new)).all(BooleanResponse::getOutput);
}

/**
* Determine if given {@literal key} exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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();
}

@ParameterizedRedisTest // DATAREDIS-525
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf160e7

Please sign in to comment.