mirror of https://github.com/go-redis/redis.git
Updating the README with connection options (#2661)
This commit is contained in:
parent
c0ab7815ea
commit
0cc9cd6e08
34
README.md
34
README.md
|
@ -105,6 +105,40 @@ func ExampleClient() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The above can be modified to specify the version of the RESP protocol by adding the `protocol` option to the `Options` struct:
|
||||||
|
|
||||||
|
```go
|
||||||
|
rdb := redis.NewClient(&redis.Options{
|
||||||
|
Addr: "localhost:6379",
|
||||||
|
Password: "", // no password set
|
||||||
|
DB: 0, // use default DB
|
||||||
|
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Connecting via a redis url
|
||||||
|
|
||||||
|
go-redis also supports connecting via the [redis uri specification](https://github.com/redis/redis-specifications/tree/master/uri/redis.txt). The example below demonstrates how the connection can easily be configured using a string, adhering to this specification.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ctx = context.Background()
|
||||||
|
|
||||||
|
func ExampleClient() {
|
||||||
|
url := "redis://localhost:6379?password=hello&protocol=3"
|
||||||
|
opts, err := redis.ParseURL(url)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
rdb := redis.NewClient(opts)
|
||||||
|
```
|
||||||
|
|
||||||
## Look and feel
|
## Look and feel
|
||||||
|
|
||||||
Some corner cases:
|
Some corner cases:
|
||||||
|
|
Loading…
Reference in New Issue