Fixed wrong object encoding during RedissonScoredSortedSet.addScore usage. #594

pull/605/head
Nikita 9 years ago
parent 29c17dbb61
commit 1cf00d2da2

@ -30,8 +30,8 @@ import java.util.Map.Entry;
import org.redisson.api.RFuture;
import org.redisson.api.RScoredSortedSet;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.codec.ScoredCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands;
@ -357,8 +357,8 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
@Override
public RFuture<Double> addScoreAsync(V object, Number value) {
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZINCRBY,
getName(), new BigDecimal(value.toString()).toPlainString(), object);
return commandExecutor.writeAsync(getName(), DoubleCodec.INSTANCE, RedisCommands.ZINCRBY,
getName(), new BigDecimal(value.toString()).toPlainString(), encode(object));
}
@Override

@ -113,7 +113,7 @@ public interface RedisCommands {
RedisCommand<List<ScoredEntry<Object>>> ZRANGE_ENTRY = new RedisCommand<List<ScoredEntry<Object>>>("ZRANGE", new ScoredSortedSetReplayDecoder<Object>());
RedisCommand<List<ScoredEntry<Object>>> ZRANGEBYSCORE_ENTRY = new RedisCommand<List<ScoredEntry<Object>>>("ZRANGEBYSCORE", new ScoredSortedSetReplayDecoder<Object>());
RedisCommand<ListScanResult<Object>> ZSCAN = new RedisCommand<ListScanResult<Object>>("ZSCAN", new NestedMultiDecoder(new ScoredSortedSetScanDecoder<Object>(), new ScoredSortedSetScanReplayDecoder()), ValueType.OBJECT);
RedisStrictCommand<Double> ZINCRBY = new RedisStrictCommand<Double>("ZINCRBY", new DoubleReplayConvertor(), 4);
RedisStrictCommand<Double> ZINCRBY = new RedisStrictCommand<Double>("ZINCRBY", new DoubleReplayConvertor());
RedisCommand<ListScanResult<String>> SCAN = new RedisCommand<ListScanResult<String>>("SCAN", new NestedMultiDecoder(new ObjectListReplayDecoder<String>(), new ListScanResultReplayDecoder()), ValueType.OBJECT);
RedisStrictCommand<String> RANDOM_KEY = new RedisStrictCommand<String>("RANDOMKEY", new StringDataDecoder());

@ -20,7 +20,6 @@ import org.redisson.api.RFuture;
import org.redisson.api.RLexSortedSet;
import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RSortedSet;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.ScoredEntry;
public class RedissonScoredSortedSetTest extends BaseTest {
@ -735,23 +734,23 @@ public class RedissonScoredSortedSetTest extends BaseTest {
Assert.assertEquals("c", a[0].getValue());
Assert.assertEquals("d", a[1].getValue());
}
@Test
public void testAddAndGet() throws InterruptedException {
RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE);
set.add(1, 100);
RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
set.add(1, "100");
Double res = set.addScore(100, 11);
Double res = set.addScore("100", 11);
Assert.assertEquals(12, (double)res, 0);
Double score = set.getScore(100);
Double score = set.getScore("100");
Assert.assertEquals(12, (double)score, 0);
RScoredSortedSet<Integer> set2 = redisson.getScoredSortedSet("simple", StringCodec.INSTANCE);
set2.add(100.2, 1);
RScoredSortedSet<String> set2 = redisson.getScoredSortedSet("simple");
set2.add(100.2, "1");
Double res2 = set2.addScore(1, new Double(12.1));
Double res2 = set2.addScore("1", new Double(12.1));
Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
res2 = set2.getScore(1);
res2 = set2.getScore("1");
Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
}

Loading…
Cancel
Save