Add ParseURL example

This commit is contained in:
Vladimir Mihailenco 2017-06-09 13:55:45 +03:00
parent f29951c899
commit 2dbe5a3d99
2 changed files with 18 additions and 1 deletions

View File

@ -35,6 +35,23 @@ func ExampleNewClient() {
// Output: PONG <nil>
}
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.

View File

@ -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)