Skip to content

Commit d7eb4af

Browse files
Merge pull request #2120 from redis/DOC-5712-python-seamless-section
DOC-5711 DOC-5712 DOC-5713 DOC-5714 DOC-5716 Smart client handoffs docs
2 parents 9a5e3fa + 3787298 commit d7eb4af

File tree

10 files changed

+318
-1
lines changed

10 files changed

+318
-1
lines changed

content/develop/clients/go/connect.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,45 @@ if err != nil {
126126
}
127127
fmt.Println("foo", val)
128128
```
129+
130+
## Connect using Smart client handoffs (SCH)
131+
132+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
133+
Redis Enterprise servers that lets them actively notify clients
134+
about planned server maintenance shortly before it happens. This
135+
lets a client take action to avoid disruptions in service.
136+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
137+
for more information about SCH.
138+
139+
To enable SCH on the client, add the `MaintNotificationsConfig` option during the
140+
connection, as shown in the following example:
141+
142+
```go
143+
rdb := redis.NewClient(&redis.Options{
144+
Addr: "localhost:6379",
145+
Protocol: 3, // RESP3 required
146+
MaintNotificationsConfig: &maintnotifications.Config{
147+
Mode: maintnotifications.ModeEnabled,
148+
EndpointType: maintnotifications.EndpointTypeExternalIP,
149+
HandoffTimeout: 10 * time.Second,
150+
RelaxedTimeout: 10 * time.Second,
151+
PostHandoffRelaxedDuration: 10 * time.Second,
152+
MaxHandoffRetries: 5,
153+
},
154+
})
155+
```
156+
157+
{{< note >}}SCH requires the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
158+
protocol, so you must set `Protocol:3` explicitly when you connect.
159+
{{< /note >}}
160+
161+
The `maintnotifications.Config` object accepts the following parameters:
162+
163+
| Name | Description |
164+
|------ |------------- |
165+
| `Mode` | Whether or not to enable SCH. The options are `ModeDisabled`, `ModeEnabled` (require SCH and abort the connection if not supported), and `ModeAuto` (require SCH and fall back to a non-SCH connection if not supported). The default is `ModeAuto`. |
166+
| `EndpointType` | The type of endpoint to use for the connection. The options are `EndpointTypeExternalIP`, `EndpointTypeInternalIP`, `EndpointTypeExternalFQDN`, `EndpointTypeInternalFQDN`, `EndpointTypeAuto` (auto-detect based on connection), and `EndpointTypeNone` (reconnect with current config). The default is `EndpointTypeExternalIP`. |
167+
| `HandoffTimeout` | The timeout to connect to the replacement node. The default is 15 seconds. |
168+
| `RelaxedTimeout` | The timeout to use for commands and connections while the server is performing maintenance. The default is 10 seconds. |
169+
| `PostHandoffRelaxedDuration` | The duration to continue using relaxed timeouts after a successful handoff (this provides extra resilience during cluster transitions). The default is 20 seconds. |
170+
| `MaxHandoffRetries` | The maximum number of times to retry connecting to the replacement node. The default is 3. |

content/develop/clients/go/produsage.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ progress in implementing the recommendations.
3030
{{< checklist-item "#monitor-performance-and-errors">}}Monitor performance and errors{{< /checklist-item >}}
3131
{{< checklist-item "#retries" >}}Retries{{< /checklist-item >}}
3232
{{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
33+
{{< checklist-item "#seamless-client-experience" >}}Smart client handoffs{{< /checklist-item >}}
3334
{{< /checklist >}}
3435

3536
## Recommendations
@@ -122,3 +123,15 @@ for your application. If timeouts are set too short, then `go-redis`
122123
might retry commands that would have succeeded if given more time. However,
123124
if they are too long, your app might hang unnecessarily while waiting for a
124125
response that will never arrive.
126+
127+
### Smart client handoffs
128+
129+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
130+
Redis Enterprise servers that lets them actively notify clients
131+
about planned server maintenance shortly before it happens. This
132+
lets a client take action to avoid disruptions in service.
133+
134+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
135+
for more information about SCH and
136+
[Connect using Smart client handoffs]({{< relref "/develop/clients/go/connect#connect-using-smart-client-handoffs-sch" >}})
137+
for example code.

content/develop/clients/lettuce/connect.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,74 @@ public class Pool {
254254
```
255255

