diff --git a/example_test.go b/example_test.go index 6453fd15..fbb92c17 100644 --- a/example_test.go +++ b/example_test.go @@ -35,6 +35,23 @@ func ExampleNewClient() { // Output: PONG } +func ExampleParseURL() { + opt, err := redis.ParseURL("redis://:qwerty@localhost:6379/1") + if err != nil { + panic(err) + } + fmt.Println("addr is", opt.Addr) + fmt.Println("db is", opt.DB) + fmt.Println("password is", opt.Password) + + // Create client as usually. + _ = redis.NewClient(opt) + + // Output: addr is localhost:6379 + // db is 1 + // password is qwerty +} + func ExampleNewFailoverClient() { // See http://redis.io/topics/sentinel for instructions how to // setup Redis Sentinel. diff --git a/options.go b/options.go index 4e1c9d0d..dfda7df3 100644 --- a/options.go +++ b/options.go @@ -125,7 +125,7 @@ func (opt *Options) init() { } } -// ParseURL parses a redis URL into options that can be used to connect to redis +// ParseURL parses an URL into Options that can be used to connect to Redis. func ParseURL(redisURL string) (*Options, error) { o := &Options{Network: "tcp"} u, err := url.Parse(redisURL)