@@ -4,7 +4,7 @@ title: Options
44
55# Options
66
7- Relay supports all of PhpRedis' ` setOption() ` options and comes with its own:
7+ Relay supports all of PhpRedis' ` setOption() ` constants and comes with its own:
88
99- ` OPT_USE_CACHE `
1010- ` OPT_PHPREDIS_COMPATIBILITY `
@@ -16,7 +16,13 @@ Relay supports all of PhpRedis' `setOption()` options and comes with its own:
1616- ` OPT_ADAPTIVE_CACHE `
1717- ` OPT_CAPA_REDIRECT `
1818- ` OPT_RESTORE_PUBSUB `
19- - ` OPT_AVAILABILITY_ZONE ` (cluster only)
19+
20+ As well as some ` Relay\Cluster ` specific ones:
21+
22+ - ` OPT_DISTRIBUTE `
23+ - ` OPT_FAILOVER `
24+ - ` OPT_AVAILABILITY_ZONE `
25+
2026
2127## ` OPT_USE_CACHE `
2228
@@ -93,12 +99,48 @@ Whether the client is capable of handling [`CLIENT CAPA redirect`](https://valke
9399
94100Whether Relay should automatically restore active Pub/Sub subscriptions after reconnecting.
95101
96- ## ` OPT_AVAILABILITY_ZONE `
102+ ## ` OPT_DISTRIBUTE `
103+
104+ Controls how readonly commands are distributed across cluster nodes. Defaults to ` DISTRIBUTE_NONE ` .
105+
106+ Instead of using PhpRedis' legacy ` OPT_SLAVE_FAILOVER ` , consider using ` OPT_DISTRIBUTE ` and ` OPT_FAILOVER ` .
107+
108+ | Value | Description |
109+ | --- | --- |
110+ | ` DISTRIBUTE_NONE ` | Send readonly commands to the primary node only. |
111+ | ` DISTRIBUTE_RANDOM ` | Distribute randomly between the primary and its replicas. Stops trying replicas after the first failed attempt. |
112+ | ` DISTRIBUTE_RANDOM_REPLICA ` | Distribute randomly among replicas only, never the primary. Stops trying replicas after the first failed attempt. |
113+ | ` DISTRIBUTE_REPLICAS ` | Distribute randomly among replicas only. Iterates through all replicas until it finds a working one. |
114+ | ` DISTRIBUTE_ALL ` | Distribute between the primary and its replicas. Iterates through all nodes until it finds a working one. |
115+
116+ ``` php
117+ $cluster->setOption(Cluster::OPT_DISTRIBUTE, Cluster::DISTRIBUTE_REPLICAS);
118+ ```
119+
120+ ### ` OPT_FAILOVER `
121+
122+ Controls the retry strategy when a command fails on a node. Defaults to ` FAILOVER_NONE ` .
123+
124+ Instead of using PhpRedis' legacy ` OPT_SLAVE_FAILOVER ` , consider using ` OPT_DISTRIBUTE ` and ` OPT_FAILOVER ` .
125+
126+ | Value | Description |
127+ | --- | --- |
128+ | ` FAILOVER_NONE ` | Don't retry. |
129+ | ` FAILOVER_RANDOM_REPLICA ` | Retry the readonly command on a randomly selected replica. |
130+ | ` FAILOVER_PRIMARY ` | Retry the readonly command on the primary node. Only applicable when the failed node is a replica. |
131+ | ` FAILOVER_REPLICAS ` | Retry the readonly command on all replicas, excluding the failed node. |
132+ | ` FAILOVER_ALL ` | Retry the readonly command on all other nodes (replicas and primary), excluding the failed node. |
133+
134+ ``` php
135+ $cluster->setOption(Cluster::OPT_FAILOVER, Cluster::FAILOVER_REPLICAS);
136+ ```
137+
138+ ### ` OPT_AVAILABILITY_ZONE `
97139
98- Available on ` Relay\Cluster ` . Sets a preferred availability zone so cluster reads can be routed to nodes in the same zone, reducing cross-AZ traffic.
140+ Sets a preferred availability zone so cluster reads can be routed to nodes in the same zone, reducing cross-AZ traffic.
99141
100142``` php
101- $cluster->setOption(Relay ::OPT_AVAILABILITY_ZONE, 'us-east-1a');
143+ $cluster->setOption(Cluster ::OPT_AVAILABILITY_ZONE, 'us-east-1a');
102144```
103145
104146## PhpRedis options
0 commit comments