Add reactive support for ZDIFF, ZDIFFSTORE, ZINTER, and ZUNION commands.
See: #2041 & #2042 Original Pull Request: #2097
This commit is contained in:
committed by
Christoph Strobl
parent
8dc6f014ee
commit
38d3576052
@@ -555,8 +555,50 @@ public class LettuceReactiveZSetCommandsIntegrationTests extends LettuceReactive
|
||||
.isEqualTo(1L);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-525
|
||||
void zUnionStoreShouldWorkCorrectly() {
|
||||
@ParameterizedRedisTest // GH-2041
|
||||
void zDiffShouldWorkCorrectly() {
|
||||
|
||||
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
|
||||
|
||||
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
|
||||
nativeCommands.zadd(KEY_2, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
|
||||
|
||||
connection.zSetCommands().zDiff(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).containsOnly(VALUE_3_BBUFFER);
|
||||
}).verifyComplete();
|
||||
|
||||
connection.zSetCommands().zDiffWithScores(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).containsOnly(new DefaultTuple(VALUE_3_BYTES, 3D));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2041
|
||||
void zDiffStoreShouldWorkCorrectly() {
|
||||
|
||||
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
|
||||
|
||||
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
|
||||
nativeCommands.zadd(KEY_2, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
|
||||
|
||||
connection.zSetCommands().zDiffStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1L).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2042
|
||||
void zInterShouldWorkCorrectly() {
|
||||
|
||||
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
|
||||
|
||||
@@ -566,9 +608,19 @@ public class LettuceReactiveZSetCommandsIntegrationTests extends LettuceReactive
|
||||
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_2, 3D, VALUE_3);
|
||||
|
||||
assertThat(connection.zSetCommands()
|
||||
.zUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block())
|
||||
.isEqualTo(3L);
|
||||
connection.zSetCommands().zInter(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).contains(VALUE_1_BBUFFER, VALUE_2_BBUFFER);
|
||||
}).verifyComplete();
|
||||
|
||||
connection.zSetCommands().zInterWithScores(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).contains(new DefaultTuple(VALUE_1_BYTES, 5D), new DefaultTuple(VALUE_2_BYTES, 10D));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-525
|
||||
@@ -587,6 +639,49 @@ public class LettuceReactiveZSetCommandsIntegrationTests extends LettuceReactive
|
||||
.isEqualTo(2L);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2042
|
||||
void zUnionShouldWorkCorrectly() {
|
||||
|
||||
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
|
||||
|
||||
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_2, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_2, 3D, VALUE_3);
|
||||
|
||||
connection.zSetCommands().zUnion(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).contains(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER);
|
||||
}).verifyComplete();
|
||||
|
||||
connection.zSetCommands().zUnionWithScores(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual).contains(new DefaultTuple(VALUE_1_BYTES, 5D), new DefaultTuple(VALUE_2_BYTES, 10D),
|
||||
new DefaultTuple(VALUE_3_BYTES, 9D));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-525
|
||||
void zUnionStoreShouldWorkCorrectly() {
|
||||
|
||||
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
|
||||
|
||||
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_2, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
|
||||
nativeCommands.zadd(KEY_2, 3D, VALUE_3);
|
||||
|
||||
assertThat(connection.zSetCommands()
|
||||
.zUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block())
|
||||
.isEqualTo(3L);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-525
|
||||
void zRangeByLex() {
|
||||
|
||||
|
||||
@@ -559,6 +559,168 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2041
|
||||
void difference() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.difference(key, otherKey).as(StepVerifier::create).expectNext(onlyInKey).verifyComplete();
|
||||
|
||||
zSetOperations.differenceWithScores(key, otherKey).as(StepVerifier::create)
|
||||
.expectNext(new DefaultTypedTuple<>(onlyInKey, 10D)).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2041
|
||||
void differenceAndStore() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
K destKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.differenceAndStore(key, otherKey, destKey).as(StepVerifier::create).expectNext(1L).verifyComplete();
|
||||
|
||||
zSetOperations.range(destKey, ZERO_TO_FIVE).as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2042
|
||||
@EnabledOnCommand("ZINTER")
|
||||
void intersect() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.intersect(key, otherKey).as(StepVerifier::create).expectNext(shared).verifyComplete();
|
||||
|
||||
zSetOperations.intersectWithScores(key, otherKey).as(StepVerifier::create)
|
||||
.expectNext(new DefaultTypedTuple<>(shared, 22D)).verifyComplete();
|
||||
|
||||
zSetOperations.intersectWithScores(key, Collections.singleton(otherKey), Aggregate.SUM, Weights.of(1, 2))
|
||||
.as(StepVerifier::create).expectNext(new DefaultTypedTuple<>(shared, 33D)).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void intersectAndStore() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
K destKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, otherKey, destKey).as(StepVerifier::create).expectNext(1L).expectComplete()
|
||||
.verify();
|
||||
|
||||
zSetOperations.range(destKey, ZERO_TO_FIVE).as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-746
|
||||
void intersectAndStoreWithAggregation() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
K destKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, Collections.singletonList(otherKey), destKey, Aggregate.SUM)
|
||||
.as(StepVerifier::create).expectNext(1L).expectComplete().verify();
|
||||
|
||||
zSetOperations.score(destKey, shared).as(StepVerifier::create) //
|
||||
.expectNext(22d) //
|
||||
.verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, Collections.singletonList(otherKey), destKey, Aggregate.SUM, Weights.of(1, 2))
|
||||
.as(StepVerifier::create).expectNext(1L).expectComplete().verify();
|
||||
|
||||
zSetOperations.score(destKey, shared).as(StepVerifier::create) //
|
||||
.expectNext(33d) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2042
|
||||
@EnabledOnCommand("ZUNION")
|
||||
void union() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.union(key, otherKey).as(StepVerifier::create).expectNextCount(3).verifyComplete();
|
||||
|
||||
zSetOperations.unionWithScores(key, otherKey).collectList().as(StepVerifier::create).assertNext(actual -> {
|
||||
assertThat(actual).containsOnly(new DefaultTypedTuple<>(onlyInKey, 10D), new DefaultTypedTuple<>(shared, 22D),
|
||||
new DefaultTypedTuple<>(onlyInOtherKey, 10D));
|
||||
|
||||
}).verifyComplete();
|
||||
|
||||
zSetOperations.unionWithScores(key, Collections.singleton(otherKey), Aggregate.SUM, Weights.of(1, 2)).collectList()
|
||||
.as(StepVerifier::create).assertNext(actual -> {
|
||||
assertThat(actual).containsOnly(new DefaultTypedTuple<>(onlyInKey, 10D), new DefaultTypedTuple<>(shared, 33D),
|
||||
new DefaultTypedTuple<>(onlyInOtherKey, 20D));
|
||||
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void unionAndStore() {
|
||||
|
||||
@@ -607,64 +769,6 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
|
||||
zSetOperations.score(destKey, shared).as(StepVerifier::create).expectNext(33d).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void intersectAndStore() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
K destKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, otherKey, destKey).as(StepVerifier::create).expectNext(1L).expectComplete()
|
||||
.verify();
|
||||
|
||||
zSetOperations.range(destKey, ZERO_TO_FIVE).as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-746
|
||||
void intersectAndStoreWithAggregation() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K otherKey = keyFactory.instance();
|
||||
K destKey = keyFactory.instance();
|
||||
|
||||
V onlyInKey = valueFactory.instance();
|
||||
V shared = valueFactory.instance();
|
||||
V onlyInOtherKey = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, onlyInKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.add(otherKey, onlyInOtherKey, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(otherKey, shared, 11).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, Collections.singletonList(otherKey), destKey, Aggregate.SUM)
|
||||
.as(StepVerifier::create)
|
||||
.expectNext(1L).expectComplete().verify();
|
||||
|
||||
zSetOperations.score(destKey, shared).as(StepVerifier::create) //
|
||||
.expectNext(22d) //
|
||||
.verifyComplete();
|
||||
|
||||
zSetOperations.intersectAndStore(key, Collections.singletonList(otherKey), destKey, Aggregate.SUM, Weights.of(1, 2))
|
||||
.as(StepVerifier::create).expectNext(1L).expectComplete().verify();
|
||||
|
||||
zSetOperations.score(destKey, shared).as(StepVerifier::create) //
|
||||
.expectNext(33d) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void rangeByLex() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user