Skip to content

Commit

Permalink
Updating the README with connection options (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored Jul 26, 2023
1 parent c0ab781 commit 0cc9cd6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Some corner cases:
Expand Down

0 comments on commit 0cc9cd6

Please sign in to comment.