Package me.ahoo.cosid.store.redis
Class LettuceRedisScripts
java.lang.Object
me.ahoo.cosid.store.redis.LettuceRedisScripts
- All Implemented Interfaces:
RedisScripts
RedisScripts on a Lettuce connection, standalone or Redis Cluster (06-stores.md ยง2.2).
Each call waits at most the timeout for its reply. With replicas > 0 it then runs
WAIT replicas timeout on the same connection (in a cluster: the connection to the node of the keys, the one
that ran the script) and fails with RedisStoreException when fewer replicas acknowledged. WAIT
blocks the connection it runs on, so give this class a connection of its own, never a shared multiplexed one: the
RedisStoreProvider does.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intconnectedReplicas(io.lettuce.core.api.StatefulRedisConnection<String, String> connection, Duration timeout) The replicas connected to the server, fromINFO replication: whatwait=autowaits for.Runs a script, by its SHA-1 digest when Redis has it cached and by its text otherwise (NOSCRIPT).static intfewestReplicas(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<String, String> connection, Duration timeout) The fewest replicas any primary of the cluster has: whatwait=autowaits for (capped at 1 by the provider).static LettuceRedisScriptsof(io.lettuce.core.api.StatefulRedisConnection<String, String> connection, Duration timeout, int replicas) Scripts on a standalone (or primary) connection.static LettuceRedisScriptsof(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<String, String> connection, Duration timeout, int replicas) Scripts on a Redis Cluster connection; the keys of a call share a hash tag, so it runs on one node.intreplicas()How many replicas must acknowledge each write.
-
Method Details
-
of
public static LettuceRedisScripts of(io.lettuce.core.api.StatefulRedisConnection<String, String> connection, Duration timeout, int replicas) Scripts on a standalone (or primary) connection.- Parameters:
connection- the connection, UTF-8 string codectimeout- how long a call waits for each reply, and theWAITtimeoutreplicas- how many replicas must acknowledge each write; 0 runs noWAIT- Returns:
- the scripts
-
of
public static LettuceRedisScripts of(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<String, String> connection, Duration timeout, int replicas) Scripts on a Redis Cluster connection; the keys of a call share a hash tag, so it runs on one node.- Parameters:
connection- the connection, UTF-8 string codectimeout- how long a call waits for each reply, and theWAITtimeoutreplicas- how many replicas of the node must acknowledge each write; 0 runs noWAIT- Returns:
- the scripts
-
connectedReplicas
public static int connectedReplicas(io.lettuce.core.api.StatefulRedisConnection<String, String> connection, Duration timeout) The replicas connected to the server, fromINFO replication: whatwait=autowaits for.- Parameters:
connection- the connectiontimeout- how long to wait for the reply- Returns:
connected_slaves
-
fewestReplicas
public static int fewestReplicas(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<String, String> connection, Duration timeout) The fewest replicas any primary of the cluster has: whatwait=autowaits for (capped at 1 by the provider). Each primary serving slots is asked for its own: the more of its connected replicas (INFO replication, whatWAITcounts) and the replicas the cluster bus knows (CLUSTER REPLICAS, connected or not). The cluster topology alone is not enough: on Redis 7.0 it may list replicas in sync as primaries without slots, soautowould resolve to 0 and neverWAIT. When some primaries have replicas and others none,WAITwould fail every write of the latter, and skipping it would drop the guarantee of the former, so this fails.- Parameters:
connection- the connectiontimeout- how long to wait for each reply- Returns:
- the replica count of the primary with the fewest replicas
- Throws:
RedisStoreException- when no primary serves slots, or some primaries have replicas and others none
-
replicas
public int replicas()How many replicas must acknowledge each write.- Returns:
- the replicas; 0 when no
WAITruns
-
eval
Description copied from interface:RedisScriptsRuns a script, by its SHA-1 digest when Redis has it cached and by its text otherwise (NOSCRIPT).- Specified by:
evalin interfaceRedisScripts- Parameters:
sha- the lower case hex SHA-1 digest ofscriptscript- the Lua scriptkeys- the keys,KEYSof the scriptargs- the arguments,ARGVof the script- Returns:
- the multi-bulk reply of the script; bulk strings as
String, integers asLong
-