Merge pull request #2999 from sulake/feature/revrank_batch

Add batch support for revRank.
pull/3000/head
Nikita Koksharov 5 years ago committed by GitHub
commit 8f3818bd6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -206,8 +206,8 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public List<Integer> addAndGetAllRevRank(Map<? extends V, Double> map) {
return get(addAndGetAllRevRankAsync(map));
public List<Integer> addAndGetRevRank(Map<? extends V, Double> map) {
return get(addAndGetRevRankAsync(map));
}
@Override
@ -219,7 +219,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public RFuture<List<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map) {
public RFuture<List<Integer>> addAndGetRevRankAsync(Map<? extends V, Double> map) {
final List<Object> params = new ArrayList<Object>(map.size() * 2);
for (java.util.Map.Entry<? extends V, Double> t : map.entrySet()) {
if (t.getKey() == null) {
@ -409,8 +409,8 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public List<Double> getAllScore(List<V> keys) {
return get(getAllScoreAsync(keys));
public List<Double> getScore(List<V> keys) {
return get(getScoreAsync(keys));
}
@Override
@ -419,7 +419,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public RFuture<List<Double>> getAllScoreAsync(Collection<V> elements) {
public RFuture<List<Double>> getScoreAsync(Collection<V> 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<V> extends RedissonExpirable implements RSc
return get(revRankAsync(o));
}
@Override
public RFuture<List<Integer>> revRankAsync(Collection<V> 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<Integer> revRank(Collection<V> elements) {
return get(revRankAsync(elements));
}
@Override
public int count(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
return get(countAsync(startScore, startScoreInclusive, endScore, endScoreInclusive));

@ -255,6 +255,14 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
*/
Integer revRank(V o);
/**
* Returns ranks of elements, with the scores ordered from high to low.
*
* @param elements - elements
* @return ranks or <code>null</code> if value does not exist
*/
List<Integer> revRank(Collection<V> elements);
/**
* Returns score of element or <code>null</code> if it doesn't exist.
*
@ -269,7 +277,7 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
* @param elements - elements
* @return element scores
*/
List<Double> getAllScore(List<V> elements);
List<Double> getScore(List<V> elements);
/**
* Adds element to this set, overrides previous score if it has been already added.
@ -304,7 +312,7 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
List<Integer> addAndGetAllRevRank(Map<? extends V, Double> map);
List<Integer> addAndGetRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -216,6 +216,14 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
*/
RFuture<Integer> revRankAsync(V o);
/**
* Returns ranks of elements, with the scores ordered from high to low.
*
* @param elements - elements
* @return ranks or <code>null</code> if value does not exist
*/
RFuture<List<Integer>> revRankAsync(Collection<V> elements);
/**
* Returns score of element or <code>null</code> if it doesn't exist.
*
@ -230,7 +238,7 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
* @param elements - elements
* @return element scores
*/
RFuture<List<Double>> getAllScoreAsync(Collection<V> elements);
RFuture<List<Double>> getScoreAsync(Collection<V> elements);
/**
* Adds element to this set, overrides previous score if it has been already added.
@ -265,7 +273,7 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
RFuture<List<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map);
RFuture<List<Integer>> addAndGetRevRankAsync(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -228,6 +228,14 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
*/
Mono<Integer> revRank(V o);
/**
* Returns ranks of elements, with the scores ordered from high to low.
*
* @param elements - elements
* @return ranks or <code>null</code> if value does not exist
*/
Mono<List<Integer>> revRankAsync(Collection<V> elements);
/**
* Returns score of element or <code>null</code> if it doesn't exist.
*
@ -242,7 +250,7 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
* @param elements - elements
* @return element scores
*/
Mono<List<Double>> getAllScore(Collection<V> elements);
Mono<List<Double>> getScore(Collection<V> elements);
/**
* Adds element to this set, overrides previous score if it has been already added.
@ -288,7 +296,7 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
Mono<List<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
Mono<List<Integer>> addAndGetRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -229,6 +229,14 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
*/
Maybe<Integer> revRank(V o);
/**
* Returns ranks of elements, with the scores ordered from high to low.
*
* @param elements - elements
* @return ranks or <code>null</code> if value does not exist
*/
Single<List<Integer>> revRank(Collection<V> elements);
/**
* Returns score of element or <code>null</code> if it doesn't exist.
*
@ -243,7 +251,7 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
* @param elements - elements
* @return element scores
*/
Single<List<Double>> getAllScore(Collection<V> elements);
Single<List<Double>> getScore(Collection<V> elements);
/**
* Adds element to this set, overrides previous score if it has been already added.
@ -289,7 +297,7 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
Single<List<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
Single<List<Integer>> addAndGetRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -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<Double> res = set.getAllScore(Arrays.asList("1", "42", "100"));
Collection<Double> 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<String> set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE);
Map<String, Double> map = new LinkedHashMap<>();
map.put("one", 1d);
map.put("three", 3d);
map.put("two", 2d);
Collection<Integer> res = set.addAndGetAllRevRank(map);
Collection<Integer> res = set.addAndGetRevRank(map);
Assert.assertArrayEquals(new Integer[]{2, 0, 1}, res.toArray());
assertThat(set.revRank("one")).isEqualTo(2);

Loading…
Cancel
Save