Skip to content

Commit 0cc9cd6

Browse files
authored
Updating the README with connection options (#2661)
1 parent c0ab781 commit 0cc9cd6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ func ExampleClient() {
105105
}
106106
```
107107

108+
The above can be modified to specify the version of the RESP protocol by adding the `protocol` option to the `Options` struct:
109+
110+
```go
111+
rdb := redis.NewClient(&redis.Options{
112+
Addr: "localhost:6379",
113+
Password: "", // no password set
114+
DB: 0, // use default DB
115+
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
116+
})
117+
118+
```
119+
120+
### Connecting via a redis url
121+
122+
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.
123+
124+
```go
125+
import (
126+
"context"
127+
"github.com/redis/go-redis/v9"
128+
"fmt"
129+
)
130+
131+
var ctx = context.Background()
132+
133+
func ExampleClient() {
134+
url := "redis://localhost:6379?password=hello&protocol=3"
135+
opts, err := redis.ParseURL(url)
136+
if err != nil {
137+
panic(err)
138+
}
139+
rdb := redis.NewClient(opts)
140+
```
141+
108142
## Look and feel
109143
110144
Some corner cases:

0 commit comments

Comments
 (0)