zadd all elements then collect revrank.

Signed-off-by: Johno Crawford <johno.crawford@gmail.com>
pull/2982/head
Johno Crawford 5 years ago
parent e89969e0f8
commit 72c0ef0e19
No known key found for this signature in database
GPG Key ID: 747B819B88FCAB8A

@ -206,7 +206,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public Collection<Integer> addAndGetAllRevRank(Map<? extends V, Double> map) {
public List<Integer> addAndGetAllRevRank(Map<? extends V, Double> map) {
return get(addAndGetAllRevRankAsync(map));
}
@ -219,7 +219,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public RFuture<Collection<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map) {
public RFuture<List<Integer>> addAndGetAllRevRankAsync(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) {
@ -237,6 +237,10 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
"for i, v in ipairs(ARGV) do " +
"if i % 2 == 0 then " +
"redis.call('zadd', KEYS[1], ARGV[i], ARGV[i-1]); " +
"end; " +
"end;" +
"for i, v in ipairs(ARGV) do " +
"if i % 2 == 0 then " +
"r[#r+1] = redis.call('zrevrank', KEYS[1], ARGV[i-1]); " +
"end; " +
"end;" +

@ -300,11 +300,11 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
/**
* Adds elements to this set, overrides previous score if it has been already added.
* Finally returns reverse rank collection of the items
* Finally returns reverse rank list of the items
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
Collection<Integer> addAndGetAllRevRank(Map<? extends V, Double> map);
List<Integer> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -16,6 +16,7 @@
package org.redisson.api;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -260,11 +261,11 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
/**
* Adds elements to this set, overrides previous score if it has been already added.
* Finally returns reverse rank collection of the items
* Finally returns reverse rank list of the items
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
RFuture<Collection<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map);
RFuture<List<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -16,6 +16,7 @@
package org.redisson.api;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -283,11 +284,11 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
/**
* Adds elements to this set, overrides previous score if it has been already added.
* Finally returns reverse rank collection of the items
* Finally returns reverse rank list of the items
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
Mono<Collection<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
Mono<List<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -16,6 +16,7 @@
package org.redisson.api;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -284,11 +285,11 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
/**
* Adds elements to this set, overrides previous score if it has been already added.
* Finally returns reverse rank collection of the items
* Finally returns reverse rank list of the items
* @param map - map of object and scores, make sure to use an ordered map
* @return collection of reverse ranks
*/
Single<Collection<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
Single<List<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -1285,13 +1285,15 @@ public class RedissonScoredSortedSetTest extends BaseTest {
public void testAddAndGetAllRevRank() throws InterruptedException {
RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE);
Map<String, Double> map = new LinkedHashMap<>();
map.put("alice", 10d);
map.put("bob", 1d);
map.put("one", 1d);
map.put("three", 3d);
map.put("two", 2d);
Collection<Integer> res = set.addAndGetAllRevRank(map);
Assert.assertArrayEquals(new Integer[]{0, 1}, res.toArray());
Assert.assertArrayEquals(new Integer[]{2, 0, 1}, res.toArray());
assertThat(set.revRank("alice")).isEqualTo(0);
assertThat(set.revRank("bob")).isEqualTo(1);
assertThat(set.revRank("one")).isEqualTo(2);
assertThat(set.revRank("two")).isEqualTo(1);
assertThat(set.revRank("three")).isEqualTo(0);
}
@Test

Loading…
Cancel
Save