Update cluster_nodes.go to handle hostnames in cluster nodes output (#938)

use hostname if present, else fallback to ipv6 address, else fallback to node ipv4 address
This commit is contained in:
tharunsikhinam 2025-06-16 18:21:41 -07:00 committed by GitHub
parent 97acb9c3be
commit efcd939d44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -32,6 +32,7 @@ func GetRedisClusterNodes(ctx context.Context, address string, username string,
// address
address := strings.Split(words[1], "@")[0]
// handle ipv6 address
tok := strings.Split(address, ":")
if len(tok) > 2 {
@ -41,6 +42,13 @@ func GetRedisClusterNodes(ctx context.Context, address string, username string,
ipv6Addr := strings.Join(tok[:len(tok)-1], ":")
address = fmt.Sprintf("[%s]:%s", ipv6Addr, port)
}
// handle hostname
hostname := strings.Split(words[1],",")
if len(hostname) > 1 {
address = fmt.Sprintf("%s:%s", hostname[1], tok[len(tok)-1])
}
if isMaster && len(words) < 9 {
log.Warnf("the current master node does not hold any slots. address=[%v]", address)
continue