@@ -29,6 +29,7 @@ progress in implementing the recommendations.
29
29
{{< checklist-item "#cluster-topology-refresh">}}Cluster topology refresh{{< /checklist-item >}}
30
30
{{< checklist-item "#dns-cache-and-redis" >}}DNS cache and Redis{{< /checklist-item >}}
31
31
{{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
32
+ {{< checklist-item "#connection-and-execution-reliability" >}}Connection and execution reliability{{< /checklist-item >}}
32
33
{{< /checklist >}}
33
34
34
35
## Recommendations
@@ -189,3 +190,51 @@ See the Error handling sections of the
189
190
[ Lettuce async] ( https://redis.github.io/lettuce/user-guide/async-api/#error-handling ) and
190
191
[ Lettuce reactive] ( https://redis.github.io/lettuce/user-guide/reactive-api/#error-handling )
191
192
API guides to learn more about handling exceptions.
193
+
194
+
195
+ ## Connection and execution reliability
196
+
197
+ By default, Lettuce uses an * at-least-once* strategy for command execution.
198
+ It will automatically reconnect after a disconnection and resume executing
199
+ any commands that were queued when the connection was lost. If you
200
+ switch to * at-most-once* execution, Lettuce will
201
+ not reconnect after a disconnection and will discard commands
202
+ instead of queuing them. You can enable at-most-once execution by setting
203
+ ` autoReconnect(false) ` in the
204
+ ` ClientOptions ` when you create the client, as shown in the example below:
205
+
206
+ ``` java
207
+ RedisURI uri = RedisURI . Builder
208
+ .redis(" localhost" , 6379 )
209
+ .withAuthentication(" default" , " yourPassword" )
210
+ .build();
211
+
212
+ RedisClient client = RedisClient . create(uri);
213
+
214
+ client. setOptions(ClientOptions . builder()
215
+ .autoReconnect(false )
216
+ .
217
+ .
218
+ .build());
219
+ ```
220
+
221
+ If you need finer control over which commands you want to execute in which mode, you can
222
+ configure a * replay filter* to choose the commands that should retry after a disconnection.
223
+ The example below shows a filter that retries all commands except for
224
+ [ ` DECR ` ] ({{< relref "/commands/decr" >}})
225
+ (this command is not [ idempotent] ( https://en.wikipedia.org/wiki/Idempotence ) and
226
+ so you might need to avoid executing it more than once). Note that
227
+ replay filters are only available in in Lettuce v6.6 and above.
228
+
229
+ ``` java
230
+ Predicate<RedisCommand<?, ?, ?> > filter =
231
+ cmd - > cmd. getType(). toString(). equalsIgnoreCase(" DECR" );
232
+
233
+ client. setOptions(ClientOptions . builder()
234
+ .replayFilter(filter)
235
+ .build());
236
+ ```
237
+
238
+ See
239
+ [ Command execution reliability] ( https://redis.github.io/lettuce/advanced-usage/#command-execution-reliability )
240
+ in the Lettuce reference guide for more information.
0 commit comments