Force integer for results of collection.

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

@ -23,6 +23,7 @@ import org.redisson.api.mapreduce.RCollectionMapReduce;
import org.redisson.client.RedisClient;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.codec.IntegerCodec;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand;
@ -205,7 +206,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public Collection<Long> addAndGetAllRevRank(Map<? extends V, Double> map) {
public Collection<Integer> addAndGetAllRevRank(Map<? extends V, Double> map) {
return get(addAndGetAllRevRankAsync(map));
}
@ -218,7 +219,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
@Override
public RFuture<Collection<Long>> addAndGetAllRevRankAsync(Map<? extends V, Double> map) {
public RFuture<Collection<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) {
@ -231,7 +232,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
params.add(BigDecimal.valueOf(t.getValue()).toPlainString());
}
return commandExecutor.evalReadAsync((String) null, LongCodec.INSTANCE, RedisCommands.EVAL_LIST,
return commandExecutor.evalReadAsync((String) null, IntegerCodec.INSTANCE, RedisCommands.EVAL_INT_LIST,
"local r = {} " +
"for i, v in ipairs(ARGV) do " +
"if i % 2 == 0 then " +

@ -305,7 +305,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
*/
Collection<Long> addAndGetAllRevRank(Map<? extends V, Double> map);
Collection<Integer> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -264,7 +264,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<Collection<Long>> addAndGetAllRevRankAsync(Map<? extends V, Double> map);
RFuture<Collection<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -287,7 +287,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<Collection<Long>> addAndGetAllRevRank(Map<? extends V, Double> map);
Mono<Collection<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -288,7 +288,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<Collection<Long>> addAndGetAllRevRank(Map<? extends V, Double> map);
Single<Collection<Integer>> addAndGetAllRevRank(Map<? extends V, Double> map);
/**
* Adds element to this set only if has not been added before.

@ -15,14 +15,6 @@
*/
package org.redisson.client.protocol;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.redisson.api.RType;
import org.redisson.api.StreamInfo;
import org.redisson.api.StreamMessageId;
@ -35,6 +27,7 @@ import org.redisson.client.protocol.convertor.BooleanNullReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNullSafeReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNumberReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.convertor.Convertor;
import org.redisson.client.protocol.convertor.DoubleNullSafeReplayConvertor;
import org.redisson.client.protocol.convertor.DoubleReplayConvertor;
import org.redisson.client.protocol.convertor.IntegerReplayConvertor;
@ -49,6 +42,14 @@ import org.redisson.client.protocol.decoder.*;
import org.redisson.client.protocol.pubsub.PubSubStatusDecoder;
import org.redisson.cluster.ClusterNodeInfo;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
*
* @author Nikita Koksharov
@ -225,6 +226,17 @@ public interface RedisCommands {
RedisStrictCommand<Void> EVAL_VOID = new RedisStrictCommand<Void>("EVAL", new VoidReplayConvertor());
RedisCommand<Object> EVAL_FIRST_LIST = new RedisCommand<Object>("EVAL", new ListFirstObjectDecoder());
RedisCommand<List<Object>> EVAL_LIST = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder<Object>());
RedisCommand<List<Integer>> EVAL_INT_LIST = new RedisCommand("EVAL", new ObjectListReplayDecoder<Integer>(), new Convertor<Integer>() {
private final Integer nullValue = null;
@Override
public Integer convert(Object obj) {
if (obj == null) {
return nullValue;
}
return ((Long) obj).intValue();
}
});
RedisCommand<Set<Object>> EVAL_SET = new RedisCommand<Set<Object>>("EVAL", new ObjectSetReplayDecoder<Object>());
RedisCommand<Object> EVAL_OBJECT = new RedisCommand<Object>("EVAL");
RedisCommand<Object> EVAL_MAP_VALUE = new RedisCommand<Object>("EVAL", ValueType.MAP_VALUE);

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

Loading…
Cancel
Save