Class 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 Detail

      • 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 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 available.
        Since:
        4.4
      • REPLICA

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

        public static final ReadFrom LOWEST_LATENCY
        Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and latencies from all nodes in the cluster.
        Since:
        6.1.7
      • NEAREST

        @Deprecated
        public static final ReadFrom NEAREST
        Deprecated.
        since 6.1.7 as we're renaming this setting to LOWEST_LATENCY for more clarity what this setting actually represents.
        Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and latencies from all nodes in the cluster.
      • 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 Detail

      • ReadFrom

        public ReadFrom()
    • Method Detail

      • 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