Skip to content

Commit

Permalink
docs: Availability zone affinity routing
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Jan 24, 2025
1 parent 8d9e2bb commit 2ffb082
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A fast Golang Valkey client that does auto pipelining and supports server-assist
* Pub/Sub, Sharded Pub/Sub, Streams
* Valkey Cluster, Sentinel, RedisJSON, RedisBloom, RediSearch, RedisTimeseries, etc.
* [Probabilistic Data Structures without Redis Stack](./valkeyprob)
* [Availability zone affinity routing](#availability-zone-affinity-routing)

---

Expand Down Expand Up @@ -411,6 +412,26 @@ client, err = valkey.NewClient(valkey.MustParseURL("redis://127.0.0.1:6379/0"))
client, err = valkey.NewClient(valkey.MustParseURL("redis://127.0.0.1:26379/0?master_set=my_master"))
```

### Availability Zone Affinity Routing

Starting from Valkey 8.1, Valkey server provides the `availability-zone` information for clients to know where the server is located.
For using this information to route requests to the replica located in the same availability zone,
set the `EnableReplicaAZInfo` option and your `ReplicaSelector` function. For example:

```go
client, err := valkey.NewClient(valkey.ClientOption{
InitAddress: []string{"address.example.com:6379"},
EnableReplicaAZInfo: true,
ReplicaSelector: func(slot uint16, replicas []valkey.ReplicaInfo) int {
for i, replica := range replicas {
if replica.AZ == "us-east-1a" {
return i // return the index of the replica.
}
}
return -1 // send to the primary.
},
})
```

## Arbitrary Command

Expand Down

0 comments on commit 2ffb082

Please sign in to comment.