public class RedisClient extends AbstractRedisClient
RedisClient can be used with:
RedisClusterClient. Master/Slave connections through
MasterSlave provide connections to Redis Master/Slave setups which run either in a static
Master/Slave setup or are managed by Redis Sentinel.
RedisClient is an expensive resource. It holds a set of netty's EventLoopGroup's that use
multiple threads. Reuse this instance as much as possible or share a ClientResources instance amongst multiple client
instances.
RedisURI,
StatefulRedisConnection,
RedisFuture,
Mono,
Flux,
RedisCodec,
ClientOptions,
ClientResources,
MasterSlave,
RedisClusterClientBUF_ALLOCATOR, channels, clientOptions, clientResources, closeableResources, connectionEvents, eventLoopGroups, genericWorkerPool, logger, timeout, timer| Modifier | Constructor and Description |
|---|---|
protected |
RedisClient()
Creates a uri-less RedisClient.
|
protected |
RedisClient(ClientResources clientResources,
RedisURI redisURI) |
| Modifier and Type | Method and Description |
|---|---|
StatefulRedisConnection<String,String> |
connect()
Open a new connection to a Redis server that treats keys and values as UTF-8 strings.
|
<K,V> StatefulRedisConnection<K,V> |
connect(RedisCodec<K,V> codec)
Open a new connection to a Redis server.
|
<K,V> StatefulRedisConnection<K,V> |
connect(RedisCodec<K,V> codec,
RedisURI redisURI)
|
StatefulRedisConnection<String,String> |
connect(RedisURI redisURI)
Open a new connection to a Redis server using the supplied
RedisURI that treats keys and values as UTF-8 strings. |
<K,V> ConnectionFuture<StatefulRedisConnection<K,V>> |
connectAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
|
StatefulRedisPubSubConnection<String,String> |
connectPubSub()
Open a new pub/sub connection to a Redis server that treats keys and values as UTF-8 strings.
|
<K,V> StatefulRedisPubSubConnection<K,V> |
connectPubSub(RedisCodec<K,V> codec)
|
<K,V> StatefulRedisPubSubConnection<K,V> |
connectPubSub(RedisCodec<K,V> codec,
RedisURI redisURI)
|
StatefulRedisPubSubConnection<String,String> |
connectPubSub(RedisURI redisURI)
Open a new pub/sub connection to a Redis server using the supplied
RedisURI that treats keys and values as UTF-8
strings. |
<K,V> ConnectionFuture<StatefulRedisPubSubConnection<K,V>> |
connectPubSubAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
|
StatefulRedisSentinelConnection<String,String> |
connectSentinel()
Open a connection to a Redis Sentinel that treats keys and values as UTF-8 strings.
|
<K,V> StatefulRedisSentinelConnection<K,V> |
connectSentinel(RedisCodec<K,V> codec)
Open a connection to a Redis Sentinel that treats keys and use the supplied
codec to encode/decode
keys and values. |
<K,V> StatefulRedisSentinelConnection<K,V> |
connectSentinel(RedisCodec<K,V> codec,
RedisURI redisURI)
|
StatefulRedisSentinelConnection<String,String> |
connectSentinel(RedisURI redisURI)
Open a connection to a Redis Sentinel using the supplied
RedisURI that treats keys and values as UTF-8 strings. |
<K,V> CompletableFuture<StatefulRedisSentinelConnection<K,V>> |
connectSentinelAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
|
static RedisClient |
create()
Creates a uri-less RedisClient with default
ClientResources. |
static RedisClient |
create(ClientResources clientResources)
Creates a uri-less RedisClient with shared
ClientResources. |
static RedisClient |
create(ClientResources clientResources,
RedisURI redisURI)
Create a new client that connects to the supplied
uri with shared ClientResources. |
static RedisClient |
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 RedisClient |
create(RedisURI redisURI)
Create a new client that connects to the supplied
uri with default ClientResources. |
static RedisClient |
create(String uri)
Create a new client that connects to the supplied uri with default
ClientResources. |
ClientResources |
getResources()
Returns the
ClientResources which are used with that client. |
protected Mono<SocketAddress> |
getSocketAddress(RedisURI redisURI)
|
protected <K,V> StatefulRedisConnectionImpl<K,V> |
newStatefulRedisConnection(RedisChannelWriter channelWriter,
RedisCodec<K,V> codec,
Duration timeout)
Create a new instance of
StatefulRedisConnectionImpl or a subclass. |
protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> |
newStatefulRedisPubSubConnection(PubSubEndpoint<K,V> endpoint,
RedisChannelWriter channelWriter,
RedisCodec<K,V> codec,
Duration timeout)
Create a new instance of
StatefulRedisPubSubConnectionImpl or a subclass. |
protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> |
newStatefulRedisSentinelConnection(RedisChannelWriter channelWriter,
RedisCodec<K,V> codec,
Duration timeout)
Create a new instance of
StatefulRedisSentinelConnectionImpl or a subclass. |
protected RedisCodec<String,String> |
newStringStringCodec()
|
void |
setOptions(ClientOptions clientOptions)
Set the
ClientOptions for the client. |
addListener, channelType, connectionBuilder, getChannelCount, getConnection, getConnection, getOptions, getResourceCount, initializeChannelAsync, removeListener, setDefaultTimeout, setDefaultTimeout, shutdown, shutdown, shutdown, shutdownAsync, shutdownAsyncprotected RedisClient(ClientResources clientResources, RedisURI redisURI)
protected RedisClient()
RedisURI on
connecting. Methods without having a RedisURI will fail with a IllegalStateException.
Non-private constructor to make RedisClient proxyable.public static RedisClient create()
ClientResources. You can connect to different Redis servers but you
must supply a RedisURI on connecting. Methods without having a RedisURI will fail with a
IllegalStateException.RedisClient.public static RedisClient 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 null.RedisClient.public static RedisClient 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 null.RedisClient.public static RedisClient create(ClientResources clientResources)
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. Methods without having a RedisURI will fail with a IllegalStateException.clientResources - the client resources, must not be null.RedisClient.public static RedisClient 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 null.uri - the Redis URI, must not be null.RedisClient.public static RedisClient 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 null.redisURI - the Redis URI, must not be null.RedisClient.public StatefulRedisConnection<String,String> connect()
public <K,V> StatefulRedisConnection<K,V> connect(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 null.public StatefulRedisConnection<String,String> connect(RedisURI redisURI)
RedisURI that treats keys and values as UTF-8 strings.redisURI - the Redis server to connect to, must not be null.public <K,V> StatefulRedisConnection<K,V> connect(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and the supplied codec to
encode/decode keys.K - Key type.V - Value type.codec - Use this codec to encode/decode keys and values, must not be null.redisURI - the Redis server to connect to, must not be null.public <K,V> ConnectionFuture<StatefulRedisConnection<K,V>> connectAsync(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and the supplied
codec to encode/decode keys.K - Key type.V - Value type.codec - Use this codec to encode/decode keys and values, must not be null.redisURI - the Redis server to connect to, must not be null.ConnectionFuture to indicate success or failure to connect.public StatefulRedisPubSubConnection<String,String> connectPubSub()
public StatefulRedisPubSubConnection<String,String> connectPubSub(RedisURI redisURI)
RedisURI that treats keys and values as UTF-8
strings.redisURI - the Redis server to connect to, must not be null.public <K,V> StatefulRedisPubSubConnection<K,V> connectPubSub(RedisCodec<K,V> codec)
RedisURI and use the supplied
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 null.public <K,V> StatefulRedisPubSubConnection<K,V> connectPubSub(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and use the supplied
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 null.redisURI - the Redis server to connect to, must not be null.public <K,V> ConnectionFuture<StatefulRedisPubSubConnection<K,V>> connectPubSubAsync(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and use the supplied
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 null.redisURI - the redis server to connect to, must not be null.ConnectionFuture to indicate success or failure to connect.public StatefulRedisSentinelConnection<String,String> connectSentinel()
public <K,V> StatefulRedisSentinelConnection<K,V> connectSentinel(RedisCodec<K,V> codec)
codec to encode/decode
keys and values. The client RedisURI must contain one or more sentinels.K - Key type.V - Value type.codec - Use this codec to encode/decode keys and values, must not be null.public StatefulRedisSentinelConnection<String,String> connectSentinel(RedisURI redisURI)
RedisURI that treats keys and values as UTF-8 strings.
The client RedisURI must contain one or more sentinels.redisURI - the Redis server to connect to, must not be null.public <K,V> StatefulRedisSentinelConnection<K,V> connectSentinel(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and use the supplied codec
to encode/decode keys and values. The client RedisURI must contain one or more sentinels.K - Key type.V - Value type.codec - the Redis server to connect to, must not be null.redisURI - the Redis server to connect to, must not be null.public <K,V> CompletableFuture<StatefulRedisSentinelConnection<K,V>> connectSentinelAsync(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI and use the supplied
codec to encode/decode keys and values. The client RedisURI must contain one or more
sentinels.K - Key type.V - Value type.codec - the Redis server to connect to, must not be null.redisURI - the Redis server to connect to, must not be null.public void setOptions(ClientOptions clientOptions)
ClientOptions for the client.setOptions in class AbstractRedisClientclientOptions - the new client options.IllegalArgumentException - if clientOptions is nullpublic ClientResources getResources()
ClientResources which are used with that client.ClientResources for this client.protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> newStatefulRedisPubSubConnection(PubSubEndpoint<K,V> endpoint, RedisChannelWriter channelWriter, RedisCodec<K,V> codec, Duration timeout)
StatefulRedisPubSubConnectionImpl or a subclass.
Subclasses of RedisClient may override that method.
K - Key-Type.V - Value Type.endpoint - the endpoint.channelWriter - the channel writer.codec - codec.timeout - default timeout.protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> newStatefulRedisSentinelConnection(RedisChannelWriter channelWriter, RedisCodec<K,V> codec, Duration timeout)
StatefulRedisSentinelConnectionImpl or a subclass.
Subclasses of RedisClient may override that method.
K - Key-Type.V - Value Type.channelWriter - the channel writer.codec - codec.timeout - default timeout.protected <K,V> StatefulRedisConnectionImpl<K,V> newStatefulRedisConnection(RedisChannelWriter channelWriter, RedisCodec<K,V> codec, Duration timeout)
StatefulRedisConnectionImpl or a subclass.
Subclasses of RedisClient may override that method.
K - Key-Type.V - Value Type.channelWriter - the channel writer.codec - codec.timeout - default timeout.protected Mono<SocketAddress> getSocketAddress(RedisURI redisURI)
Mono that resolves RedisURI to a SocketAddress. Resolution is performed either using Redis
Sentinel (if the RedisURI is configured with Sentinels) or via DNS resolution.
Subclasses of RedisClient may override that method.
redisURI - must not be null.SocketAddress.ClientResources.dnsResolver(),
RedisURI.getSentinels(),
RedisURI.getSentinelMasterId()protected RedisCodec<String,String> newStringStringCodec()
String codec.StringCodec.UTF8Copyright © 2021 lettuce.io. All rights reserved.