mirror of https://github.com/go-redis/redis.git
Merge pull request #577 from go-redis/fix/parse-url-example
Add ParseURL example
This commit is contained in:
commit
eb066030c0
|
@ -35,6 +35,23 @@ func ExampleNewClient() {
|
||||||
// Output: PONG <nil>
|
// 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() {
|
func ExampleNewFailoverClient() {
|
||||||
// See http://redis.io/topics/sentinel for instructions how to
|
// See http://redis.io/topics/sentinel for instructions how to
|
||||||
// setup Redis Sentinel.
|
// setup Redis Sentinel.
|
||||||
|
|
|
@ -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) {
|
func ParseURL(redisURL string) (*Options, error) {
|
||||||
o := &Options{Network: "tcp"}
|
o := &Options{Network: "tcp"}
|
||||||
u, err := url.Parse(redisURL)
|
u, err := url.Parse(redisURL)
|
||||||
|
|
Loading…
Reference in New Issue