File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,10 +23,11 @@ func ParseURL(str string) (opt ClientOption, err error) {
2323 if err != nil {
2424 return opt , err
2525 }
26+ fallbackHost := u .Host
2627 parseAddr := func (hostport string ) (host string , addr string ) {
2728 host , port , _ := net .SplitHostPort (hostport )
2829 if host == "" {
29- host = u . Host
30+ host = fallbackHost
3031 }
3132 if host == "" {
3233 host = "localhost"
@@ -52,6 +53,7 @@ func ParseURL(str string) (opt ClientOption, err error) {
5253 }
5354 if opt .InitAddress == nil {
5455 host , addr := parseAddr (u .Host )
56+ fallbackHost = host
5557 opt .InitAddress = []string {addr }
5658 if opt .TLSConfig != nil {
5759 opt .TLSConfig .ServerName = host
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ func TestParseURL(t *testing.T) {
3535 if opt , err := ParseURL ("redis://?addr=:6380&addr=:6381" ); err != nil || opt .InitAddress [0 ] != "localhost:6379" || opt .InitAddress [1 ] != "localhost:6380" || opt .InitAddress [2 ] != "localhost:6381" {
3636 t .Fatalf ("unexpected %v %v" , opt , err )
3737 }
38+ if opt , err := ParseURL ("redis://cache:6379?addr=:6380" ); err != nil || opt .InitAddress [0 ] != "cache:6379" || opt .InitAddress [1 ] != "cache:6380" {
39+ t .Fatalf ("unexpected %v %v" , opt , err )
40+ }
41+ if opt , err := ParseURL ("redis://[::1]:6379?addr=:6380" ); err != nil || opt .InitAddress [0 ] != "[::1]:6379" || opt .InitAddress [1 ] != "[::1]:6380" {
42+ t .Fatalf ("unexpected %v %v" , opt , err )
43+ }
3844 if opt , err := ParseURL ("redis://myhost:1234" ); err != nil || opt .InitAddress [0 ] != "myhost:1234" {
3945 t .Fatalf ("unexpected %v %v" , opt , err )
4046 }
You can’t perform that action at this time.
0 commit comments