diff --git a/redisson/src/main/java/org/redisson/client/protocol/decoder/ClusterNodesDecoder.java b/redisson/src/main/java/org/redisson/client/protocol/decoder/ClusterNodesDecoder.java index 38d3a373c48c4309b2ad9dd33e133bb716c88ba2..1683dc040c6792ff9e38cc4e2a91e3cc9cebe742 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/decoder/ClusterNodesDecoder.java +++ b/redisson/src/main/java/org/redisson/client/protocol/decoder/ClusterNodesDecoder.java @@ -15,18 +15,17 @@ */ package org.redisson.client.protocol.decoder; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - +import io.netty.buffer.ByteBuf; +import io.netty.util.CharsetUtil; import org.redisson.client.handler.State; import org.redisson.client.protocol.Decoder; import org.redisson.cluster.ClusterNodeInfo; -import org.redisson.cluster.ClusterSlotRange; import org.redisson.cluster.ClusterNodeInfo.Flag; +import org.redisson.cluster.ClusterSlotRange; -import io.netty.buffer.ByteBuf; -import io.netty.util.CharsetUtil; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @@ -84,7 +83,7 @@ public class ClusterNodesDecoder implements Decoder> { if (params.length > 8) { for (int i = 0; i < params.length - 8; i++) { String slots = params[i + 8]; - if (slots.indexOf("-<-") != -1 || slots.indexOf("->-") != -1) { + if (slots.contains("-<-") || slots.contains("->-")) { continue; } diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterPartition.java b/redisson/src/main/java/org/redisson/cluster/ClusterPartition.java index 12e78c5475451f2dfad71cfbba41b995c94ee644..f3b5df779f458f0075a5a4397ee35d630c8ec4b9 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterPartition.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterPartition.java @@ -22,6 +22,8 @@ import java.util.Set; import org.redisson.misc.RedisURI; +import static org.redisson.connection.MasterSlaveConnectionManager.MAX_SLOT; + /** * * @author Nikita Koksharov @@ -39,7 +41,7 @@ public class ClusterPartition { private final Set slaveAddresses = new HashSet<>(); private final Set failedSlaves = new HashSet<>(); - private final BitSet slots = new BitSet(); + private final BitSet slots = new BitSet(MAX_SLOT); private final Set slotRanges = new HashSet(); private ClusterPartition parent; @@ -86,17 +88,13 @@ public class ClusterPartition { public void addSlotRanges(Set ranges) { for (ClusterSlotRange clusterSlotRange : ranges) { - for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) { - slots.set(i); - } + slots.set(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1); } slotRanges.addAll(ranges); } public void removeSlotRanges(Set ranges) { for (ClusterSlotRange clusterSlotRange : ranges) { - for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) { - slots.clear(i); - } + slots.clear(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1); } slotRanges.removeAll(ranges); } @@ -105,7 +103,7 @@ public class ClusterPartition { } public Iterable getSlots() { - return (Iterable) slots.stream()::iterator; + return slots.stream()::iterator; } public BitSet slots() {