From f8c4200f10347a25c28a569877284452412a5582 Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Tue, 18 Aug 2020 02:59:53 +0200 Subject: [PATCH] Force integer for results of collection. Signed-off-by: Johno Crawford --- .../org/redisson/RedissonScoredSortedSet.java | 7 +++-- .../org/redisson/api/RScoredSortedSet.java | 2 +- .../redisson/api/RScoredSortedSetAsync.java | 2 +- .../api/RScoredSortedSetReactive.java | 2 +- .../org/redisson/api/RScoredSortedSetRx.java | 2 +- .../client/protocol/RedisCommands.java | 28 +++++++++++++------ .../redisson/RedissonScoredSortedSetTest.java | 6 ++-- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java index a5afb2045..04149f0f8 100644 --- a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -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 extends RedissonExpirable implements RSc } @Override - public Collection addAndGetAllRevRank(Map map) { + public Collection addAndGetAllRevRank(Map map) { return get(addAndGetAllRevRankAsync(map)); } @@ -218,7 +219,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc } @Override - public RFuture> addAndGetAllRevRankAsync(Map map) { + public RFuture> addAndGetAllRevRankAsync(Map map) { final List params = new ArrayList(map.size() * 2); for (java.util.Map.Entry t : map.entrySet()) { if (t.getKey() == null) { @@ -231,7 +232,7 @@ public class RedissonScoredSortedSet 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 " + diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java index a61032923..60fdcbb6a 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java @@ -305,7 +305,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 */ - Collection addAndGetAllRevRank(Map map); + Collection addAndGetAllRevRank(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 8313da0d3..6060ae2ec 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java @@ -264,7 +264,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> addAndGetAllRevRankAsync(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 c6626174c..ad795010c 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java @@ -287,7 +287,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> addAndGetAllRevRank(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 7f0903c1c..c890e5d7d 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java @@ -288,7 +288,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> addAndGetAllRevRank(Map map); /** * Adds element to this set only if has not been added before. diff --git a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java index 44825b3c1..cefccbff4 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -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 EVAL_VOID = new RedisStrictCommand("EVAL", new VoidReplayConvertor()); RedisCommand EVAL_FIRST_LIST = new RedisCommand("EVAL", new ListFirstObjectDecoder()); RedisCommand> EVAL_LIST = new RedisCommand>("EVAL", new ObjectListReplayDecoder()); + RedisCommand> EVAL_INT_LIST = new RedisCommand("EVAL", new ObjectListReplayDecoder(), new Convertor() { + private final Integer nullValue = null; + + @Override + public Integer convert(Object obj) { + if (obj == null) { + return nullValue; + } + return ((Long) obj).intValue(); + } + }); RedisCommand> EVAL_SET = new RedisCommand>("EVAL", new ObjectSetReplayDecoder()); RedisCommand EVAL_OBJECT = new RedisCommand("EVAL"); RedisCommand EVAL_MAP_VALUE = new RedisCommand("EVAL", ValueType.MAP_VALUE); diff --git a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index 40073763d..a9d8fa79c 100644 --- a/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -1283,12 +1283,12 @@ public class RedissonScoredSortedSetTest extends BaseTest { @Test public void testAddAndGetAllRevRank() throws InterruptedException { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); + RScoredSortedSet set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE); Map map = new LinkedHashMap<>(); map.put("alice", 10d); map.put("bob", 1d); - Collection res = set.addAndGetAllRevRank(map); - Assert.assertArrayEquals(new Long[]{0L, 1L}, res.toArray()); + Collection res = set.addAndGetAllRevRank(map); + Assert.assertArrayEquals(new Integer[]{0, 1}, res.toArray()); assertThat(set.revRank("alice")).isEqualTo(0); assertThat(set.revRank("bob")).isEqualTo(1);