From a7cea0a63ed1241b3cfc4fd004bbbe2bd08da565 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 25 Sep 2023 09:41:07 +0300 Subject: [PATCH] Fixed - RSortedSet doesn't work correctly if NameMapper was specified. #5327 --- .../java/org/redisson/RedissonSortedSet.java | 28 ++++++++------- .../org/redisson/RedissonSortedSetTest.java | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonSortedSet.java b/redisson/src/main/java/org/redisson/RedissonSortedSet.java index c051200a5..6cd5cff93 100644 --- a/redisson/src/main/java/org/redisson/RedissonSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonSortedSet.java @@ -81,16 +81,16 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet) redisson.getList(getRawName()); + lock = redisson.getLock(getLockName()); + list = (RedissonList) redisson.getList(getName()); } public RedissonSortedSet(Codec codec, CommandAsyncExecutor commandExecutor, String name, Redisson redisson) { super(codec, commandExecutor, name); comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); - lock = redisson.getLock("redisson_sortedset_lock:{" + getRawName() + "}"); - list = (RedissonList) redisson.getList(getRawName(), codec); + lock = redisson.getLock(getLockName()); + list = (RedissonList) redisson.getList(getName(), codec); } @Override @@ -148,7 +148,7 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet> readAllAsync() { - return commandExecutor.readAsync(getRawName(), codec, RedisCommands.LRANGE_SET, getRawName(), 0, -1); + return (RFuture>) (Object) list.readAllAsync(); } @Override @@ -194,14 +194,14 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSetasList(getRawName()), index, encodedValue)); + + "redis.call('rpush', KEYS[1], ARGV[2]);", Arrays.asList(list.getRawName()), index, encodedValue)); return true; } else { return false; @@ -364,8 +364,12 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet extends RedissonObject implements RSortedSet extends RedissonObject implements RSortedSet> distributedScanIteratorAsync(String iteratorName, int count) { - return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_SCAN, + return commandExecutor.evalWriteAsync(list.getRawName(), codec, RedisCommands.EVAL_SCAN, "local start_index = redis.call('get', KEYS[2]); " + "if start_index ~= false then " + "start_index = tonumber(start_index); " @@ -432,7 +436,7 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet set = redisson.getSortedSet("simple", LongCodec.INSTANCE); + set.add(2L); + set.add(0L); + set.add(1L); + set.add(5L); + + assertThat(set.first()).isEqualTo(0L); + assertThat(set.last()).isEqualTo(5L); + + assertThat(set.readAll()).containsExactly(0L, 1L, 2L, 5L); + } + + @Test public void test1() { RSortedSet set = redisson.getSortedSet("simple", LongCodec.INSTANCE);