From 4dd5a7a4fa32bc5097ff0acf4e681877e5efd454 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 15 Mar 2021 17:28:19 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20JedisClusterZSetCommands.reverseRangeByLe?= =?UTF-8?q?x(=E2=80=A6)=20parameter=20order.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit max/min parameter are now used in the correct order. Closes #1998 --- .../jedis/JedisClusterZSetCommands.java | 4 +- .../jedis/JedisClusterConnectionTests.java | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java index 376f7c8b4..53df37898 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java @@ -384,9 +384,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands { try { if (limit.isUnlimited()) { - return connection.getCluster().zrevrangeByLex(key, min, max); + return connection.getCluster().zrevrangeByLex(key, max, min); } - return connection.getCluster().zrevrangeByLex(key, min, max, limit.getOffset(), limit.getCount()); + return connection.getCluster().zrevrangeByLex(key, max, min, limit.getOffset(), limit.getCount()); } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 7029daaa1..e64c4754f 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -23,9 +23,9 @@ import static org.springframework.data.redis.connection.BitFieldSubCommands.BitF import static org.springframework.data.redis.connection.ClusterTestVariables.*; import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*; import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*; +import static org.springframework.data.redis.connection.RedisZSetCommands.*; import static org.springframework.data.redis.core.ScanOptions.*; -import org.springframework.data.redis.test.condition.EnabledOnCommand; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; @@ -63,14 +63,13 @@ import org.springframework.data.redis.connection.RedisListCommands.Position; import org.springframework.data.redis.connection.RedisNode; import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; import org.springframework.data.redis.connection.RedisStringCommands.SetOption; -import org.springframework.data.redis.connection.RedisZSetCommands.Range; -import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; import org.springframework.data.redis.connection.ReturnType; import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.script.DigestUtils; import org.springframework.data.redis.core.types.Expiration; +import org.springframework.data.redis.test.condition.EnabledOnCommand; import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable; import org.springframework.data.redis.test.extension.JedisExtension; import org.springframework.data.redis.test.util.HexStringUtils; @@ -2041,6 +2040,40 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { JedisConverters.toBytes("c"), JedisConverters.toBytes("d")); } + @Test // GH-1998 + public void zRevRangeByLexShouldReturnValuesCorrectly() { + + nativeConnection.zadd(KEY_1, 0, "a"); + nativeConnection.zadd(KEY_1, 0, "b"); + nativeConnection.zadd(KEY_1, 0, "c"); + nativeConnection.zadd(KEY_1, 0, "d"); + nativeConnection.zadd(KEY_1, 0, "e"); + nativeConnection.zadd(KEY_1, 0, "f"); + nativeConnection.zadd(KEY_1, 0, "g"); + + Set values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("c")); + + assertThat(values).containsExactly(JedisConverters.toBytes("c"), JedisConverters.toBytes("b"), + JedisConverters.toBytes("a")); + assertThat(values).doesNotContain(JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), + JedisConverters.toBytes("f"), JedisConverters.toBytes("g")); + + values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lt("c")); + assertThat(values).containsExactly(JedisConverters.toBytes("b"), JedisConverters.toBytes("a")); + assertThat(values).doesNotContain(JedisConverters.toBytes("c")); + + values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g")); + assertThat(values).containsExactly(JedisConverters.toBytes("f"), JedisConverters.toBytes("e"), + JedisConverters.toBytes("d"), JedisConverters.toBytes("c"), JedisConverters.toBytes("b")); + assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("g")); + + values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("d"), Limit.limit().count(2).offset(1)); + + assertThat(values).hasSize(2).containsExactly(JedisConverters.toBytes("c"), JedisConverters.toBytes("b")); + assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("d"), + JedisConverters.toBytes("e"), JedisConverters.toBytes("f"), JedisConverters.toBytes("g")); + } + @Test // DATAREDIS-315 public void zRangeByScoreShouldReturnValuesCorrectly() {