public class RedisClusterClient extends AbstractRedisClient
getPartitions()
method.
Connections to particular nodes can be obtained by RedisAdvancedClusterConnection.getConnection(String)
providing the
node id or RedisAdvancedClusterConnection.getConnection(String, int)
by host and port.
RedisClusterClient
is an expensive resource. Reuse this instance or the ClientResources
as much as possible.Modifier and Type | Field and Description |
---|---|
protected AtomicBoolean |
clusterTopologyRefreshActivated |
protected AtomicReference<ScheduledFuture<?>> |
clusterTopologyRefreshFuture |
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 |
---|---|
protected RedisAsyncConnectionImpl<String,String> |
connectAsyncImpl(SocketAddress socketAddress) |
RedisAdvancedClusterConnection<String,String> |
connectCluster()
Open a new synchronous connection to a Redis Cluster that treats keys and values as UTF-8 strings.
|
<K,V> RedisAdvancedClusterConnection<K,V> |
connectCluster(RedisCodec<K,V> codec)
Open a new synchronous connection to a Redis Cluster.
|
RedisAdvancedClusterAsyncConnection<String,String> |
connectClusterAsync()
Open a new asynchronous connection to a Redis Cluster that treats keys and values as UTF-8 strings.
|
<K,V> RedisAdvancedClusterAsyncConnection<K,V> |
connectClusterAsync(RedisCodec<K,V> codec)
Open a new asynchronous connection to a Redis Cluster.
|
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(com.google.common.base.Predicate<? super Closeable> selector,
com.google.common.base.Predicate<T> function) |
protected void |
forEachClusterConnection(com.google.common.base.Predicate<RedisAdvancedClusterAsyncConnectionImpl<?,?>> function) |
protected RedisURI |
getFirstUri() |
Partitions |
getPartitions()
Retrieve the cluster view.
|
ClientResources |
getResources()
Returns the
ClientResources which are used with that client. |
protected com.google.common.base.Supplier<SocketAddress> |
getSocketAddressSupplier(com.google.common.base.Function<? extends Collection<RedisClusterNode>,Collection<RedisClusterNode>> sortFunction)
Returns a
Supplier for connection points . |
protected void |
initializePartitions() |
protected boolean |
isEventLoopActive()
Check if the
AbstractRedisClient.genericWorkerPool is active |
protected Partitions |
loadPartitions()
Retrieve partitions.
|
protected <K,V> RedisAdvancedClusterAsyncConnectionImpl<K,V> |
newRedisAdvancedClusterAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Construct a new
RedisAdvancedClusterAsyncConnectionImpl . |
protected <K,V> RedisAsyncConnectionImpl<K,V> |
newRedisAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Construct a new
RedisAsyncConnectionImpl . |
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.
|
void |
shutdown(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Shutdown this client and close all open connections.
|
protected void |
updatePartitionsInConnections() |
addListener, channelType, connectAsyncImpl, connectionBuilder, getChannelCount, getOptions, getResourceCount, initializeChannel, removeListener, setDefaultTimeout, setOptions, shutdown, syncHandler
protected AtomicBoolean clusterTopologyRefreshActivated
protected AtomicReference<ScheduledFuture<?>> clusterTopologyRefreshFuture
@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 RedisAdvancedClusterConnection<String,String> connectCluster()
public <K,V> RedisAdvancedClusterConnection<K,V> connectCluster(RedisCodec<K,V> codec)
codec
to encode/decode keys and
values.K
- Key type.V
- Value type.codec
- Use this codec to encode/decode keys and values, must not be nullpublic RedisAdvancedClusterAsyncConnection<String,String> connectClusterAsync()
public <K,V> RedisAdvancedClusterAsyncConnection<K,V> connectClusterAsync(RedisCodec<K,V> codec)
codec
to encode/decode keys
and values.K
- Key type.V
- Value type.codec
- Use this codec to encode/decode keys and values, must not be nullprotected RedisAsyncConnectionImpl<String,String> connectAsyncImpl(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 <K,V> RedisAsyncConnectionImpl<K,V> newRedisAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
RedisAsyncConnectionImpl
. Can be overridden in order to construct a subclass of
RedisAsyncConnectionImpl
. These connections are the "inner" connections used by the
ClusterDistributionChannelWriter
.K
- Key type.V
- Value type.channelWriter
- the channel writercodec
- the codec to usetimeout
- Timeout valueunit
- Timeout unitprotected <K,V> RedisAdvancedClusterAsyncConnectionImpl<K,V> newRedisAdvancedClusterAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
RedisAdvancedClusterAsyncConnectionImpl
. Can be overridden in order to construct a subclass of
RedisAdvancedClusterAsyncConnectionImpl
K
- Key type.V
- Value type.channelWriter
- the channel writercodec
- the codec to usetimeout
- Timeout valueunit
- Timeout unitprotected RedisURI getFirstUri()
protected com.google.common.base.Supplier<SocketAddress> getSocketAddressSupplier(com.google.common.base.Function<? extends Collection<RedisClusterNode>,Collection<RedisClusterNode>> sortFunction)
Supplier
for connection points
.sortFunction
- Sort function to enforce a specific order. The sort function must not change the order or the input
parameter but create a new collection with the desired order, must not be null.Supplier
for connection points
.protected Utf8StringCodec newStringStringCodec()
public void setPartitions(Partitions partitions)
partitions
- partitions objectpublic ClientResources getResources()
ClientResources
which are used with that client.ClientResources
for this clientpublic void shutdown(long quietPeriod, long timeout, TimeUnit timeUnit)
shutdown
in class AbstractRedisClient
quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is shutdown regardless if a task was submitted
during the quiet periodtimeUnit
- the unit of quietPeriod
and timeout
protected void forEachClusterConnection(com.google.common.base.Predicate<RedisAdvancedClusterAsyncConnectionImpl<?,?>> function)
protected <T extends Closeable> void forEachCloseable(com.google.common.base.Predicate<? super Closeable> selector, com.google.common.base.Predicate<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.