You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/develop/clients/redis-py/failover.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,56 @@ There are also a few other options you can pass to the `MultiDbConfig` construct
202
202
|`failover_attempts`| Number of attempts to fail over to a new endpoint before giving up. Default is `10`. |
203
203
|`failover_delay`| Time interval between successive failover attempts. Default is `12` seconds. |
204
204
|`auto_fallback_interval`| Time interval between automatic failback attempts. Default is `30` seconds. |
205
+
|`event_dispatcher`|`EventDispatcher` object to use for emitting events. Supply this to register custom event listeners (see [Failover callbacks](#failover-callbacks) below for more information). |
206
+
207
+
### Failover callbacks
208
+
209
+
You may want to take some custom action when a failover occurs. For example, you could log a warning, increment a metric, or externally persist the cluster connection state.
210
+
211
+
You can implement a custom event listener using a class that implements `EventListenerInterface`. This includes a `listen()` method that is called when
212
+
the event occurs. You should specifically listen for the `ActiveDatabaseChanged`
213
+
event, which is emitted when a failover happens.
214
+
215
+
The example below shows how to implement a simple listener class and register an instance
216
+
of it using an `EventDispatcher` object. You can then pass the `EventDispatcher` to the
217
+
`MultiDbConfig` constructor to enable the custom behavior.
218
+
219
+
```py
220
+
import logging
221
+
222
+
from redis.multidb.client import MultiDBClient
223
+
from redis.multidb.config import MultiDbConfig
224
+
225
+
from redis.event import EventListenerInterface, EventDispatcher
226
+
from redis.multidb.event import ActiveDatabaseChanged
0 commit comments