@@ -21,6 +21,7 @@ A fast Golang Redis client that does auto pipelining and supports server-assiste
21
21
* Pub/Sub, Sharded Pub/Sub, Streams
22
22
* Redis Cluster, Sentinel, RedisJSON, RedisBloom, RediSearch, RedisTimeseries, etc.
23
23
* [ Probabilistic Data Structures without Redis Stack] ( ./rueidisprob )
24
+ * [ Availability zone affinity routing] ( #availability-zone-affinity-routing )
24
25
25
26
---
26
27
@@ -411,6 +412,26 @@ client, err = rueidis.NewClient(rueidis.MustParseURL("redis://127.0.0.1:6379/0")
411
412
client, err = rueidis.NewClient (rueidis.MustParseURL (" redis://127.0.0.1:26379/0?master_set=my_master" ))
412
413
```
413
414
415
+ ### Availability Zone Affinity Routing
416
+
417
+ Starting from Valkey 8.1, Valkey server provides the ` availability-zone ` information for clients to know where the server is located.
418
+ For using this information to route requests to the replica located in the same availability zone,
419
+ set the ` EnableReplicaAZInfo ` option and your ` ReplicaSelector ` function. For example:
420
+
421
+ ``` go
422
+ client , err := rueidis.NewClient (rueidis.ClientOption {
423
+ InitAddress : []string {" address.example.com:6379" },
424
+ EnableReplicaAZInfo : true ,
425
+ ReplicaSelector : func (slot uint16 , replicas []rueidis.ReplicaInfo ) int {
426
+ for i , replica := range replicas {
427
+ if replica.AZ == " us-east-1a" {
428
+ return i // return the index of the replica.
429
+ }
430
+ }
431
+ return -1 // send to the primary.
432
+ },
433
+ })
434
+ ```
414
435
415
436
## Arbitrary Command
416
437
0 commit comments