use of org.springframework.data.redis.connection.RedisClusterNode.Flag in project redisson by redisson.
the class RedisClusterNodeDecoder method decode.
@Override
public List<RedisClusterNode> decode(ByteBuf buf, State state) throws IOException {
String response = buf.toString(CharsetUtil.UTF_8);
List<RedisClusterNode> nodes = new ArrayList<RedisClusterNode>();
for (String nodeInfo : response.split("\n")) {
String[] params = nodeInfo.split(" ");
String nodeId = params[0];
String flagsStr = params[2];
Set<Flag> flags = EnumSet.noneOf(Flag.class);
for (String flag : flagsStr.split(",")) {
String flagValue = flag.toUpperCase().replaceAll("\\?", "");
flags.add(Flag.valueOf(flagValue));
}
RedisURI address = null;
if (!flags.contains(Flag.NOADDR)) {
String addr = params[1].split("@")[0];
address = new RedisURI("redis://" + addr);
}
String masterId = params[3];
if ("-".equals(masterId)) {
masterId = null;
}
Set<Integer> slotsCollection = new HashSet<Integer>();
LinkState linkState = null;
if (params.length >= 8 && params[7] != null) {
linkState = LinkState.valueOf(params[7].toUpperCase());
}
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) {
continue;
}
String[] parts = slots.split("-");
if (parts.length == 1) {
slotsCollection.add(Integer.valueOf(parts[0]));
} else if (parts.length == 2) {
for (int j = Integer.valueOf(parts[0]); j < Integer.valueOf(parts[1]) + 1; j++) {
slotsCollection.add(j);
}
}
}
}
NodeType type = null;
if (flags.contains(Flag.MASTER)) {
type = NodeType.MASTER;
} else if (flags.contains(Flag.SLAVE)) {
type = NodeType.SLAVE;
}
RedisClusterNodeBuilder builder = RedisClusterNode.newRedisClusterNode().linkState(linkState).slaveOf(masterId).serving(new SlotRange(slotsCollection)).withId(nodeId).promotedAs(type).withFlags(flags);
if (address != null) {
builder.listeningAt(address.getHost(), address.getPort());
}
nodes.add(builder.build());
}
return nodes;
}
Aggregations