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

Function ParseURL

options.go:497–511  ·  view source on GitHub ↗

ParseURL parses a URL into Options that can be used to connect to Redis. Scheme is required. There are two connection types: by tcp socket and by unix socket. Tcp connection: redis:// : @ : / Unix connection: unix:// : @ ?db=<

(redisURL string)

Source from the content-addressed store, hash-verified

495// MaxRetries: 2,
496// }
497func ParseURL(redisURL string) (*Options, error) {
498 u, err := url.Parse(redisURL)
499 if err != nil {
500 return nil, err
501 }
502
503 switch u.Scheme {
504 case "redis", "rediss":
505 return setupTCPConn(u)
506 case "unix":
507 return setupUnixConn(u)
508 default:
509 return nil, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
510 }
511}
512
513func setupTCPConn(u *url.URL) (*Options, error) {
514 o := &Options{Network: "tcp"}

Callers 1

TestParseURLFunction · 0.85

Calls 2

setupTCPConnFunction · 0.85
setupUnixConnFunction · 0.85

Tested by 1

TestParseURLFunction · 0.68