Module lettuce.core

Class RedisClusterNode

java.lang.Object
io.lettuce.core.cluster.models.partitions.RedisClusterNode
All Implemented Interfaces:
RedisInstance, RedisNodeDescription, Serializable

public class RedisClusterNode
extends Object
implements Serializable, RedisNodeDescription
Representation of a Redis Cluster node. A RedisClusterNode is identified by its nodeId.

A RedisClusterNode can be a responsible master or replica. Masters can be responsible for zero to 16384 slots. Each replica refers to exactly one master. Nodes can have different flags assigned.

This class is mutable and not thread-safe if mutated by multiple threads concurrently.

Since:
3.0
Author:
Mark Paluch, Alessandro Simi
See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • of

      public static RedisClusterNode of​(String nodeId)
      Create a new instance of RedisClusterNode by passing the nodeId
      Parameters:
      nodeId - the nodeId
      Returns:
      a new instance of RedisClusterNode
    • clone

      public RedisClusterNode clone()
      Clone this RedisClusterNode.
      Overrides:
      clone in class Object
      Returns:
      a copy of this RedisClusterNode.
    • getUri

      public RedisURI getUri()
      Specified by:
      getUri in interface RedisNodeDescription
      Returns:
      the URI of the node
    • setUri

      public void setUri​(RedisURI uri)
      Sets the connection point details. Usually the host/ip/port where a particular Redis Cluster node server is running.
      Parameters:
      uri - the RedisURI, must not be null
    • getNodeId

      public String getNodeId()
    • setNodeId

      public void setNodeId​(String nodeId)
      Sets nodeId.
      Parameters:
      nodeId - the nodeId
    • isConnected

      public boolean isConnected()
    • setConnected

      public void setConnected​(boolean connected)
      Sets the connected flag. The connected flag describes whether the node which provided details about the node is connected to the particular RedisClusterNode.
      Parameters:
      connected - the connected flag
    • getSlaveOf

      public String getSlaveOf()
    • setSlaveOf

      public void setSlaveOf​(String slaveOf)
      Sets the replication source.
      Parameters:
      slaveOf - the replication source, can be null
    • getPingSentTimestamp

      public long getPingSentTimestamp()
    • setPingSentTimestamp

      public void setPingSentTimestamp​(long pingSentTimestamp)
      Sets the last pingSentTimestamp.
      Parameters:
      pingSentTimestamp - the last pingSentTimestamp
    • getPongReceivedTimestamp

      public long getPongReceivedTimestamp()
    • setPongReceivedTimestamp

      public void setPongReceivedTimestamp​(long pongReceivedTimestamp)
      Sets the last pongReceivedTimestamp.
      Parameters:
      pongReceivedTimestamp - the last pongReceivedTimestamp
    • getConfigEpoch

      public long getConfigEpoch()
    • setConfigEpoch

      public void setConfigEpoch​(long configEpoch)
      Sets the configEpoch.
      Parameters:
      configEpoch - the configEpoch
    • getSlots

      public List<Integer> getSlots()
      Return the slots as List. Note that this method creates a new List for each time it gets called.
      Returns:
      the slots as List.
    • forEachSlot

      public void forEachSlot​(IntConsumer consumer)
      Performs the given action for each slot of this RedisClusterNode until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.
      Parameters:
      consumer -
      Since:
      5.2
    • setSlots

      public void setSlots​(List<Integer> slots)
      Sets the list of slots for which this RedisClusterNode is the RedisClusterNode.NodeFlag.UPSTREAM. The list is empty if this node is not a upstream or the node is not responsible for any slots at all.
      Parameters:
      slots - list of slots, must not be null but may be empty
    • hasSameSlotsAs

      public boolean hasSameSlotsAs​(RedisClusterNode other)
      Return true if the other node contains the same slots as this node.
      Parameters:
      other - the node to compare with.
      Returns:
      true if the other node contains the same slots as this node.
    • getFlags

      public Set<RedisClusterNode.NodeFlag> getFlags()
      Return the NodeFlags.
      Returns:
      the NodeFlags.
    • setFlags

      public void setFlags​(Set<RedisClusterNode.NodeFlag> flags)
      Set of node flags.
      Parameters:
      flags - the set of node flags.
    • is

      public boolean is​(RedisClusterNode.NodeFlag nodeFlag)
      Parameters:
      nodeFlag - the node flag
      Returns:
      true if the RedisClusterNode.NodeFlag is contained within the flags.
    • addAlias

      public void addAlias​(RedisURI alias)
      Add an alias to RedisClusterNode.
      Parameters:
      alias - must not be null.
    • getAliases

      public List<RedisURI> getAliases()
    • hasSlot

      public boolean hasSlot​(int slot)
      Parameters:
      slot - the slot hash
      Returns:
      true if the slot is contained within the handled slots.
    • getRole

      public RedisInstance.Role getRole()
      Returns the RedisInstance.Role of the Redis Cluster node based on the flags.
      Specified by:
      getRole in interface RedisInstance
      Returns:
      the Redis Cluster node role
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object