Class LettuceRedisScripts

java.lang.Object
me.ahoo.cosid.store.redis.LettuceRedisScripts
All Implemented Interfaces:
RedisScripts

public final class LettuceRedisScripts extends Object implements 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 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 codec
      timeout - how long a call waits for each reply, and the WAIT timeout
      replicas - how many replicas must acknowledge each write; 0 runs no WAIT
      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 codec
      timeout - how long a call waits for each reply, and the WAIT timeout
      replicas - how many replicas of the node must acknowledge each write; 0 runs no WAIT
      Returns:
      the scripts
    • connectedReplicas

      public static int connectedReplicas(io.lettuce.core.api.StatefulRedisConnection<String,String> connection, Duration timeout)
      The replicas connected to the server, from INFO replication: what wait=auto waits for.
      Parameters:
      connection - the connection
      timeout - 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: what wait=auto waits for (capped at 1 by the provider). Each primary serving slots is asked for its own: the more of its connected replicas (INFO replication, what WAIT counts) 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, so auto would resolve to 0 and never WAIT. When some primaries have replicas and others none, WAIT would fail every write of the latter, and skipping it would drop the guarantee of the former, so this fails.
      Parameters:
      connection - the connection
      timeout - 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 WAIT runs
    • eval

      public List<Object> eval(String sha, String script, List<String> keys, List<String> args)
      Description copied from interface: RedisScripts
      Runs a script, by its SHA-1 digest when Redis has it cached and by its text otherwise (NOSCRIPT).
      Specified by:
      eval in interface RedisScripts
      Parameters:
      sha - the lower case hex SHA-1 digest of script
      script - the Lua script
      keys - the keys, KEYS of the script
      args - the arguments, ARGV of the script
      Returns:
      the multi-bulk reply of the script; bulk strings as String, integers as Long