diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 8ddeb3b27..19cdfb431 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -718,7 +718,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { int start = indexOf(key, (byte) '{'); if (start != -1) { int end = indexOf(key, (byte) '}'); - key = Arrays.copyOfRange(key, start+1, end); + if (end != -1 && start + 1 < end) { + key = Arrays.copyOfRange(key, start + 1, end); + } } int result = CRC16.crc16(key) % MAX_SLOT; @@ -734,7 +736,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { int start = key.indexOf('{'); if (start != -1) { int end = key.indexOf('}'); - key = key.substring(start+1, end); + if (end != -1 && start + 1 < end) { + key = key.substring(start + 1, end); + } } int result = CRC16.crc16(key.getBytes()) % MAX_SLOT; diff --git a/redisson/src/test/java/org/redisson/RedissonSetTest.java b/redisson/src/test/java/org/redisson/RedissonSetTest.java index 61e66357d..81ed995df 100644 --- a/redisson/src/test/java/org/redisson/RedissonSetTest.java +++ b/redisson/src/test/java/org/redisson/RedissonSetTest.java @@ -528,9 +528,9 @@ public class RedissonSetTest extends BaseTest { .setLoadBalancer(new RandomLoadBalancer()) .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort()); RedissonClient redisson = Redisson.create(config); - + int size = 10000; - RSet set = redisson.getSet("test"); + RSet set = redisson.getSet("{test"); for (int i = 0; i < size; i++) { set.add("" + i); } @@ -541,7 +541,7 @@ public class RedissonSetTest extends BaseTest { } assertThat(keys).hasSize(size); - + redisson.shutdown(); process.shutdown(); }