From 2dbe5a3d990d0d414ae710615ef05b05961a351f Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 9 Jun 2017 13:55:45 +0300 Subject: [PATCH] Add ParseURL example --- example_test.go | 17 +++++++++++++++++ options.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index 6453fd1..fbb92c1 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 4e1c9d0..dfda7df 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)