@@ -21,6 +21,7 @@ A fast Golang Redis client that does auto pipelining and supports server-assiste
2121* Pub/Sub, Sharded Pub/Sub, Streams
2222* Redis Cluster, Sentinel, RedisJSON, RedisBloom, RediSearch, RedisTimeseries, etc.
2323* [ Probabilistic Data Structures without Redis Stack] ( ./rueidisprob )
24+ * [ Availability zone affinity routing] ( #availability-zone-affinity-routing )
2425
2526---
2627
@@ -411,6 +412,26 @@ client, err = rueidis.NewClient(rueidis.MustParseURL("redis://127.0.0.1:6379/0")
411412client, err = rueidis.NewClient (rueidis.MustParseURL (" redis://127.0.0.1:26379/0?master_set=my_master" ))
412413```
413414
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+ ```
414435
415436## Arbitrary Command
416437
0 commit comments