public class RedisClusterClient extends AbstractRedisClient
getPartitions()
method.
Connections to the cluster members are opened on the first access to the cluster node and managed by the
StatefulRedisClusterConnection
. You should not use transactional commands on cluster connections since MULTI
,
EXEC
and DISCARD
have no key and cannot be assigned to a particular node.
The Redis cluster client provides a sync
, async
and reactive
API.
Connections to particular nodes can be obtained by StatefulRedisClusterConnection.getConnection(String)
providing the
node id or StatefulRedisClusterConnection.getConnection(String, int)
by host and port.
Multiple keys operations have to operate on a key that hashes to the same slot. Following commands do not need to follow that rule since they are pipelined according its hash value to multiple nodes in parallel:
Cluster commands can be issued to multiple hosts in parallel by using the NodeSelectionSupport
API. A set of nodes is
selected using a Predicate
and commands can be issued to the node selection
AsyncExecutions
RedisClusterClient
is an expensive resource. It holds a set of netty's EventLoopGroup
's that
consist of up to Number of CPU's * 4
threads. Reuse this instance as much as possible.Modifier and Type | Field and Description |
---|---|
protected AtomicBoolean |
clusterTopologyRefreshActivated |
BUF_ALLOCATOR, channels, clientOptions, closeableResources, connectionEvents, eventLoopGroups, genericWorkerPool, timeout, timer, unit
Modifier | Constructor and Description |
---|---|
protected |
RedisClusterClient() |
|
RedisClusterClient(List<RedisURI> redisURIs)
Deprecated.
Use
create(Iterable) |
|
RedisClusterClient(RedisURI initialUri)
Deprecated.
Use
create(RedisURI) |
Modifier and Type | Method and Description |
---|---|
StatefulRedisClusterConnection<String,String> |
connect()
Connect to a Redis Cluster and treat keys and values as UTF-8 strings.
|
<K,V> StatefulRedisClusterConnection<K,V> |
connect(RedisCodec<K,V> codec)
Connect to a Redis Cluster.
|
RedisAdvancedClusterCommands<String,String> |
connectCluster()
Deprecated.
Use
connect().sync() |
<K,V> RedisAdvancedClusterCommands<K,V> |
connectCluster(RedisCodec<K,V> codec)
Deprecated.
@deprecated Use
connect(codec).sync() |
RedisAdvancedClusterAsyncCommands<String,String> |
connectClusterAsync()
Deprecated.
Use
connect().async() |
<K,V> RedisAdvancedClusterAsyncCommands<K,V> |
connectClusterAsync(RedisCodec<K,V> codec)
Deprecated.
@deprecated Use
connect(codec).async() |
protected StatefulRedisConnection<String,String> |
connectToNode(SocketAddress socketAddress) |
static RedisClusterClient |
create(Iterable<RedisURI> redisURIs)
Create a new client that connects to the supplied iterable of
uris . |
static RedisClusterClient |
create(RedisURI redisURI)
Create a new client that connects to the supplied
uri . |
static RedisClusterClient |
create(String uri)
Create a new client that connects to the supplied uri.
|
protected <T extends Closeable> |
forEachCloseable(java.util.function.Predicate<? super Closeable> selector,
java.util.function.Consumer<T> function) |
protected void |
forEachClusterConnection(java.util.function.Consumer<StatefulRedisClusterConnectionImpl<?,?>> function) |
protected RedisURI |
getFirstUri() |
Partitions |
getPartitions()
Retrieve the cluster view.
|
protected void |
initializePartitions() |
protected boolean |
isEventLoopActive()
Check if the
AbstractRedisClient.genericWorkerPool is active |
protected Partitions |
loadPartitions()
Retrieve partitions.
|
protected Utf8StringCodec |
newStringStringCodec() |
void |
reloadPartitions()
Reload partitions and re-initialize the distribution table.
|
void |
setOptions(ClusterClientOptions clientOptions)
Set the
ClusterClientOptions for the client. |
void |
setPartitions(Partitions partitions)
Sets the new cluster topology.
|
protected void |
updatePartitionsInConnections() |
addListener, channelType, connectAsyncImpl, connectionBuilder, getChannelCount, getOptions, getResourceCount, initializeChannel, removeListener, setDefaultTimeout, setOptions, shutdown, shutdown
protected AtomicBoolean clusterTopologyRefreshActivated
protected RedisClusterClient()
@Deprecated public RedisClusterClient(RedisURI initialUri)
create(RedisURI)
initialUri
- initial cluster URI@Deprecated public RedisClusterClient(List<RedisURI> redisURIs)
create(Iterable)
redisURIs
- iterable of initial cluster URIs
. Must not be null and not empty.public static RedisClusterClient create(RedisURI redisURI)
uri
. You can connect to different Redis servers but
you must supply a RedisURI
on connecting.redisURI
- the Redis URI, must not be nullRedisClusterClient
public static RedisClusterClient create(Iterable<RedisURI> redisURIs)
uris
. You can connect to different Redis
servers but you must supply a RedisURI
on connecting.redisURIs
- one or more Redis URI, must not be null and not emptyRedisClusterClient
public static RedisClusterClient create(String uri)
RedisURI
on connecting.uri
- the Redis URI, must not be nullRedisClusterClient
public StatefulRedisClusterConnection<String,String> connect()
public <K,V> StatefulRedisClusterConnection<K,V> connect(RedisCodec<K,V> codec)
codec
to encode/decode keys and values.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be null@Deprecated public RedisAdvancedClusterCommands<String,String> connectCluster()
connect().sync()
@Deprecated public <K,V> RedisAdvancedClusterCommands<K,V> connectCluster(RedisCodec<K,V> codec)
connect(codec).sync()
codec
to encode/decode keys and
values.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be null@Deprecated public RedisAdvancedClusterAsyncCommands<String,String> connectClusterAsync()
connect().async()
@Deprecated public <K,V> RedisAdvancedClusterAsyncCommands<K,V> connectClusterAsync(RedisCodec<K,V> codec)
connect(codec).async()
codec
to encode/decode keys
and values.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullprotected StatefulRedisConnection<String,String> connectToNode(SocketAddress socketAddress)
public void reloadPartitions()
protected void updatePartitionsInConnections()
protected void initializePartitions()
public Partitions getPartitions()
protected Partitions loadPartitions()
Partitions
are ordered by latency. Lower latency nodes come first.protected boolean isEventLoopActive()
AbstractRedisClient.genericWorkerPool
is activeprotected RedisURI getFirstUri()
protected Utf8StringCodec newStringStringCodec()
public void setPartitions(Partitions partitions)
partitions
- partitions objectprotected void forEachClusterConnection(java.util.function.Consumer<StatefulRedisClusterConnectionImpl<?,?>> function)
protected <T extends Closeable> void forEachCloseable(java.util.function.Predicate<? super Closeable> selector, java.util.function.Consumer<T> function)
public void setOptions(ClusterClientOptions clientOptions)
ClusterClientOptions
for the client.clientOptions
- client options for the client and connections that are created after setting the optionsCopyright © 2015. All rights reserved.