public class Partitions extends Object 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.UPSTREAM/
RedisClusterNode.NodeFlag.REPLICA stateRedisClusterNode.getSlots() responsibilityreplication source (the master of a replica)RedisClusterNode.getUri() () connection point}All query/read operations use the read-only view. Updates to Partitions are performed in an atomic way. Changes to the read-only cache become visible after the partition update is completed.
| Constructor and Description |
|---|
Partitions() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(RedisClusterNode redisClusterNode)
Adds the
RedisClusterNode to this Partitions. |
boolean |
addAll(Collection<? extends RedisClusterNode> c)
Add all
nodes from the given collection and update the read-view/caches. |
void |
addPartition(RedisClusterNode partition)
Adds a partition without updating the read view/cache.
|
void |
clear()
Removes all
nodes and update the read-view/caches. |
Partitions |
clone()
Create a deep copy of this
Partitions object. |
boolean |
contains(Object o)
Returns
true if this Partitions contains the specified element. |
boolean |
containsAll(Collection<?> c)
Returns
true if this collection contains all of the elements in the specified collection. |
RedisClusterNode |
getPartition(int index)
Returns the
RedisClusterNode at index. |
RedisClusterNode |
getPartition(String host,
int port)
Retrieve a
RedisClusterNode by its hostname/port considering node aliases. |
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()
Returns the internal
List of RedisClusterNode that holds the partition source. |
boolean |
isEmpty()
Returns
true if this Partitions contains no elements using the read-view. |
Iterator<RedisClusterNode> |
iterator()
Returns an iterator over the
nodes in this Partitions from the read-view. |
void |
reload(List<RedisClusterNode> partitions)
Update partitions and rebuild slot cache.
|
boolean |
remove(Object o)
Remove the element from this
Partitions. |
boolean |
removeAll(Collection<?> c)
Remove all
nodes from the Partitions using elements from the given collection and update
the read-view/caches. |
boolean |
retainAll(Collection<?> c)
Retains only the elements in this
Partitions that are contained in the specified collection (optional
operation)and update the read-view/caches. |
int |
size() |
Object[] |
toArray()
Returns an array containing all of the elements in this
Partitions using the read-view. |
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this
Partitions using the read-view. |
String |
toString() |
void |
updateCache()
Update the partition cache.
|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic Partitions clone()
Partitions object.clone in class ObjectPartitions object.public RedisClusterNode getPartitionBySlot(int slot)
RedisClusterNode by its slot number. This method does not distinguish between masters and slaves.slot - the slot hash.RedisClusterNode or null if not found.public RedisClusterNode getPartitionByNodeId(String nodeId)
RedisClusterNode by its node id.nodeId - the nodeId.RedisClusterNode or null if not found.public RedisClusterNode getPartition(String host, int port)
RedisClusterNode by its hostname/port considering node aliases.host - hostname.port - port number.RedisClusterNode or null if not found.public void updateCache()
public Iterator<RedisClusterNode> iterator()
nodes in this Partitions from the read-view. The
Iterator remains consistent during partition updates with the nodes that have been part of the Partitions
. Nodes added/removed during iteration/after obtaining the Iterator don't become visible
during iteration but upon the next call to iterator().iterator in interface Iterable<RedisClusterNode>iterator in interface Collection<RedisClusterNode>nodes in this Partitions from the read-view.public List<RedisClusterNode> getPartitions()
List of RedisClusterNode that holds the partition source. This List is used
to populate partition caches and should not be used directly and subject to change by refresh processes. Access
(read/write) requires synchronization on getPartitions().public void addPartition(RedisClusterNode partition)
partition - the partitionpublic int size()
size in interface Collection<RedisClusterNode>public RedisClusterNode getPartition(int index)
RedisClusterNode at index.index - the indexpublic void reload(List<RedisClusterNode> partitions)
partitions - list of new partitionspublic boolean isEmpty()
true if this Partitions contains no elements using the read-view.isEmpty in interface Collection<RedisClusterNode>true if this Partitions contains no elements using the read-view.public boolean contains(Object o)
true if this Partitions contains the specified element.contains in interface Collection<RedisClusterNode>o - the element to check fortrue if this Partitions contains the specified elementpublic boolean addAll(Collection<? extends RedisClusterNode> c)
nodes from the given collection and update the read-view/caches.addAll in interface Collection<RedisClusterNode>c - must not be nulltrue if this Partitions changed as a result of the callpublic boolean removeAll(Collection<?> c)
nodes from the Partitions using elements from the given collection and update
the read-view/caches.removeAll in interface Collection<RedisClusterNode>c - must not be nulltrue if this Partitions changed as a result of the callpublic boolean retainAll(Collection<?> c)
Partitions that are contained in the specified collection (optional
operation)and update the read-view/caches. In other words, removes from this collection all of its elements that are not
contained in the specified collection.retainAll in interface Collection<RedisClusterNode>c - must not be nulltrue if this Partitions changed as a result of the callpublic void clear()
nodes and update the read-view/caches.clear in interface Collection<RedisClusterNode>public Object[] toArray()
Partitions using the read-view.toArray in interface Collection<RedisClusterNode>Partitions using the read-view.public <T> T[] toArray(T[] a)
Partitions using the read-view.toArray in interface Collection<RedisClusterNode>T - type of the array to contain the collectiona - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new
array of the same runtime type is allocated for this purpose.Partitions using the read-view.public boolean add(RedisClusterNode redisClusterNode)
RedisClusterNode to this Partitions.add in interface Collection<RedisClusterNode>redisClusterNode - must not be nulltrue if this Partitions changed as a result of the callpublic boolean remove(Object o)
Partitions.remove in interface Collection<RedisClusterNode>o - must not be nulltrue if this Partitions changed as a result of the callpublic boolean containsAll(Collection<?> c)
true if this collection contains all of the elements in the specified collection.containsAll in interface Collection<RedisClusterNode>c - collection to be checked for containment in this collection, must not be nullCopyright © 2021 lettuce.io. All rights reserved.