(u *url.URL)
| 511 | } |
| 512 | |
| 513 | func setupTCPConn(u *url.URL) (*Options, error) { |
| 514 | o := &Options{Network: "tcp"} |
| 515 | |
| 516 | o.Username, o.Password = getUserPassword(u) |
| 517 | |
| 518 | h, p := getHostPortWithDefaults(u) |
| 519 | o.Addr = net.JoinHostPort(h, p) |
| 520 | |
| 521 | f := strings.FieldsFunc(u.Path, func(r rune) bool { |
| 522 | return r == '/' |
| 523 | }) |
| 524 | switch len(f) { |
| 525 | case 0: |
| 526 | o.DB = 0 |
| 527 | case 1: |
| 528 | var err error |
| 529 | if o.DB, err = strconv.Atoi(f[0]); err != nil { |
| 530 | return nil, fmt.Errorf("redis: invalid database number: %q", f[0]) |
| 531 | } |
| 532 | default: |
| 533 | return nil, fmt.Errorf("redis: invalid URL path: %s", u.Path) |
| 534 | } |
| 535 | |
| 536 | if u.Scheme == "rediss" { |
| 537 | o.TLSConfig = &tls.Config{ |
| 538 | ServerName: h, |
| 539 | MinVersion: tls.VersionTLS12, |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | return setupConnParams(u, o) |
| 544 | } |
| 545 | |
| 546 | // getHostPortWithDefaults is a helper function that splits the url into |
| 547 | // a host and a port. If the host is missing, it defaults to localhost |
no test coverage detected