Module lettuce.core

Class ReadFrom

java.lang.Object
io.lettuce.core.ReadFrom

public abstract class ReadFrom
extends Object
Defines from which Redis nodes data is read.
Since:
4.0
Author:
Mark Paluch, Ryosuke Hasebe, Omer Cilingir, Yohei Ueki
  • Field Details

    • MASTER

      public static final ReadFrom MASTER
      Setting to read from the upstream only.
    • MASTER_PREFERRED

      public static final ReadFrom MASTER_PREFERRED
      Setting to read preferred from the upstream and fall back to a replica if the master is not available.
    • UPSTREAM

      public static final ReadFrom UPSTREAM
      Setting to read from the upstream only.
      Since:
      6.0
    • UPSTREAM_PREFERRED

      public static final ReadFrom UPSTREAM_PREFERRED
      Setting to read preferred from the upstream and fall back to a replica if the upstream is not available.
      Since:
      6.0
    • REPLICA_PREFERRED

      public static final ReadFrom REPLICA_PREFERRED
      Setting to read preferred from replica and fall back to upstream if no replica is not available.
      Since:
      5.2
    • SLAVE_PREFERRED

      @Deprecated public static final ReadFrom SLAVE_PREFERRED
      Deprecated.
      Renamed to REPLICA_PREFERRED.
      Setting to read preferred from replicas and fall back to upstream if no replica is not available.
      Since:
      4.4
    • REPLICA

      public static final ReadFrom REPLICA
      Setting to read from the replica only.
      Since:
      5.2
    • SLAVE

      @Deprecated public static final ReadFrom SLAVE
      Deprecated.
      renamed to REPLICA.
      Setting to read from the replica only.
    • NEAREST

      public static final ReadFrom NEAREST
      Setting to read from the nearest node.
    • ANY

      public static final ReadFrom ANY
      Setting to read from any node.
      Since:
      5.2
    • ANY_REPLICA

      public static final ReadFrom ANY_REPLICA
      Setting to read from any replica node.
      Since:
      6.0.1
  • Constructor Details

    • ReadFrom

      public ReadFrom()
  • Method Details

    • subnet

      public static ReadFrom subnet​(String... cidrNotations)
      Setting to read from any node in the subnets.
      Parameters:
      cidrNotations - CIDR-block notation strings, e.g., "192.168.0.0/16", "2001:db8:abcd:0000::/52". Must not be null.
      Returns:
      an instance of ReadFromImpl.ReadFromSubnet.
      Since:
      6.1
    • regex

      public static ReadFrom regex​(Pattern pattern)
      Read from any node that has RedisURI matching with the given pattern.
      Parameters:
      pattern - regex pattern, e.g., Pattern.compile(".*region-1.*"). Must not be null.
      Returns:
      an instance of ReadFromImpl.ReadFromRegex.
      Since:
      6.1
    • regex

      public static ReadFrom regex​(Pattern pattern, boolean orderSensitive)
      Read from any node that has RedisURI matching with the given pattern.
      Parameters:
      pattern - regex pattern, e.g., Pattern.compile(".*region-1.*"). Must not be null.
      orderSensitive - true to attempt reads in the order of hosts returned by select(Nodes); false to apply randomization.
      Returns:
      an instance of ReadFromImpl.ReadFromRegex.
      Since:
      6.1
    • select

      public abstract List<RedisNodeDescription> select​(ReadFrom.Nodes nodes)
      Chooses the nodes from the matching Redis nodes that match this read selector.
      Parameters:
      nodes - set of nodes that are suitable for reading
      Returns:
      List of RedisNodeDescriptions that are selected for reading
    • isOrderSensitive

      protected boolean isOrderSensitive()
      Returns whether this ReadFrom requires ordering of the resulting nodes.
      Returns:
      true if code using ReadFrom should retain ordering or false to allow reordering of nodes.
      Since:
      5.2
    • valueOf

      public static ReadFrom valueOf​(String name)
      Retrieve the ReadFrom preset by name.
      Parameters:
      name - the name of the read from setting
      Returns:
      the ReadFrom preset
      Throws:
      IllegalArgumentException - if name is empty, null or the ReadFrom preset is unknown.