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. Reuse this instance or the ClientResources
as much as possible.Modifier and Type | Field and Description |
---|---|
protected AtomicBoolean |
clusterTopologyRefreshActivated |
BUF_ALLOCATOR, channels, clientOptions, clientResources, closeableResources, connectionEvents, eventLoopGroup, eventLoopGroups, genericWorkerPool, timeout, timer, unit
Modifier | Constructor and Description |
---|---|
protected |
RedisClusterClient(ClientResources clientResources,
Iterable<RedisURI> redisURIs)
Initialize the client with a list of cluster URI's.
|
|
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(ClientResources clientResources,
Iterable<RedisURI> redisURIs)
Create a new client that connects to the supplied
uri with shared ClientResources . |
static RedisClusterClient |
create(ClientResources clientResources,
RedisURI redisURI)
Create a new client that connects to the supplied
uri with shared ClientResources . |
static RedisClusterClient |
create(ClientResources clientResources,
String uri)
Create a new client that connects to the supplied uri with shared
ClientResources .You need to shut down the
ClientResources upon shutting down your application. |
static RedisClusterClient |
create(Iterable<RedisURI> redisURIs)
Create a new client that connects to the supplied
uri with default ClientResources . |
static RedisClusterClient |
create(RedisURI redisURI)
Create a new client that connects to the supplied
uri with default ClientResources . |
static RedisClusterClient |
create(String uri)
Create a new client that connects to the supplied uri with default
ClientResources . |
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.
|
ClientResources |
getResources()
Returns the
ClientResources which are used with that client. |
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
@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.protected RedisClusterClient(ClientResources clientResources, Iterable<RedisURI> redisURIs)
clientResources
- the client resources. If null, the client will create a new dedicated instance of
client resources and keep track of them.redisURIs
- iterable of initial cluster URIs
. Must not be null and not empty.public static RedisClusterClient create(RedisURI redisURI)
uri
with default ClientResources
. 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)
uri
with default ClientResources
. 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)
ClientResources
. You can connect to different
Redis servers but you must supply a RedisURI
on connecting.uri
- the Redis URI, must not be nullRedisClusterClient
public static RedisClusterClient create(ClientResources clientResources, RedisURI redisURI)
uri
with shared ClientResources
. You need to
shut down the ClientResources
upon shutting down your application.You can connect to different Redis servers but
you must supply a RedisURI
on connecting.clientResources
- the client resources, must not be nullredisURI
- the Redis URI, must not be nullRedisClusterClient
public static RedisClusterClient create(ClientResources clientResources, String uri)
ClientResources
.You need to shut down the
ClientResources
upon shutting down your application. You can connect to different Redis servers but you must
supply a RedisURI
on connecting.clientResources
- the client resources, must not be nulluri
- the Redis URI, must not be nullRedisClusterClient
public static RedisClusterClient create(ClientResources clientResources, Iterable<RedisURI> redisURIs)
uri
with shared ClientResources
. You need to
shut down the ClientResources
upon shutting down your application.You can connect to different Redis servers but
you must supply a RedisURI
on connecting.clientResources
- the client resources, must not be nullredisURIs
- one or more Redis URI, must not be null and not emptyRedisClusterClient
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 objectpublic ClientResources getResources()
ClientResources
which are used with that client.ClientResources
for this clientprotected 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 © 2016. All rights reserved.