Skip to content

Commit 6acf4f6

Browse files
DOC-5716 updated Lettuce API in example
1 parent 6e59690 commit 6acf4f6

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

content/develop/clients/lettuce/connect.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ lets a client take action to avoid disruptions in service.
264264
See [Smart client handoffs]({{< relref "/develop/clients/sch" >}})
265265
for more information about SCH.
266266

267-
To enable SCH on the client, create a `MaintenanceEventsOptions` object
268-
and pass it to the `ClientOptions` builder using the `supportMaintenanceEvents()` method:
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:
269270

270271
```java
271272
import io.lettuce.core.*;
@@ -275,20 +276,51 @@ import io.lettuce.core.protocol.ProtocolVersion;
275276
// ...
276277

277278
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
278-
279-
MaintenanceEventsOptions maintOptions = MaintenanceEventsOptions.builder()
280-
// You can also pass `false` as a parameter to `supportMaintenanceEvents()`
281-
// to explicitly disable SCH.
282-
.supportMaintenanceEvents()
283-
.build();
279+
280+
MaintNotificationsConfig maintNotificationsConfig = MaintNotificationsConfig.builder()
281+
.enableMaintNotifications()
282+
// .autoResolveEndpointType() // default is auto-resolve
283+
.endpointType(EndpointType.INTERNAL_IP)
284+
.build();
285+
286+
TimeoutOptions timeoutOptions = TimeoutOptions.builder()
287+
.relaxedTimeoutsDuringMaintenance( Duration.ofSeconds(10))
288+
.build();
284289

285290
ClientOptions clientOptions = ClientOptions.builder()
286-
.supportMaintenanceEvents(maintOptions)
287-
.build();
291+
.maintNotificationsConfig(maintNotificationsConfig)
292+
.timeoutOptions(timeoutOptions)
293+
.build();
288294

289295
redisClient.setOptions(clientOptions);
290296

291-
try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
292-
// ...
293-
// ...
297+
// or
298+
ClientOptions clientOptions = ClientOptions.builder()
299+
.maintNotificationsConfig(MaintNotificationsConfig.enabled(EndpointType.INTERNAL_IP))
300+
.build();
301+
302+
redisClient.setOptions(clientOptions);
303+
304+
// or
305+
ClientOptions clientOptions = ClientOptions.builder()
306+
.maintNotificationsConfig(MaintNotificationsConfig.enabled())
307+
.build();
308+
309+
redisClient.setOptions(clientOptions);
294310
```
311+
312+
The `MaintNotificationsConfig` builder accepts the following options:
313+
314+
| Method | Description |
315+
|--------|-------------|
316+
| `enableMaintNotifications()` | Enable SCH. |
317+
| `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). |
318+
| `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. |
319+
320+
Among other options, the `TimeoutOptions` builder accepts the following option
321+
that is relevant to SCH:
322+
323+
| Method | Description |
324+
|--------|-------------|
325+
| `relaxedTimeoutsDuringMaintenance(Duration duration)` | Set the timeout to use while the server is performing maintenance. The default is 10 seconds. |
326+
|

0 commit comments

Comments
 (0)