Class RedisCommandTimeout
StringRedisTemplate has no per-call timeout: a blocked command waits
for the connection factory's command timeout (60s by default for Lettuce). Machine id guarding runs on a single
thread, so one hung command stalls it. When enabled, the command runs on a daemon worker and the caller gives up
after getTimeout(), interrupting the worker and throwing RedisCommandTimeoutException.
It bounds the steady-state commands (machine id guard and revert, segment nextMaxId). The first command
at startup (machine id distribution, segment offset initialization) is left unbounded: on a cold JVM it pays for
connecting and class loading, which can take about a second even against a local Redis.
A timed-out command may still have been applied on the server. That is safe for CosId's commands: a lost segment increment only leaves a gap, and machine id distribution is idempotent per instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Durationstatic final intUpper bound of concurrently running commands, shared with the otherCallTimeoutusers.static final RedisCommandTimeoutNo timeout: commands run on the caller thread, as before. -
Method Summary
Modifier and TypeMethodDescription<T> TRun a Redis command within the timeout.booleanstatic RedisCommandTimeoutCreate a command timeout.voidtoString()
-
Field Details
-
DEFAULT_TIMEOUT
-
NONE
No timeout: commands run on the caller thread, as before. -
MAX_CONCURRENT_COMMANDS
public static final int MAX_CONCURRENT_COMMANDSUpper bound of concurrently running commands, shared with the otherCallTimeoutusers. Beyond it, callers fail fast instead of piling up threads behind a hung Redis.- See Also:
-
-
Method Details
-
of
Create a command timeout.- Parameters:
timeout- timeout of each command,nullor zero means no timeout- Returns:
- command timeout
-
getTimeout
-
isEnabled
public boolean isEnabled() -
call
Run a Redis command within the timeout.- Type Parameters:
T- result type- Parameters:
operation- name of the operation, used in the timeout messagecommand- the Redis command- Returns:
- the command result
-
run
-
toString
-