Skip to content

Commit 24d7f7b

Browse files
DOC-5849 implemented PR feedback
1 parent 57e0062 commit 24d7f7b

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

content/develop/clients/redis-py/failover.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ failing back to that server even if it is not optimal.
8282

8383
redis-py periodically runs a "health check" on each server to see if it has recovered.
8484
The health check can be as simple as
85-
sending a Redis [`ECHO`]({{< relref "/commands/echo" >}}) command and ensuring
85+
sending a Redis [`PING`]({{< relref "/commands/ping" >}}) command and ensuring
8686
that it gives the expected response.
8787

8888
You can also configure redis-py to run health checks on the current target
@@ -131,13 +131,26 @@ constructor in the `databases_config` parameter.
131131

132132
| Option | Description |
133133
| --- | --- |
134-
| `client_kwargs` | Keyword parameters to pass to the internal `RedisClient` constructor for this endpoint. Use it to specify the host, port, username, password, and other connection parameters (see [Connect to the server]({{< relref "/develop/clients/redis-py/connect" >}}) for more information). |
134+
| `client_kwargs` | Keyword parameters to pass to the internal client constructor for this endpoint. Use it to specify the host, port, username, password, and other connection parameters (see [Connect to the server]({{< relref "/develop/clients/redis-py/connect" >}}) for more information). This is especially useful if you are using a custom client class (see [Client configuration](#client-configuration) below for more information). |
135135
| `from_url` | Redis URL to connect to this endpoint, as an alternative to passing the host and port in `client_kwargs`. |
136136
| `from_pool` | A `ConnectionPool` to supply the endpoint connection (see [Connect with a connection pool]({{< relref "/develop/clients/redis-py/connect#connect-with-a-connection-pool" >}}) for more information) |
137137
| `weight` | Priority of the endpoint, with higher values being tried first. Default is `1.0`. |
138138
| `grace_period` | Duration in seconds to keep an unhealthy endpoint disabled before attempting a failback. Default is `60` seconds. |
139139
| `health_check_url` | URL for health checks that use the database's REST API (see [`LagAwareHealthCheck`](#lag-aware-health-check) for more information). |
140140

141+
### Client configuration
142+
143+
`MultiDbConfig` provides the `client_class` option to specify the class of the internal client to use for each endpoint. The default is the basic `redis.Redis` client, but
144+
you could, for example, replace this with `redis.asyncio.client.Redis` for an asynchronous basic client, or with `redis.cluster.RedisCluster`/`redis.asyncio.cluster.RedisCluster` for a cluster client. Use the `client_kwargs` option of `DatabaseConfig` to supply any extra parameters required by the client class (see [Endpoint configuration](#endpoint-configuration) above for more information).
145+
146+
```py
147+
cfg = MultiDbConfig(
148+
...
149+
client_class=redis.asyncio.client.Redis,
150+
...
151+
)
152+
```
153+
141154
### Retry configuration
142155

143156
`MultiDbConfig` provides the `command_retry` option to configure retries for failed commands. This follows the usual approach to configuring retries used with a standard
@@ -159,7 +172,7 @@ cfg = MultiDbConfig(
159172
### Health check configuration
160173

161174
Each health check consists of one or more separate "probes", each of which is a simple
162-
test (such as an [`ECHO`]({{< relref "/commands/echo" >}}) command) to determine if the database is available. The results of the separate probes are combined
175+
test (such as a [`PING`]({{< relref "/commands/ping" >}}) command) to determine if the database is available. The results of the separate probes are combined
163176
using a configurable policy to determine if the database is healthy. `MultiDbConfig` provides the following options to configure the health check behavior:
164177

165178
| Option | Description |
@@ -168,7 +181,7 @@ using a configurable policy to determine if the database is healthy. `MultiDbCon
168181
| `health_check_probes` | Number of separate probes performed during each health check. Default is `3`. |
169182
| `health_check_probes_delay` | Delay between probes during a health check. Default is `0.5` seconds. |
170183
| `health_check_policy` | `HealthCheckPolicies` enum value to specify the policy for determining database health from the separate probes of a health check. The options are `HealthCheckPolicies.ALL` (all probes must succeed), `HealthCheckPolicies.ANY` (at least one probe must succeed), and `HealthCheckPolicies.MAJORITY` (more than half the probes must succeed). The default policy is `HealthCheckPolicies.MAJORITY`. |
171-
| `health_check` | Custom list of `HealthCheck` objects to specify how to perform each probe during a health check. This defaults to just the simple [`EchoHealthCheck`](#echohealthcheck-default). |
184+
| `health_check` | Custom list of `HealthCheck` objects to specify how to perform each probe during a health check. This defaults to just the simple [`PingHealthCheck`](#pinghealthcheck-default). |
172185

173186
### Circuit breaker configuration
174187

@@ -196,12 +209,12 @@ There are several strategies available for health checks that you can configure
196209
`MultiClusterClientConfig` builder. The sections below explain these strategies
197210
in more detail.
198211

199-
### `EchoHealthCheck` (default)
212+
### `PingHealthCheck` (default)
200213

201-
The default strategy, `EchoHealthCheck`, periodically sends a Redis
202-
[`ECHO`]({{< relref "/commands/echo" >}}) command
214+
The default strategy, `PingHealthCheck`, periodically sends a Redis
215+
[`PING`]({{< relref "/commands/ping" >}}) command
203216
and checks that it gives the expected response. Any unexpected response
204-
or exception indicates an unhealthy server. Although `EchoHealthCheck` is
217+
or exception indicates an unhealthy server. Although `PingHealthCheck` is
205218
very simple, it is a good basic approach for most Redis deployments.
206219

207220
### `LagAwareHealthCheck` (Redis Enterprise only) {#lag-aware-health-check}
@@ -279,30 +292,30 @@ instance of your custom class to the `health_check` list in
279292
the `MultiDbConfig` constructor, as with [`LagAwareHealthCheck`](#lag-aware-health-check).
280293

281294
The example below
282-
shows a simple custom strategy that sends a Redis [`PING`]({{< relref "/commands/ping" >}})
283-
command and checks for the expected `PONG` response.
295+
shows a simple custom strategy that sends a Redis [`ECHO`]({{< relref "/commands/echo" >}})
296+
command and checks for the expected response.
284297

285298
```py
286299
from redis.multidb.healthcheck import AbstractHealthCheck
287300
from redis.retry import Retry
288301
from redis.utils import dummy_fail
289302

290-
class PingHealthCheck(AbstractHealthCheck):
303+
class EchoHealthCheck(AbstractHealthCheck):
291304
def __init__(self, retry: Retry):
292305
super().__init__(retry=retry)
293306
def check_health(self, database) -> bool:
294307
return self._retry.call_with_retry(
295-
lambda: self._returns_pong(database),
308+
lambda: self._returns_echo(database),
296309
lambda _: dummy_fail()
297310
)
298-
def _returns_pong(self, database) -> bool:
299-
expected_message = ["PONG", b"PONG"]
300-
actual_message = database.client.execute_command("PING")
311+
def _returns_echo(self, database) -> bool:
312+
expected_message = ["Yodel-Ay-Ee-Oooo!", b"Yodel-Ay-Ee-Oooo!"]
313+
actual_message = database.client.execute_command("ECHO", "Yodel-Ay-Ee-Oooo!")
301314
return actual_message in expected_message
302315

303316
cfg = MultiDbConfig(
304317
...
305-
health_check=[PingHealthCheck(retry=Retry(retries=3))],
318+
health_check=[EchoHealthCheck(retry=Retry(retries=3))],
306319
...
307320
)
308321

0 commit comments

Comments
 (0)