From 272788339c34cd8919378f10c697dd7bbd5cf4f3 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 19 Nov 2025 12:50:22 +0200 Subject: [PATCH 1/3] Added custom event handler section --- docs/multi_database.rst | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/multi_database.rst b/docs/multi_database.rst index 88ec21a2fb..9da932bcba 100644 --- a/docs/multi_database.rst +++ b/docs/multi_database.rst @@ -315,7 +315,7 @@ reverse proxy behind an actual REST API endpoint. health_check_url="https://cluster.example.com", ), ], - # Add custom checks (in addition to default PingHealthCheck) + # Add custom health check to replace the default health_checks=[ # Redis Enterprise REST-based lag-aware check LagAwareHealthCheck( @@ -412,6 +412,51 @@ To enable periodic fallback to a higher-priority healthy database, set `auto_fal ) client = MultiDBClient(cfg) + +Custom failover callbacks +------------------------- + +You may want to make a custom actions when failover happens. For example, you may want to collect some metrics, +logs or externally persist a connection state. + +You can register your own event listener for `ActiveDatabaseChanged` event that was emitted when failover happened, via +the `EventDispatcher`. + +.. code-block:: python + + class LogFailoverEventListener(EventListenerInterface): + def __init__(self, logger: Logger): + self.logger = logger + + def listen(self, event: ActiveDatabaseChanged): + self.logger.warning( + f"Failover happened. Active database switched from {event.old_database} to {event.new_database}" + ) + + event_dispatcher = EventDispatcher() + listener = LogFailoverEventListener(logging.getLogger(__name__)) + + # Register custom listener + event_dispatcher.register_listeners( + { + ActiveDatabaseChanged: [listener], + } + ) + + config = MultiDbConfig( + client_class=client_class, + databases_config=db_configs, + command_retry=command_retry, + min_num_failures=min_num_failures, + health_check_probes=3, + health_check_interval=health_check_interval, + event_dispatcher=event_dispatcher, + health_check_probes_delay=health_check_delay, + ) + + client = MultiDBClient(config) + + Managing databases at runtime ----------------------------- From 8491781aea89cb86e497058c9af2ba7763f15565 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Wed, 19 Nov 2025 13:37:45 +0200 Subject: [PATCH 2/3] Update docs/multi_database.rst Co-authored-by: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> --- docs/multi_database.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/multi_database.rst b/docs/multi_database.rst index 9da932bcba..5154de7562 100644 --- a/docs/multi_database.rst +++ b/docs/multi_database.rst @@ -416,7 +416,7 @@ To enable periodic fallback to a higher-priority healthy database, set `auto_fal Custom failover callbacks ------------------------- -You may want to make a custom actions when failover happens. For example, you may want to collect some metrics, +You may want to activate custom actions when failover happens. For example, you may want to collect some metrics, logs or externally persist a connection state. You can register your own event listener for `ActiveDatabaseChanged` event that was emitted when failover happened, via From cbd18668c5144f1f5f5377b9e79b7cf6fd92b628 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Wed, 19 Nov 2025 13:37:51 +0200 Subject: [PATCH 3/3] Update docs/multi_database.rst Co-authored-by: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> --- docs/multi_database.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/multi_database.rst b/docs/multi_database.rst index 5154de7562..479fab0cd0 100644 --- a/docs/multi_database.rst +++ b/docs/multi_database.rst @@ -419,7 +419,7 @@ Custom failover callbacks You may want to activate custom actions when failover happens. For example, you may want to collect some metrics, logs or externally persist a connection state. -You can register your own event listener for `ActiveDatabaseChanged` event that was emitted when failover happened, via +You can register your own event listener for the `ActiveDatabaseChanged` event (which is emitted when a failover happens) using the `EventDispatcher`. .. code-block:: python