Add support for bracket-less IPv6 addresses to CLUSTER NODES Converter.
Closes #2678 Original pull request: #2679
This commit is contained in:
committed by
Mark Paluch
parent
158c73e028
commit
d1908fdbfc
@@ -60,6 +60,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author daihuabin
|
||||
* @author John Blum
|
||||
* @author Sorokin Evgeniy
|
||||
*/
|
||||
public abstract class Converters {
|
||||
|
||||
@@ -560,21 +561,28 @@ public abstract class Converters {
|
||||
public RedisClusterNode convert(String source) {
|
||||
|
||||
String[] args = source.split(" ");
|
||||
String[] hostAndPort = StringUtils.split(args[HOST_PORT_INDEX], ":");
|
||||
|
||||
Assert.notNull(hostAndPort, "ClusterNode information does not define host and port");
|
||||
int lastColonIndex = args[HOST_PORT_INDEX].lastIndexOf(":");
|
||||
|
||||
Assert.isTrue(lastColonIndex >= 0 && lastColonIndex < args[HOST_PORT_INDEX].length() - 1,
|
||||
"ClusterNode information does not define host and port");
|
||||
|
||||
String portPart = args[HOST_PORT_INDEX].substring(lastColonIndex + 1);
|
||||
String hostPart = args[HOST_PORT_INDEX].substring(0, lastColonIndex);
|
||||
|
||||
SlotRange range = parseSlotRange(args);
|
||||
Set<Flag> flags = parseFlags(args);
|
||||
|
||||
String portPart = hostAndPort[1];
|
||||
|
||||
if (portPart.contains("@")) {
|
||||
portPart = portPart.substring(0, portPart.indexOf('@'));
|
||||
}
|
||||
|
||||
if (hostPart.startsWith("[") && hostPart.endsWith("]")) {
|
||||
hostPart = hostPart.substring(1, hostPart.length() - 1);
|
||||
}
|
||||
|
||||
RedisClusterNodeBuilder nodeBuilder = RedisClusterNode.newRedisClusterNode()
|
||||
.listeningAt(hostAndPort[0], Integer.parseInt(portPart)) //
|
||||
.listeningAt(hostPart, Integer.parseInt(portPart)) //
|
||||
.withId(args[ID_INDEX]) //
|
||||
.promotedAs(flags.contains(Flag.MASTER) ? NodeType.MASTER : NodeType.REPLICA) //
|
||||
.serving(range) //
|
||||
|
||||
Reference in New Issue
Block a user