From 2ca0f2d00853a50b9717648d62e8ebfa921779d4 Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 17 Mar 2016 18:12:44 +0300 Subject: [PATCH] revRank and revRankAsync methods added. #433 --- .../org/redisson/RedissonScoredSortedSet.java | 10 ++++++++++ .../redisson/client/protocol/RedisCommands.java | 1 + .../java/org/redisson/core/RScoredSortedSet.java | 2 ++ .../org/redisson/core/RScoredSortedSetAsync.java | 2 ++ .../org/redisson/RedissonScoredSortedSetTest.java | 15 +++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/src/main/java/org/redisson/RedissonScoredSortedSet.java b/src/main/java/org/redisson/RedissonScoredSortedSet.java index e6751cc78..e4755f679 100644 --- a/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -480,4 +480,14 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGEBYSCORE_ENTRY, getName(), startValue, endValue, "WITHSCORES", "LIMIT", offset, count); } + @Override + public Future revRankAsync(V o) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZREVRANK_INT, getName(), o); + } + + @Override + public int revRank(V o) { + return get(revRankAsync(o)); + } + } diff --git a/src/main/java/org/redisson/client/protocol/RedisCommands.java b/src/main/java/org/redisson/client/protocol/RedisCommands.java index f4b741800..7d62ca62e 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -83,6 +83,7 @@ public interface RedisCommands { RedisCommand ZSCORE_CONTAINS = new RedisCommand("ZSCORE", new BooleanNotNullReplayConvertor(), 2); RedisStrictCommand ZSCORE = new RedisStrictCommand("ZSCORE", new DoubleReplayConvertor(), 2); RedisCommand ZRANK_INT = new RedisCommand("ZRANK", new IntegerReplayConvertor(), 2); + RedisCommand ZREVRANK_INT = new RedisCommand("ZREVRANK", new IntegerReplayConvertor(), 2); RedisStrictCommand ZRANK = new RedisStrictCommand("ZRANK", 2); RedisCommand ZRANGE_SINGLE = new RedisCommand("ZRANGE", new ObjectFirstResultReplayDecoder()); RedisCommand> ZRANGE = new RedisCommand>("ZRANGE", new ObjectListReplayDecoder()); diff --git a/src/main/java/org/redisson/core/RScoredSortedSet.java b/src/main/java/org/redisson/core/RScoredSortedSet.java index ddaeef9b9..ce4e6fccf 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSet.java +++ b/src/main/java/org/redisson/core/RScoredSortedSet.java @@ -37,6 +37,8 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< int removeRangeByRank(int startIndex, int endIndex); int rank(V o); + + int revRank(V o); Double getScore(V o); diff --git a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java index fe6ea081a..83e41798e 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java +++ b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java @@ -39,6 +39,8 @@ public interface RScoredSortedSetAsync extends RExpirableAsync { Future removeRangeByRankAsync(int startIndex, int endIndex); Future rankAsync(V o); + + Future revRankAsync(V o); Future getScoreAsync(V o); diff --git a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index 8da3dacd0..3aeab3d72 100644 --- a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -161,6 +161,21 @@ public class RedissonScoredSortedSetTest extends BaseTest { Assert.assertEquals(3, (int)set.rank("d")); } + + @Test + public void testRevRank() { + RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + set.add(0.1, "a"); + set.add(0.2, "b"); + set.add(0.3, "c"); + set.add(0.4, "d"); + set.add(0.5, "e"); + set.add(0.6, "f"); + set.add(0.7, "g"); + + Assert.assertEquals(1, (int)set.revRank("f")); + } + @Test public void testAddAsync() throws InterruptedException, ExecutionException {