RedisNode creation from bare hostname assigns default port.

Closes #2928
Original pull request: #3002
This commit is contained in:
LeeHyungGeol
2024-09-22 16:50:02 +09:00
committed by Mark Paluch
parent 6e85141310
commit 047e63ea78
2 changed files with 86 additions and 1 deletions

View File

@@ -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);
}
}
}