RedisNode creation from bare hostname assigns default port.
Closes #2928 Original pull request: #3002
This commit is contained in:
committed by
Mark Paluch
parent
6e85141310
commit
047e63ea78
@@ -24,10 +24,13 @@ import org.springframework.util.StringUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
* @author LeeHyungGeol
|
||||
* @since 1.4
|
||||
*/
|
||||
public class RedisNode implements NamedNode {
|
||||
|
||||
private static final int DEFAULT_PORT = 6379;
|
||||
|
||||
@Nullable String id;
|
||||
@Nullable String name;
|
||||
@Nullable String host;
|
||||
@@ -94,7 +97,17 @@ public class RedisNode implements NamedNode {
|
||||
portString = hostPortString.substring(colonPos + 1);
|
||||
} else {
|
||||
// 0 or 2+ colons. Bare hostname or IPv6 literal.
|
||||
host = hostPortString;
|
||||
int lastColonIndex = hostPortString.lastIndexOf(':');
|
||||
|
||||
// IPv6 literal
|
||||
if (lastColonIndex > hostPortString.indexOf(']')) {
|
||||
host = hostPortString.substring(0, lastColonIndex);
|
||||
portString = hostPortString.substring(lastColonIndex + 1);
|
||||
} else {
|
||||
// bare hostname
|
||||
host = hostPortString;
|
||||
portString = Integer.toString(DEFAULT_PORT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user