mirror of
https://github.com/redis/go-redis.git
synced 2025-07-29 17:41:15 +03:00
Handle IPv6 in isMovedError (#2981)
* Handle IPv6 in isMovedError * Simplify GetAddr --------- Co-authored-by: Monkey <golang@88.com>
This commit is contained in:
@ -2,6 +2,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -64,3 +65,19 @@ func ReplaceSpaces(s string) string {
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func GetAddr(addr string) string {
|
||||
ind := strings.LastIndexByte(addr, ':')
|
||||
if ind == -1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.IndexByte(addr, '.') != -1 {
|
||||
return addr
|
||||
}
|
||||
|
||||
if addr[0] == '[' {
|
||||
return addr
|
||||
}
|
||||
return net.JoinHostPort(addr[:ind], addr[ind+1:])
|
||||
}
|
||||
|
Reference in New Issue
Block a user