Add support for ZMSCORE through score(key, values).
We now support Redis 6.2 ZMSCORE through the Template API and on the connection level for all drivers. Closes #2038 Original Pull Request: #2088
This commit is contained in:
committed by
Christoph Strobl
parent
c878a933f5
commit
8c743d40ef
@@ -2054,6 +2054,16 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
verifyResults(Arrays.asList(new Object[] { true, true, true, 3d }));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnCommand("ZMSCORE")
|
||||
void testZMScore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
actual.add(connection.zAdd("myset", 1, "James"));
|
||||
actual.add(connection.zAdd("myset", 3, "Joe"));
|
||||
actual.add(connection.zMScore("myset", "James", "Joe"));
|
||||
verifyResults(Arrays.asList(new Object[] { true, true, true, Arrays.asList(1d, 3d) }));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testZUnionStore() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
|
||||
@@ -670,6 +670,9 @@ public interface ClusterConnectionTests {
|
||||
// DATAREDIS-315
|
||||
void zScoreShouldRetrieveScoreForValue();
|
||||
|
||||
// GH-2038
|
||||
void zMScoreShouldRetrieveScoreForValues();
|
||||
|
||||
// DATAREDIS-315
|
||||
void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots();
|
||||
|
||||
|
||||
@@ -1330,6 +1330,12 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
|
||||
super.testZScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZMScore() {
|
||||
doReturn(Collections.singletonList(Arrays.asList(1d, 3d))).when(nativeConnection).closePipeline();
|
||||
super.testZMScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStoreAggWeightsBytes() {
|
||||
doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline();
|
||||
|
||||
@@ -1433,6 +1433,13 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
||||
super.testZScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZMScore() {
|
||||
doReturn(Collections.singletonList(Collections.singletonList(Arrays.asList(1d, 3d)))).when(nativeConnection)
|
||||
.closePipeline();
|
||||
super.testZMScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStoreAggWeightsBytes() {
|
||||
doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline();
|
||||
|
||||
@@ -1624,6 +1624,13 @@ public class DefaultStringRedisConnectionTests {
|
||||
verifyResults(Collections.singletonList(3d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZMScore() {
|
||||
doReturn(Arrays.asList(1d, 3d)).when(nativeConnection).zMScore(fooBytes, barBytes, bar2Bytes);
|
||||
actual.add(connection.zMScore(foo, bar, bar2));
|
||||
verifyResults(Collections.singletonList(Arrays.asList(1d, 3d)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStoreAggWeightsBytes() {
|
||||
doReturn(5L).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes));
|
||||
|
||||
@@ -1316,6 +1316,12 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
||||
super.testZScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZMScore() {
|
||||
doReturn(Collections.singletonList(Arrays.asList(1d, 3d))).when(nativeConnection).exec();
|
||||
super.testZMScore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZUnionStoreAggWeightsBytes() {
|
||||
doReturn(Collections.singletonList(5L)).when(nativeConnection).exec();
|
||||
|
||||
@@ -833,6 +833,10 @@ class RedisConnectionUnitTests {
|
||||
return delegate.zScore(key, value);
|
||||
}
|
||||
|
||||
public List<Double> zMScore(byte[] key, byte[][] values) {
|
||||
return delegate.zMScore(key, values);
|
||||
}
|
||||
|
||||
public Long zRemRange(byte[] key, long begin, long end) {
|
||||
return delegate.zRemRange(key, begin, end);
|
||||
}
|
||||
|
||||
@@ -2304,6 +2304,16 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES)).isEqualTo(20D);
|
||||
}
|
||||
|
||||
@Test // GH-2038
|
||||
@EnabledOnCommand("ZMSCORE")
|
||||
public void zMScoreShouldRetrieveScoreForValues() {
|
||||
|
||||
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
|
||||
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
|
||||
|
||||
assertThat(clusterConnection.zMScore(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES)).containsSequence(10D, 20D);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
|
||||
assertThatExceptionOfType(DataAccessException.class)
|
||||
|
||||
@@ -2345,6 +2345,16 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES)).isEqualTo(20D);
|
||||
}
|
||||
|
||||
@Test // GH-2038
|
||||
@EnabledOnCommand("ZMSCORE")
|
||||
public void zMScoreShouldRetrieveScoreForValues() {
|
||||
|
||||
nativeConnection.zadd(KEY_1, 10D, VALUE_1);
|
||||
nativeConnection.zadd(KEY_1, 20D, VALUE_2);
|
||||
|
||||
assertThat(clusterConnection.zMScore(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES)).containsExactly(10D, 20D);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
|
||||
assertThatExceptionOfType(DataAccessException.class)
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Arrays;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnCommand;
|
||||
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
|
||||
|
||||
/**
|
||||
@@ -402,6 +403,17 @@ public class LettuceReactiveZSetCommandsIntegrationTests extends LettuceReactive
|
||||
assertThat(connection.zSetCommands().zScore(KEY_1_BBUFFER, VALUE_2_BBUFFER).block()).isEqualTo(2D);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2038
|
||||
@EnabledOnCommand("ZMSCORE")
|
||||
void zMScoreShouldReturnScoreCorrectly() {
|
||||
|
||||
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
|
||||
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
|
||||
|
||||
connection.zSetCommands().zMScore(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER))
|
||||
.as(StepVerifier::create).expectNext(Arrays.asList(1D, 2D)).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-525
|
||||
void zRemRangeByRankShouldRemoveValuesCorrectly() {
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnCommand;
|
||||
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
|
||||
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
|
||||
|
||||
@@ -460,6 +461,21 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
|
||||
zSetOperations.score(key, value2).as(StepVerifier::create).expectNext(10d).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2038
|
||||
@EnabledOnCommand("ZMSCORE")
|
||||
void scores() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
|
||||
zSetOperations.add(key, value1, 42.1).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
zSetOperations.add(key, value2, 10).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
|
||||
zSetOperations.score(key, value1, value2, valueFactory.instance()).as(StepVerifier::create)
|
||||
.expectNext(Arrays.asList(42.1d, 10d, null)).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void removeRange() {
|
||||
|
||||
|
||||
@@ -339,6 +339,21 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
|
||||
assertThat(zSetOps.range(key, 0, -1)).containsOnly(value2);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest
|
||||
void testScore() {
|
||||
|
||||
K key = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
V value3 = valueFactory.instance();
|
||||
|
||||
zSetOps.add(key, value1, 1.9);
|
||||
zSetOps.add(key, value2, 3.7);
|
||||
zSetOps.add(key, value3, 5.8);
|
||||
|
||||
assertThat(zSetOps.score(key, value1, value2, valueFactory.instance())).containsExactly(1.9d, 3.7d, null);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest
|
||||
void zCardRetrievesDataCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user