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. ARedisClusterNode
is identified by itsnodeId
.A
RedisClusterNode
can be aresponsible master
or replica. Masters can be responsible for zero to16384
slots. Each replica refers to exactly onemaster
. Nodes can have differentflags
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 class
RedisClusterNode.NodeFlag
Redis 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAlias(RedisURI alias)
Add an alias toRedisClusterNode
.RedisClusterNode
clone()
Clonethis
RedisClusterNode
.boolean
equals(Object o)
void
forEachSlot(IntConsumer consumer)
Performs the given action for each slot of thisRedisClusterNode
until all elements have been processed or the action throws an exception.List<RedisURI>
getAliases()
long
getConfigEpoch()
Set<RedisClusterNode.NodeFlag>
getFlags()
Return theNodeFlags
.String
getNodeId()
long
getPingSentTimestamp()
long
getPongReceivedTimestamp()
long
getReplOffset()
RedisInstance.Role
getRole()
Returns theRedisInstance.Role
of the Redis Cluster node based on theflags
.String
getSlaveOf()
List<Integer>
getSlots()
Return the slots asList
.RedisURI
getUri()
int
hashCode()
boolean
hasSameSlotsAs(RedisClusterNode other)
boolean
hasSlot(int slot)
boolean
is(RedisClusterNode.NodeFlag nodeFlag)
boolean
isConnected()
static RedisClusterNode
of(String nodeId)
Create a new instance ofRedisClusterNode
by passing thenodeId
void
setConfigEpoch(long configEpoch)
Sets theconfigEpoch
.void
setConnected(boolean connected)
Sets theconnected
flag.void
setFlags(Set<RedisClusterNode.NodeFlag> flags)
Set ofnode flags
.void
setNodeId(String nodeId)
SetsnodeId
.void
setPingSentTimestamp(long pingSentTimestamp)
Sets the lastpingSentTimestamp
.void
setPongReceivedTimestamp(long pongReceivedTimestamp)
Sets the lastpongReceivedTimestamp
.void
setReplOffset(long replOffset)
Sets thereplOffset
.void
setSlaveOf(String slaveOf)
Sets the replication source.void
setSlots(List<Integer> slots)
Sets the list of slots for which thisRedisClusterNode
is theRedisClusterNode.NodeFlag.UPSTREAM
.void
setUri(RedisURI uri)
Sets the connection point details.String
toString()
-
-
-
Constructor Detail
-
RedisClusterNode
public RedisClusterNode()
-
RedisClusterNode
public RedisClusterNode(RedisURI uri, String nodeId, boolean connected, String slaveOf, long pingSentTimestamp, long pongReceivedTimestamp, long configEpoch, List<Integer> slots, Set<RedisClusterNode.NodeFlag> flags)
-
RedisClusterNode
public RedisClusterNode(RedisClusterNode redisClusterNode)
-
-
Method Detail
-
of
public static RedisClusterNode of(String nodeId)
Create a new instance ofRedisClusterNode
by passing thenodeId
- Parameters:
nodeId
- the nodeId- Returns:
- a new instance of
RedisClusterNode
-
clone
public RedisClusterNode clone()
Clonethis
RedisClusterNode
.- Overrides:
clone
in classObject
- Returns:
- a copy of
this
RedisClusterNode
.
-
getUri
public RedisURI getUri()
- Specified by:
getUri
in interfaceRedisNodeDescription
- 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
- theRedisURI
, must not benull
-
getNodeId
public String getNodeId()
-
setNodeId
public void setNodeId(String nodeId)
SetsnodeId
.- Parameters:
nodeId
- thenodeId
-
isConnected
public boolean isConnected()
-
setConnected
public void setConnected(boolean connected)
Sets theconnected
flag. Theconnected
flag describes whether the node which provided details about the node is connected to the particularRedisClusterNode
.- Parameters:
connected
- theconnected
flag
-
getSlaveOf
public String getSlaveOf()
-
setSlaveOf
public void setSlaveOf(String slaveOf)
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
-
getReplOffset
public long getReplOffset()
-
setReplOffset
public void setReplOffset(long replOffset)
Sets thereplOffset
. Typically, obtained fromINFO REPLICATION master_repl_offset
. Can be-1
in case it was not obtained from Redis or set in the data model.- Parameters:
replOffset
- thereplOffset
-
forEachSlot
public void forEachSlot(IntConsumer consumer)
Performs the given action for each slot of thisRedisClusterNode
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 thisRedisClusterNode
is 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 benull
but may be empty
-
hasSameSlotsAs
public boolean hasSameSlotsAs(RedisClusterNode other)
- Parameters:
other
- the node to compare with.- Returns:
true
ifthe other node
contains the same slots asthis node
.
-
getFlags
public Set<RedisClusterNode.NodeFlag> getFlags()
Return theNodeFlags
.- Returns:
- the
NodeFlags
.
-
setFlags
public void setFlags(Set<RedisClusterNode.NodeFlag> flags)
Set ofnode 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 toRedisClusterNode
.- Parameters:
alias
- must not benull
.
-
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 theRedisInstance.Role
of the Redis Cluster node based on theflags
.- Specified by:
getRole
in interfaceRedisInstance
- Returns:
- the Redis Cluster node role
-
-