2

I was using lettuce client as a Redis cluster client because it supports Cluster Redis well.

A practical problem I have met is when creating a client or during topological refresh, lettuce will send out "info" command, which usually takes longer than normal get command. Setting a general timeout, for example, 10ms, will cause the client failed to start.

I was wondering if I could set the command timeout based on different command types.

Update: I have read the source code and found out that I could write my own TimeoutSource to set the timeout on command level.

I am posting this question because I have communicated with Mark, the author of Lettuce. We thought it would be helpful to share this issue on the broader community as people could someday meet the same issue.

Qiao Feng
  • 21
  • 2

1 Answers1

1

TL; DR

It's possible through TimeoutOptions and specifically a TimeoutSource.

Details

Lettuce provides since version 5.1 a configuration option to apply either the configured connection timeout, a fixed timeout (not related to the connection timeout) or a per-command timeout.

The entrypoint to configure timeouts is TimeoutOptions that can be supplied via ClientOptions.

  • TimeoutOptions.enabled(Duration) uses a fixed timeout.
  • TimeoutOptions.enabled() applies the connection timeout.
  • TimeoutOptions.builder().timeoutSource(TimeoutSource).build() uses the provided TimeoutSource to determine a timeout on RedisCommand level.

If you implement TimeoutSource then you can decide on a given RedisCommand what timeout to apply.

mp911de
  • 17,546
  • 2
  • 55
  • 95