256256
In this setup, `LettuceConnectionFactory` is a custom class you would need to implement, adhering to Apache Commons Pool's `PooledObjectFactory` interface, to manage lifecycle events of pooled `StatefulRedisConnection` objects.
257+
258+
## Connect using Smart client handoffs (SCH)
259+
260+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
261+
Redis Enterprise servers that lets them actively notify clients
262+
about planned server maintenance shortly before it happens. This
263+
lets a client take action to avoid disruptions in service.
264+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
265+
for more information about SCH.
266+
267+
To enable SCH on the client, create a `MaintNotificationsConfig` object
268+
and/or a `TimeoutOptions` object
269+
and pass them to the `ClientOptions` builder as shown in the example below:
270+
271+
```java
272+
import io.lettuce.core.*;
273+
import io.lettuce.core.api.StatefulRedisConnection;
274+
import io.lettuce.core.protocol.ProtocolVersion;
275+
import java.time.Duration;
276+
// ...
277+
// ...
278+
279+
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
280+
281+
MaintNotificationsConfig maintNotificationsConfig = MaintNotificationsConfig.builder()
282+
.enableMaintNotifications()
283+
// .autoResolveEndpointType() // default is auto-resolve
284+
.endpointType(EndpointType.INTERNAL_IP)
285+
.build();
286+
287+
TimeoutOptions timeoutOptions = TimeoutOptions.builder()
288+
.relaxedTimeoutsDuringMaintenance(Duration.ofSeconds(10))
289+
.build();
290+
291+
ClientOptions clientOptions = ClientOptions.builder()
292+
.maintNotificationsConfig(maintNotificationsConfig)
293+
.timeoutOptions(timeoutOptions)
294+
.build();
295+
296+
redisClient.setOptions(clientOptions);
297+
298+
// or
299+
ClientOptions clientOptions = ClientOptions.builder()
300+
.maintNotificationsConfig(MaintNotificationsConfig.enabled(EndpointType.INTERNAL_IP))
301+
.build();
302+
303+
redisClient.setOptions(clientOptions);
304+
305+
// or
306+
ClientOptions clientOptions = ClientOptions.builder()
307+
.maintNotificationsConfig(MaintNotificationsConfig.enabled())
308+
.build();
309+
310+
redisClient.setOptions(clientOptions);
311+
```
312+
313+
The `MaintNotificationsConfig` builder accepts the following options:
314+
315+
| Method | Description |
316+
|--------|-------------|
317+
| `enableMaintNotifications()` | Enable SCH. |
318+
| `endpointType(EndpointType type)` | Set the type of endpoint to use for the connection. The options are `EndpointType.EXTERNAL_IP`, `EndpointType.INTERNAL_IP`, `EndpointType.EXTERNAL_FQDN`, `EndpointType.INTERNAL_FQDN`, and `EndpointType.NONE`. Use the separate `autoResolveEndpointType()` method to auto-detect based on the connection (this is the default behavior). |
319+
| `autoResolveEndpointType()` | Auto-detect the type of endpoint to use for the connection. This is the default behavior. Use `endpointType()` to set a specific endpoint type. |
320+
321+
Among other options, the `TimeoutOptions` builder accepts the following option
322+
that is relevant to SCH:
323+
324+
| Method | Description |
325+
|--------|-------------|
326+
| `relaxedTimeoutsDuringMaintenance(Duration duration)` | Set the timeout to use while the server is performing maintenance. The default is 10 seconds. |
327+
|

