mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add query parameter parsing to ParseURL()
Before this change, ParseURL would only accept a very restricted set of URLs (it returned an error, if it encountered any parameter). This commit introduces the ability to process URLs like redis://localhost/1?dial_timeout=10s and similar. Go programs which were providing a configuration tunable (e.g. CLI flag, config entry or environment variable) to configure the Redis connection now don't need to perform this task themselves.
This commit is contained in:
@ -39,13 +39,14 @@ func ExampleNewClient() {
|
||||
}
|
||||
|
||||
func ExampleParseURL() {
|
||||
opt, err := redis.ParseURL("redis://:qwerty@localhost:6379/1")
|
||||
opt, err := redis.ParseURL("redis://:qwerty@localhost:6379/1?dial_timeout=5s")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("addr is", opt.Addr)
|
||||
fmt.Println("db is", opt.DB)
|
||||
fmt.Println("password is", opt.Password)
|
||||
fmt.Println("dial timeout is", opt.DialTimeout)
|
||||
|
||||
// Create client as usually.
|
||||
_ = redis.NewClient(opt)
|
||||
@ -53,6 +54,7 @@ func ExampleParseURL() {
|
||||
// Output: addr is localhost:6379
|
||||
// db is 1
|
||||
// password is qwerty
|
||||
// dial timeout is 5s
|
||||
}
|
||||
|
||||
func ExampleNewFailoverClient() {
|
||||
|
Reference in New Issue
Block a user