1
0
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:
Dominik Menke
2021-09-10 21:12:33 +02:00
parent 3ac3452fe5
commit dfedc31d20
3 changed files with 221 additions and 19 deletions

View File

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