Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/utils/cluster_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down