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)
| 495 | // MaxRetries: 2, |
| 496 | // } |
| 497 | func 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 | |
| 513 | func setupTCPConn(u *url.URL) (*Options, error) { |
| 514 | o := &Options{Network: "tcp"} |