content/develop/clients/lettuce/produsage.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ progress in implementing the recommendations.
3030
{{< checklist-item "#dns-cache-and-redis" >}}DNS cache and Redis{{< /checklist-item >}}
3131
{{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
3232
{{< checklist-item "#connection-and-execution-reliability" >}}Connection and execution reliability{{< /checklist-item >}}
33+
{{< checklist-item "#seamless-client-experience" >}}Smart client handoffs{{< /checklist-item >}}
3334
{{< /checklist >}}
3435

3536
## Recommendations
@@ -283,3 +284,15 @@ client.setOptions(ClientOptions.builder()
283284
See
284285
[Command execution reliability](https://redis.github.io/lettuce/advanced-usage/#command-execution-reliability)
285286
in the Lettuce reference guide for more information.
287+
288+
## Smart client handoffs
289+
290+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
291+
Redis Enterprise servers that lets them actively notify clients
292+
about planned server maintenance shortly before it happens. This
293+
lets a client take action to avoid disruptions in service.
294+
295+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
296+
for more information about SCH and
297+
[Connect using Smart client handoffs]({{< relref "/develop/clients/lettuce/connect#connect-using-smart-client-handoffs-sch" >}})
298+
for example code.

content/develop/clients/nodejs/connect.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,51 @@ createClient({
329329
});
330330
```
331331

332+
## Connect using Smart client handoffs (SCH)
333+
334+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
335+
Redis Enterprise servers that lets them actively notify clients
336+
about planned server maintenance shortly before it happens. This
337+
lets a client take action to avoid disruptions in service.
338+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
339+
for more information about SCH.
340+
341+
Use the configuration options shown in the example below to enable SCH
342+
during the connection:
343+
344+
```js
345+
const client = createClient({
346+
RESP: 3,
347+
maintNotifications: 'auto',
348+
maintEndpointType: 'auto',
349+
maintRelaxedCommandTimeout: 10000,
350+
maintRelaxedSocketTimeout: 10000,
351+
...
352+
});
353+
```
354+
355+
{{< note >}}SCH requires the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
356+
protocol, so you must set the `RESP:3` option explicitly when you connect.
357+
{{< /note >}}
358+
359+
The available options are:
360+
361+
- `maintNotifications`: (`string`) Whether or not to enable SCH. The options are
362+
- `'disabled'`: don't use SCH
363+
- `'enabled'`: attempt to activate SCH on the server and abort the connection if it isn't supported
364+
- `'auto'`: attempt to activate SCH on the server and fall back to a non-SCH
365+
connection if it isn't supported. This is the default.
366+
- `maintEndpointType`: (`MovingEndpointType`) The type of endpoint to use for the connection. The options are:
367+
- `'external-ip'`: use the external IP address of the server
368+
- `'internal-ip'`: use the internal IP address of the server
369+
- `'external-fqdn'`: use the external FQDN of the server
370+
- `'internal-fqdn'`: use the internal FQDN of the server
371+
- `'auto'`: auto-detect based on connection. This is the default.
372+
- `maintRelaxedCommandTimeout`: (`number`) The command timeout to use while the server is
373+
performing maintenance. The default is 10000 (10 seconds). If a timeout happens during the maintenance period, the client receives a `CommandTimeoutDuringMaintenance` error.
374+
- `maintRelaxedSocketTimeout`: (`number`) The socket timeout to use while the server is
375+
performing maintenance. The default is 10000 (10 seconds). If a timeout happens during the maintenance period, the client receives a `SocketTimeoutDuringMaintenance` error.
376+
332377
## Connection events
333378

334379
The client object emits the following

content/develop/clients/nodejs/produsage.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ progress in implementing the recommendations.
2929
{{< checklist-item "#handling-reconnections" >}}Handling reconnections{{< /checklist-item >}}
3030
{{< checklist-item "#connection-timeouts" >}}Connection timeouts{{< /checklist-item >}}
3131
{{< checklist-item "#command-execution-reliability" >}}Command execution reliability{{< /checklist-item >}}
32+
{{< checklist-item "#seamless-client-experience" >}}Smart client handoffs{{< /checklist-item >}}
3233
{{< /checklist >}}
3334

3435
## Recommendations
@@ -105,3 +106,15 @@ const client = createClient({
105106

106107
Use a separate connection with the queue disabled if you want to avoid queuing
107108
only for specific commands.
109+
110+
### Smart client handoffs
111+
112+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
113+
Redis Enterprise servers that lets them actively notify clients
114+
about planned server maintenance shortly before it happens. This
115+
lets a client take action to avoid disruptions in service.
116+
117+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
118+
for more information about SCH and
119+
[Connect using Smart client handoffs]({{< relref "/develop/clients/nodejs/connect#connect-using-smart-client-handoffs-sch" >}})
120+
for example code.

content/develop/clients/patterns/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description: Novel patterns for working with Redis data structures
1313
linkTitle: Coding patterns
1414
title: Coding patterns
1515
aliases: /develop/use/patterns
16-
weight: 50
16+
weight: 60
1717
---
1818

1919
The following documents describe some novel development patterns you can use with Redis.

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,45 @@ a simple retry strategy by default, but there are various ways you can customize
252252
this behavior to suit your use case. See
253253
[Retries]({{< relref "/develop/clients/redis-py/produsage#retries" >}})
254254
for more information about custom retry strategies, with example code.
255+
256+
## Connect using Smart client handoffs (SCH)
257+
258+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
259+
Redis Enterprise servers that lets them actively notify clients
260+
about planned server maintenance shortly before it happens. This
261+
lets a client take action to avoid disruptions in service.
262+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
263+
for more information about SCH.
264+
265+
To enable SCH on the client, pass a `MaintNotificationsConfig` object
266+
during the connection, as shown in the following example:
267+
268+
```py
269+
import redis
270+
from redis.maint_notifications import MaintNotificationsConfig, EndpointType
271+
272+
r = redis.Redis(
273+
decode_responses=True,
274+
protocol=3,
275+
maint_notifications_config=MaintNotificationsConfig(
276+
enabled=True,
277+
proactive_reconnect=True,
278+
relaxed_timeout=10,
279+
endpoint_type=EndpointType.EXTERNAL_IP
280+
),
281+
...
282+
)
283+
```
284+
285+
{{< note >}}SCH requires the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
286+
protocol, so you must set `protocol=3` explicitly when you connect.
287+
{{< /note >}}
288+
289+
The `MaintNotificationsConfig` constructor accepts the following parameters:
290+
291+
| Name | Type | Default | Description |
292+
|------|------|---------|-------------|
293+
| `enabled` | `bool` | `False` | Whether or not to enable SCH. |
294+
| `proactive_reconnect` | `bool` | `True` | Whether or not to automatically reconnect when a node is replaced. |
295+
| `endpoint_type` | `EndpointType` | Auto-detect | The type of endpoint to use for the connection. The options are `EndpointType.EXTERNAL_IP`, `EndpointType.INTERNAL_IP`, `EndpointType.EXTERNAL_FQDN`, `EndpointType.INTERNAL_FQDN`, and `EndpointType.NONE`. |
296+
| `relaxed_timeout` | `int` | `20` | The timeout (in seconds) to use while the server is performing maintenance. A value of `-1` disables the relax timeout and just uses the normal timeout during maintenance. |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ progress in implementing the recommendations.
3030
{{< checklist-item "#health-checks" >}}Health checks{{< /checklist-item >}}
3131
{{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
3232
{{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
33+
{{< checklist-item "#seamless-client-experience" >}}Smart client handoffs{{< /checklist-item >}}
3334
{{< /checklist >}}
3435

3536
## Recommendations
@@ -197,3 +198,15 @@ If you use timeouts that are too short, then `redis-py` might retry
197198
commands that would have succeeded if given more time. However, if the
198199
timeouts are too long, your app might hang unnecessarily while waiting for a
199200
response that will never arrive.
201+
202+
### Smart client handoffs
203+
204+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
205+
Redis Enterprise servers that lets them actively notify clients
206+
about planned server maintenance shortly before it happens. This
207+
lets a client take action to avoid disruptions in service.
208+
209+
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
210+
for more information about SCH and
211+
[Connect using Smart client handoffs]({{< relref "/develop/clients/redis-py/connect#connect-using-smart-client-handoffs-sch" >}})
212+
for example code.

content/develop/clients/sch.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
categories:
3+
- docs
4+
- develop
5+
- stack
6+
- oss
7+
- rs
8+
- rc
9+
- oss
10+
- kubernetes
11+
- clients
12+
description: Learn how to avoid disruptions during Redis server maintenance.
13+
linkTitle: Smart client handoffs
14+
title: Smart client handoffs
15+
weight: 50
16+
---
17+
18+
*Smart client handoffs (SCH)* is a feature of Redis Cloud and
19+
Redis Enterprise servers that lets them actively notify clients
20+
about planned server maintenance shortly before it happens. This
21+
lets a client reconnect or otherwise respond gracefully without significant
22+
interruptions in service.
23+
24+
SCH is primarily useful when server software or hardware upgrades
25+
are required. It provides two main features to help the
26+
client avoid disruptions in service during the maintenance period:
27+
28+
- **Relaxed timeouts**: Upgrades tend to impact the general performance of the server.
29+
Advance notification of the upgrade lets a client adjust its command
30+
timeouts to take this into account and avoid aborting commands too soon.
31+
- **Transparent reconnection**: Upgrades also involve migrating
32+
Redis shards to new nodes, which inevitably disconnects clients from
33+
existing nodes. However, with some advance warning of the disconnection,
34+
a client can buffer commands, connect to a new node, and then resume
35+
the buffered commands without aborting any of them. As a result, users
36+
see no disruption in service.
37+
38+
## Enable SCH
39+
40+
SCH is enabled by default on Redis Cloud, but you must enable it
41+
explicitly on Redis Enterprise servers by using the
42+
[v1/cluster]({{< relref "/operate/rs/references/rest-api/requests/cluster" >}})
43+
REST API request to set the `client_maint_notifications` option to `true`.
44+
The example below shows how to do this using the
45+
[`curl`](https://curl.se/) command line utility:
46+
47+
```bash
48+
curl -k -X PUT -H "accept: application/json" \
49+
-H "content-type: application/json" \
50+
-u "[email protected]:test123" \
51+
-d '{ "client_maint_notifications": true }' \
52+
https://localhost:9443/v1/cluster
53+
```
54+
55+
SCH is enabled automatically on the client side during connection
56+
if you select the [RESP3]({{< relref "/develop/reference/protocol-spec#resp-versions" >}})
57+
protocol, which is a requirement for SCH. However, you can
58+
configure some parameters, such as the timeouts to use
59+
during maintenance.
60+
See the pages linked below to learn how to configure SCH for:
61+
62+
- [redis-py]({{< relref "/develop/clients/redis-py/connect#connect-using-smart-client-handoffs-sch" >}})
63+
- [node-redis]({{< relref "/develop/clients/nodejs/connect#connect-using-smart-client-handoffs-sch" >}})
64+
- [Lettuce]({{< relref "/develop/clients/lettuce/connect#connect-using-smart-client-handoffs-sch" >}})
65+
- [go-redis]({{< relref "/develop/clients/go/connect#connect-using-smart-client-handoffs-sch" >}})

0 commit comments

Comments
 (0)