MCPcopy
hub / github.com/redis/go-redis / setupTCPConn

Function setupTCPConn

options.go:513–544  ·  view source on GitHub ↗
(u *url.URL)

Source from the content-addressed store, hash-verified

511}
512
513func 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

Callers 1

ParseURLFunction · 0.85

Calls 3

getUserPasswordFunction · 0.85
getHostPortWithDefaultsFunction · 0.85
setupConnParamsFunction · 0.85

Tested by

no test coverage detected