public class Partitions extends AbstractCollection<RedisClusterNode> implements Collection<RedisClusterNode>
Partitions
provides access to the partitions of a Redis Cluster. A partition is
represented by a Redis Cluster node that has a nodeId
and
connection point details
.
Partitions can be looked up by nodeId
or slot
(masters only). A nodeId can be migrated to a different host.
Partitions are cached to ensure a cheap lookup by slot
. Users of Partitions
are required to call
updateCache()
after topology changes occur.
RedisClusterNode.NodeFlag.MASTER
/
RedisClusterNode.NodeFlag.SLAVE
stateRedisClusterNode.getSlots()
responsibilityslave replication source
(the master of a slave)RedisClusterNode.getUri()
() connection point}Constructor and Description |
---|
Partitions() |
Modifier and Type | Method and Description |
---|---|
void |
addPartition(RedisClusterNode partition) |
RedisClusterNode |
getPartition(int index) |
RedisClusterNode |
getPartitionByNodeId(String nodeId)
Retrieve a
RedisClusterNode by its node id. |
RedisClusterNode |
getPartitionBySlot(int slot)
Retrieve a
RedisClusterNode by its slot number. |
List<RedisClusterNode> |
getPartitions() |
Iterator<RedisClusterNode> |
iterator() |
void |
reload(List<RedisClusterNode> partitions)
Update partitions and rebuild slot cache.
|
int |
size() |
String |
toString() |
void |
updateCache()
Update the partition cache.
|
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
public RedisClusterNode getPartitionBySlot(int slot)
RedisClusterNode
by its slot number. This method does not distinguish between masters and slaves.slot
- the slotpublic RedisClusterNode getPartitionByNodeId(String nodeId)
RedisClusterNode
by its node id.nodeId
- the nodeIdpublic void updateCache()
public Iterator<RedisClusterNode> iterator()
iterator
in interface Iterable<RedisClusterNode>
iterator
in interface Collection<RedisClusterNode>
iterator
in class AbstractCollection<RedisClusterNode>
public List<RedisClusterNode> getPartitions()
public void addPartition(RedisClusterNode partition)
public String toString()
toString
in class AbstractCollection<RedisClusterNode>
public int size()
size
in interface Collection<RedisClusterNode>
size
in class AbstractCollection<RedisClusterNode>
public RedisClusterNode getPartition(int index)
public void reload(List<RedisClusterNode> partitions)
partitions
- list of new partitionsCopyright © 2015. All rights reserved.