private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) { String[] response = new String[3]; String[] messageInfo = clusterRedirectResponse.split(" "); String[] targetHostAndPort = HostAndPort.extractParts(messageInfo[2]); response[0] = messageInfo[1]; response[1] = targetHostAndPort[0]; response[2] = targetHostAndPort[1]; return response; }
/** * Creates HostAndPort instance from string. * String must be in ( host + ":" + port ) format. * Port is mandatory. Can convert host part. * @see #convertHost(String) * @param from String to parse * @return HostAndPort instance */ public static HostAndPort parseString(String from){ // NOTE: redis answers with // '99aa9999aa9a99aa099aaa990aa99a09aa9a9999 9a09:9a9:a090:9a::99a slave 8c88888888cc08088cc8c8c888c88c8888c88cc8 0 1468251272993 37 connected' // for CLUSTER NODES, ASK and MOVED scenarios. That's why there is no possibility to parse address in 'correct' way. // Redis should switch to 'bracketized' (RFC 3986) IPv6 address. try { String[] parts = extractParts(from); String host = parts[0]; int port = Integer.parseInt(parts[1]); return new HostAndPort(convertHost(host), port); } catch (NumberFormatException ex) { throw new IllegalArgumentException(ex); } }