diff --git a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java index 2b2608e42..56d558fa9 100644 --- a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -206,8 +206,8 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } @Override - public List addAndGetAllRevRank(Map map) { - return get(addAndGetAllRevRankAsync(map)); + public List addAndGetRevRank(Map map) { + return get(addAndGetRevRankAsync(map)); } @Override @@ -219,7 +219,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } @Override - public RFuture> addAndGetAllRevRankAsync(Map map) { + public RFuture> addAndGetRevRankAsync(Map map) { final List params = new ArrayList(map.size() * 2); for (java.util.Map.Entry t : map.entrySet()) { if (t.getKey() == null) { @@ -409,8 +409,8 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } @Override - public List getAllScore(List keys) { - return get(getAllScoreAsync(keys)); + public List getScore(List keys) { + return get(getScoreAsync(keys)); } @Override @@ -419,7 +419,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } @Override - public RFuture> getAllScoreAsync(Collection elements) { + public RFuture> getScoreAsync(Collection elements) { return commandExecutor.evalReadAsync((String) null, DoubleCodec.INSTANCE, RedisCommands.EVAL_LIST, "local r = {} " + "for i, v in ipairs(ARGV) do " + @@ -751,6 +751,22 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc return get(revRankAsync(o)); } + @Override + public RFuture> revRankAsync(Collection elements) { + return commandExecutor.evalReadAsync((String) null, IntegerCodec.INSTANCE, RedisCommands.EVAL_INT_LIST, + "local r = {} " + + "for i, v in ipairs(ARGV) do " + + "r[#r+1] = redis.call('zrevrank', KEYS[1], ARGV[i]); " + + "end;" + + "return r;", + Collections.singletonList(getName()), encode(elements).toArray()); + } + + @Override + public List revRank(Collection elements) { + return get(revRankAsync(elements)); + } + @Override public int count(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) { return get(countAsync(startScore, startScoreInclusive, endScore, endScoreInclusive)); diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java index cec190009..155258f3a 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java @@ -255,6 +255,14 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< */ Integer revRank(V o); + /** + * Returns ranks of elements, with the scores ordered from high to low. + * + * @param elements - elements + * @return ranks or null if value does not exist + */ + List revRank(Collection elements); + /** * Returns score of element or null if it doesn't exist. * @@ -269,7 +277,7 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< * @param elements - elements * @return element scores */ - List getAllScore(List elements); + List getScore(List elements); /** * Adds element to this set, overrides previous score if it has been already added. @@ -304,7 +312,7 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< * @param map - map of object and scores, make sure to use an ordered map * @return collection of reverse ranks */ - List addAndGetAllRevRank(Map map); + List addAndGetRevRank(Map map); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java index 2ae10eb1a..e097f96a0 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java @@ -216,6 +216,14 @@ public interface RScoredSortedSetAsync extends RExpirableAsync, RSortableAsyn */ RFuture revRankAsync(V o); + /** + * Returns ranks of elements, with the scores ordered from high to low. + * + * @param elements - elements + * @return ranks or null if value does not exist + */ + RFuture> revRankAsync(Collection elements); + /** * Returns score of element or null if it doesn't exist. * @@ -230,7 +238,7 @@ public interface RScoredSortedSetAsync extends RExpirableAsync, RSortableAsyn * @param elements - elements * @return element scores */ - RFuture> getAllScoreAsync(Collection elements); + RFuture> getScoreAsync(Collection elements); /** * Adds element to this set, overrides previous score if it has been already added. @@ -265,7 +273,7 @@ public interface RScoredSortedSetAsync extends RExpirableAsync, RSortableAsyn * @param map - map of object and scores, make sure to use an ordered map * @return collection of reverse ranks */ - RFuture> addAndGetAllRevRankAsync(Map map); + RFuture> addAndGetRevRankAsync(Map map); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java index 4bea58935..f9e6cba7d 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java @@ -228,6 +228,14 @@ public interface RScoredSortedSetReactive extends RExpirableReactive, RSortab */ Mono revRank(V o); + /** + * Returns ranks of elements, with the scores ordered from high to low. + * + * @param elements - elements + * @return ranks or null if value does not exist + */ + Mono> revRankAsync(Collection elements); + /** * Returns score of element or null if it doesn't exist. * @@ -242,7 +250,7 @@ public interface RScoredSortedSetReactive extends RExpirableReactive, RSortab * @param elements - elements * @return element scores */ - Mono> getAllScore(Collection elements); + Mono> getScore(Collection elements); /** * Adds element to this set, overrides previous score if it has been already added. @@ -288,7 +296,7 @@ public interface RScoredSortedSetReactive extends RExpirableReactive, RSortab * @param map - map of object and scores, make sure to use an ordered map * @return collection of reverse ranks */ - Mono> addAndGetAllRevRank(Map map); + Mono> addAndGetRevRank(Map map); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java index a4d999cdb..46bbe459e 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java @@ -229,6 +229,14 @@ public interface RScoredSortedSetRx extends RExpirableRx, RSortableRx> */ Maybe revRank(V o); + /** + * Returns ranks of elements, with the scores ordered from high to low. + * + * @param elements - elements + * @return ranks or null if value does not exist + */ + Single> revRank(Collection elements); + /** * Returns score of element or null if it doesn't exist. * @@ -243,7 +251,7 @@ public interface RScoredSortedSetRx extends RExpirableRx, RSortableRx> * @param elements - elements * @return element scores */ - Single> getAllScore(Collection elements); + Single> getScore(Collection elements); /** * Adds element to this set, overrides previous score if it has been already added. @@ -289,7 +297,7 @@ public interface RScoredSortedSetRx extends RExpirableRx, RSortableRx> * @param map - map of object and scores, make sure to use an ordered map * @return collection of reverse ranks */ - Single> addAndGetAllRevRank(Map map); + Single> addAndGetRevRank(Map map); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index 00ab7b4ac..5e2c9897f 100644 --- a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -595,6 +595,7 @@ public class RedissonScoredSortedSetTest extends BaseTest { set.add(0.7, "g"); assertThat(set.revRank("d")).isEqualTo(3); + assertThat(set.revRank(Arrays.asList("d", "a", "g", "abc", "f"))).isEqualTo(Arrays.asList(3, 6, 0, null, 1)); assertThat(set.rank("abc")).isNull(); } @@ -1238,7 +1239,7 @@ public class RedissonScoredSortedSetTest extends BaseTest { res2 = set.getScore("1"); Assert.assertTrue(new Double(112.3).compareTo(res2) == 0); - Collection res = set.getAllScore(Arrays.asList("1", "42", "100")); + Collection res = set.getScore(Arrays.asList("1", "42", "100")); Assert.assertArrayEquals(new Double[] {112.3d, null, null}, res.toArray()); } @@ -1282,13 +1283,13 @@ public class RedissonScoredSortedSetTest extends BaseTest { } @Test - public void testAddAndGetAllRevRank() throws InterruptedException { + public void testAddAndGetRevRankCollection() throws InterruptedException { RScoredSortedSet set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE); Map map = new LinkedHashMap<>(); map.put("one", 1d); map.put("three", 3d); map.put("two", 2d); - Collection res = set.addAndGetAllRevRank(map); + Collection res = set.addAndGetRevRank(map); Assert.assertArrayEquals(new Integer[]{2, 0, 1}, res.toArray()); assertThat(set.revRank("one")).isEqualTo(2);