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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRedisClusterNode.NodeFlagRedis Cluster node flags.Nested classes/interfaces inherited from interface io.lettuce.core.models.role.RedisInstance
RedisInstance.Role -
Constructor Summary
Constructors Constructor Description RedisClusterNode()RedisClusterNode(RedisClusterNode redisClusterNode)RedisClusterNode(RedisURI uri, String nodeId, boolean connected, String slaveOf, long pingSentTimestamp, long pongReceivedTimestamp, long configEpoch, List<Integer> slots, Set<RedisClusterNode.NodeFlag> flags) -
Method Summary
Modifier and Type Method Description voidaddAlias(RedisURI alias)Add an alias toRedisClusterNode.RedisClusterNodeclone()ClonethisRedisClusterNode.booleanequals(Object o)voidforEachSlot(IntConsumer consumer)Performs the given action for each slot of thisRedisClusterNodeuntil all elements have been processed or the action throws an exception.List<RedisURI>getAliases()longgetConfigEpoch()Set<RedisClusterNode.NodeFlag>getFlags()Return theNodeFlags.StringgetNodeId()longgetPingSentTimestamp()longgetPongReceivedTimestamp()RedisInstance.RolegetRole()Returns theRedisInstance.Roleof the Redis Cluster node based on theflags.StringgetSlaveOf()List<Integer>getSlots()Return the slots asList.RedisURIgetUri()inthashCode()booleanhasSameSlotsAs(RedisClusterNode other)booleanhasSlot(int slot)booleanis(RedisClusterNode.NodeFlag nodeFlag)booleanisConnected()static RedisClusterNodeof(String nodeId)Create a new instance ofRedisClusterNodeby passing thenodeIdvoidsetConfigEpoch(long configEpoch)Sets theconfigEpoch.voidsetConnected(boolean connected)Sets theconnectedflag.voidsetFlags(Set<RedisClusterNode.NodeFlag> flags)Set ofnode flags.voidsetNodeId(String nodeId)SetsnodeId.voidsetPingSentTimestamp(long pingSentTimestamp)Sets the lastpingSentTimestamp.voidsetPongReceivedTimestamp(long pongReceivedTimestamp)Sets the lastpongReceivedTimestamp.voidsetSlaveOf(String slaveOf)Sets the replication source.voidsetSlots(List<Integer> slots)Sets the list of slots for which thisRedisClusterNodeis theRedisClusterNode.NodeFlag.UPSTREAM.voidsetUri(RedisURI uri)Sets the connection point details.StringtoString()
-
Constructor Details
-
RedisClusterNode
public RedisClusterNode() -
RedisClusterNode
-
RedisClusterNode
-
-
Method Details
-
of
Create a new instance ofRedisClusterNodeby passing thenodeId- Parameters:
nodeId- the nodeId- Returns:
- a new instance of
RedisClusterNode
-
clone
ClonethisRedisClusterNode.- Overrides:
clonein classObject- Returns:
- a copy of
thisRedisClusterNode.
-
getUri
- Specified by:
getUriin interfaceRedisNodeDescription- Returns:
- the URI of the node
-
setUri
Sets the connection point details. Usually the host/ip/port where a particular Redis Cluster node server is running.- Parameters:
uri- theRedisURI, must not benull
-
getNodeId
-
setNodeId
SetsnodeId.- Parameters:
nodeId- thenodeId
-
isConnected
public boolean isConnected() -
setConnected
public void setConnected(boolean connected)Sets theconnectedflag. Theconnectedflag describes whether the node which provided details about the node is connected to the particularRedisClusterNode.- Parameters:
connected- theconnectedflag
-
getSlaveOf
-
setSlaveOf
Sets the replication source.- Parameters:
slaveOf- the replication source, can benull
-
getPingSentTimestamp
public long getPingSentTimestamp() -
setPingSentTimestamp
public void setPingSentTimestamp(long pingSentTimestamp)Sets the lastpingSentTimestamp.- Parameters:
pingSentTimestamp- the lastpingSentTimestamp
-
getPongReceivedTimestamp
public long getPongReceivedTimestamp() -
setPongReceivedTimestamp
public void setPongReceivedTimestamp(long pongReceivedTimestamp)Sets the lastpongReceivedTimestamp.- Parameters:
pongReceivedTimestamp- the lastpongReceivedTimestamp
-
getConfigEpoch
public long getConfigEpoch() -
setConfigEpoch
public void setConfigEpoch(long configEpoch)Sets theconfigEpoch.- Parameters:
configEpoch- theconfigEpoch
-
getSlots
- Returns:
- the slots as
List.
-
forEachSlot
Performs the given action for each slot of thisRedisClusterNodeuntil 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
Sets the list of slots for which thisRedisClusterNodeis theRedisClusterNode.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 benullbut may be empty
-
hasSameSlotsAs
- Parameters:
other- the node to compare with.- Returns:
trueifthe other nodecontains the same slots asthis node.
-
getFlags
Return theNodeFlags.- Returns:
- the
NodeFlags.
-
setFlags
Set ofnode flags.- Parameters:
flags- the set of node flags.
-
is
- Parameters:
nodeFlag- the node flag- Returns:
- true if the RedisClusterNode.NodeFlag is contained within the flags.
-
addAlias
Add an alias toRedisClusterNode.- Parameters:
alias- must not benull.
-
getAliases
-
hasSlot
public boolean hasSlot(int slot)- Parameters:
slot- the slot hash- Returns:
- true if the slot is contained within the handled slots.
-
getRole
Returns theRedisInstance.Roleof the Redis Cluster node based on theflags.- Specified by:
getRolein interfaceRedisInstance- Returns:
- the Redis Cluster node role
-
equals
-
hashCode
public int hashCode() -
toString
-