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
+29-16Lines changed: 29 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ failing back to that server even if it is not optimal.
82
82
83
83
redis-py periodically runs a "health check" on each server to see if it has recovered.
84
84
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
86
86
that it gives the expected response.
87
87
88
88
You can also configure redis-py to run health checks on the current target
@@ -131,13 +131,26 @@ constructor in the `databases_config` parameter.
131
131
132
132
| Option | Description |
133
133
| --- | --- |
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). |
135
135
|`from_url`| Redis URL to connect to this endpoint, as an alternative to passing the host and port in `client_kwargs`. |
136
136
|`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) |
137
137
|`weight`| Priority of the endpoint, with higher values being tried first. Default is `1.0`. |
138
138
|`grace_period`| Duration in seconds to keep an unhealthy endpoint disabled before attempting a failback. Default is `60` seconds. |
139
139
|`health_check_url`| URL for health checks that use the database's REST API (see [`LagAwareHealthCheck`](#lag-aware-health-check) for more information). |
140
140
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
+
141
154
### Retry configuration
142
155
143
156
`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(
159
172
### Health check configuration
160
173
161
174
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
163
176
using a configurable policy to determine if the database is healthy. `MultiDbConfig` provides the following options to configure the health check behavior:
164
177
165
178
| Option | Description |
@@ -168,7 +181,7 @@ using a configurable policy to determine if the database is healthy. `MultiDbCon
168
181
|`health_check_probes`| Number of separate probes performed during each health check. Default is `3`. |
169
182
|`health_check_probes_delay`| Delay between probes during a health check. Default is `0.5` seconds. |
170
183
|`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). |
172
185
173
186
### Circuit breaker configuration
174
187
@@ -196,12 +209,12 @@ There are several strategies available for health checks that you can configure
196
209
`MultiClusterClientConfig` builder. The sections below explain these strategies
197
210
in more detail.
198
211
199
-
### `EchoHealthCheck` (default)
212
+
### `PingHealthCheck` (default)
200
213
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
203
216
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
205
218
very simple, it is a good basic approach for most Redis deployments.
0 commit comments