diff --git a/src/main/java/org/redisson/RedissonScoredSortedSet.java b/src/main/java/org/redisson/RedissonScoredSortedSet.java index 8f5a5902d..1588fb381 100644 --- a/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -411,6 +411,21 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE, getName(), startValue, endValue); } + @Override + public Collection valueRangeReversed(double startScore, boolean startScoreInclusive, double endScore, + boolean endScoreInclusive) { + return get(valueRangeReversedAsync(startScore, startScoreInclusive, endScore, endScoreInclusive)); + } + + @Override + public Future> valueRangeReversedAsync(double startScore, boolean startScoreInclusive, double endScore, + boolean endScoreInclusive) { + String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive); + String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZREVRANGEBYSCORE, getName(), endValue, startValue); + } + + @Override public Collection> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) { return get(entryRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive)); @@ -435,6 +450,18 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE, getName(), startValue, endValue, "LIMIT", offset, count); } + @Override + public Collection valueRangeReversed(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) { + return get(valueRangeReversedAsync(startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count)); + } + + @Override + public Future> valueRangeReversedAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) { + String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive); + String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZREVRANGEBYSCORE, getName(), endValue, startValue, "LIMIT", offset, count); + } + @Override public Collection> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) { return get(entryRangeAsync(startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count)); diff --git a/src/main/java/org/redisson/client/protocol/RedisCommands.java b/src/main/java/org/redisson/client/protocol/RedisCommands.java index 36893e64b..5efc7df00 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -91,6 +91,7 @@ public interface RedisCommands { RedisStrictCommand ZREMRANGEBYLEX = new RedisStrictCommand("ZREMRANGEBYLEX", new IntegerReplayConvertor()); RedisCommand> ZRANGEBYLEX = new RedisCommand>("ZRANGEBYLEX", new ObjectListReplayDecoder()); RedisCommand> ZRANGEBYSCORE = new RedisCommand>("ZRANGEBYSCORE", new ObjectListReplayDecoder()); + RedisCommand> ZREVRANGEBYSCORE = new RedisCommand>("ZREVRANGEBYSCORE", new ObjectListReplayDecoder()); RedisCommand>> ZRANGE_ENTRY = new RedisCommand>>("ZRANGE", new ScoredSortedSetReplayDecoder()); RedisCommand>> ZRANGEBYSCORE_ENTRY = new RedisCommand>>("ZRANGEBYSCORE", new ScoredSortedSetReplayDecoder()); RedisCommand> ZSCAN = new RedisCommand>("ZSCAN", new NestedMultiDecoder(new ScoredSortedSetScanDecoder(), new ScoredSortedSetScanReplayDecoder()), ValueType.OBJECT); diff --git a/src/main/java/org/redisson/core/RScoredSortedSet.java b/src/main/java/org/redisson/core/RScoredSortedSet.java index bf37e97cb..ddaeef9b9 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSet.java +++ b/src/main/java/org/redisson/core/RScoredSortedSet.java @@ -88,10 +88,14 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< Collection valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); + Collection valueRangeReversed(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); + Collection> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); Collection valueRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); + Collection valueRangeReversed(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); + Collection> entryRange(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); } diff --git a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java index e49857952..fe6ea081a 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java +++ b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java @@ -82,10 +82,14 @@ public interface RScoredSortedSetAsync extends RExpirableAsync { Future> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); + Future> valueRangeReversedAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); + Future>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive); Future> valueRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); + Future> valueRangeReversedAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); + Future>> entryRangeAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count); } diff --git a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index 9996ebb01..e5290ac8e 100644 --- a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -508,8 +508,8 @@ public class RedissonScoredSortedSetTest extends BaseTest { } @Test - public void testScoredSortedSetValueRange() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + public void testScoredSortedSetValueRangeLimit() { + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); set.add(0, "a"); set.add(1, "b"); @@ -518,13 +518,54 @@ public class RedissonScoredSortedSetTest extends BaseTest { set.add(4, "e"); Collection r = set.valueRange(1, true, 4, false, 1, 2); - String[] a = r.toArray(new String[0]); - Assert.assertArrayEquals(new String[]{"c", "d"}, a); + assertThat(r).containsExactly("c", "d"); + } + + @Test + public void testScoredSortedSetValueRange() { + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + + set.add(0, "a"); + set.add(1, "b"); + set.add(2, "c"); + set.add(3, "d"); + set.add(4, "e"); + + Collection r = set.valueRange(1, true, 4, false); + assertThat(r).containsExactly("b", "c", "d"); + } + + @Test + public void testScoredSortedSetValueRangeReversedLimit() { + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + + set.add(0, "a"); + set.add(1, "b"); + set.add(2, "c"); + set.add(3, "d"); + set.add(4, "e"); + + Collection r = set.valueRangeReversed(1, true, 4, false, 1, 2); + assertThat(r).containsExactly("c", "b"); + } + + @Test + public void testScoredSortedSetValueRangeReversed() { + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + + set.add(0, "a"); + set.add(1, "b"); + set.add(2, "c"); + set.add(3, "d"); + set.add(4, "e"); + + Collection r = set.valueRangeReversed(1, true, 4, false); + assertThat(r).containsExactly("d", "c", "b"); } @Test public void testScoredSortedSetEntryRange() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); set.add(0, "a"); set.add(1, "b");