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
,
Observable
,
RedisCodec
,
ClientOptions
,
ClientResources
,
MasterSlave
,
RedisClusterClient
BUF_ALLOCATOR, channels, clientOptions, clientResources, closeableResources, connectionEvents, eventLoopGroup, eventLoopGroups, genericWorkerPool, logger, timeout, timer, unit
Modifier | Constructor and Description |
---|---|
|
RedisClient()
Deprecated.
Use the factory method
create() |
protected |
RedisClient(ClientResources clientResources,
RedisURI redisURI) |
|
RedisClient(RedisURI redisURI)
Deprecated.
Use the factory method
create(RedisURI) |
|
RedisClient(String host)
Deprecated.
Use the factory method
create(String) |
|
RedisClient(String host,
int port)
Deprecated.
Use the factory method
create(RedisURI) |
Modifier and Type | Method and Description |
---|---|
RedisConnectionPool<RedisAsyncCommands<String,String>> |
asyncPool()
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
RedisConnectionPool<RedisAsyncCommands<String,String>> |
asyncPool(int maxIdle,
int maxActive)
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
<K,V> RedisConnectionPool<RedisAsyncCommands<K,V>> |
asyncPool(RedisCodec<K,V> codec,
int maxIdle,
int maxActive)
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
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. |
RedisAsyncCommands<String,String> |
connectAsync()
Deprecated.
|
<K,V> RedisAsyncCommands<K,V> |
connectAsync(RedisCodec<K,V> codec)
Deprecated.
Use
connect(codec).async() |
<K,V> RedisAsyncCommands<K,V> |
connectAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
Deprecated.
Use
connect(codec, redisURI).async() |
RedisAsyncCommands<String,String> |
connectAsync(RedisURI redisURI)
Deprecated.
Use
connect(redisURI).async() |
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. |
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. |
RedisSentinelAsyncCommands<String,String> |
connectSentinelAsync()
Deprecated.
Use
connectSentinel().async() |
<K,V> RedisSentinelAsyncCommands<K,V> |
connectSentinelAsync(RedisCodec<K,V> codec)
Deprecated.
Use
connectSentinel(codec).async() |
<K,V> RedisSentinelAsyncCommands<K,V> |
connectSentinelAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
Deprecated.
Use
connectSentinel(codec, redisURI).async() |
RedisSentinelAsyncCommands<String,String> |
connectSentinelAsync(RedisURI redisURI)
Deprecated.
Use
connectSentinel(redisURI).async() |
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 SocketAddress |
getSocketAddress(RedisURI redisURI)
Resolve a
RedisURI to a SocketAddress . |
protected long |
makeTimeout() |
protected <K,V> StatefulRedisConnectionImpl<K,V> |
newStatefulRedisConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
|
protected <K,V> StatefulRedisConnectionImpl<K,V> |
newStatefulRedisConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Create a new instance of
StatefulRedisConnectionImpl or a subclass. |
protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> |
newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
|
protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> |
newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Create a new instance of
StatefulRedisPubSubConnectionImpl or a subclass. |
protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> |
newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
|
protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> |
newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Create a new instance of
StatefulRedisSentinelConnectionImpl or a subclass. |
protected RedisCodec<String,String> |
newStringStringCodec()
|
RedisConnectionPool<RedisCommands<String,String>> |
pool()
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
RedisConnectionPool<RedisCommands<String,String>> |
pool(int maxIdle,
int maxActive)
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
<K,V> RedisConnectionPool<RedisCommands<K,V>> |
pool(RedisCodec<K,V> codec,
int maxIdle,
int maxActive)
Deprecated.
Will be removed in future versions. Use
ConnectionPoolSupport . |
void |
setOptions(ClientOptions clientOptions)
Set the
ClientOptions for the client. |
addListener, channelType, connectAsyncImpl, connectionBuilder, getChannelCount, getConnection, getOptions, getResourceCount, initializeChannel, initializeChannelAsync, removeListener, setDefaultTimeout, shutdown, shutdown, shutdownAsync, shutdownAsync
protected RedisClient(ClientResources clientResources, RedisURI redisURI)
@Deprecated public RedisClient()
create()
RedisURI
on
connecting. Methods without having a RedisURI
will fail with a IllegalStateException
.@Deprecated public RedisClient(String host)
create(String)
host
- Server hostname.@Deprecated public RedisClient(String host, int port)
create(RedisURI)
timeout
after 60 seconds.host
- Server hostname.port
- Server port.@Deprecated public RedisClient(RedisURI redisURI)
create(RedisURI)
timeout
after 60 seconds.redisURI
- Redis URI.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 nullRedisClient
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 nullRedisClient
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 nullRedisClient
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 nulluri
- the Redis URI, must not be nullRedisClient
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 nullredisURI
- the Redis URI, must not be nullRedisClient
@Deprecated public RedisConnectionPool<RedisCommands<String,String>> pool()
ConnectionPoolSupport
.RedisConnectionPool
instance@Deprecated public RedisConnectionPool<RedisCommands<String,String>> pool(int maxIdle, int maxActive)
ConnectionPoolSupport
.maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instance@Deprecated public <K,V> RedisConnectionPool<RedisCommands<K,V>> pool(RedisCodec<K,V> codec, int maxIdle, int maxActive)
ConnectionPoolSupport
.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullmaxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instanceprotected long makeTimeout()
@Deprecated public RedisConnectionPool<RedisAsyncCommands<String,String>> asyncPool()
ConnectionPoolSupport
.RedisConnectionPool
instance@Deprecated public RedisConnectionPool<RedisAsyncCommands<String,String>> asyncPool(int maxIdle, int maxActive)
ConnectionPoolSupport
.maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instance@Deprecated public <K,V> RedisConnectionPool<RedisAsyncCommands<K,V>> asyncPool(RedisCodec<K,V> codec, int maxIdle, int maxActive)
ConnectionPoolSupport
.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullmaxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instancepublic StatefulRedisConnection<String,String> connect()
public <K,V> StatefulRedisConnection<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 nullpublic 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 nullpublic <K,V> StatefulRedisConnection<K,V> connect(RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI
and the supplied codec
to
encode/decode keys.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullredisURI
- the Redis server to connect to, must not be null@Deprecated public RedisAsyncCommands<String,String> connectAsync()
@Deprecated public <K,V> RedisAsyncCommands<K,V> connectAsync(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 null@Deprecated public RedisAsyncCommands<String,String> connectAsync(RedisURI redisURI)
connect(redisURI).async()
RedisURI
that treats keys and values as
UTF-8 strings.redisURI
- the Redis server to connect to, must not be null@Deprecated public <K,V> RedisAsyncCommands<K,V> connectAsync(RedisCodec<K,V> codec, RedisURI redisURI)
connect(codec, redisURI).async()
RedisURI
and the supplied
codec
to encode/decode keys.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullredisURI
- the Redis server to connect to, must not be nullpublic 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 nullpublic <K,V> StatefulRedisPubSubConnection<K,V> connectPubSub(RedisCodec<K,V> codec)
RedisURI
and use the supplied
codec
to encode/decode keys and values.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullpublic <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 typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullredisURI
- the Redis server to connect to, must not be nullpublic 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 typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullpublic 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 nullpublic <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 typeV
- Value typecodec
- the Redis server to connect to, must not be nullredisURI
- the Redis server to connect to, must not be null@Deprecated public RedisSentinelAsyncCommands<String,String> connectSentinelAsync()
connectSentinel().async()
@Deprecated public <K,V> RedisSentinelAsyncCommands<K,V> connectSentinelAsync(RedisCodec<K,V> codec)
connectSentinel(codec).async()
codec
to encode/decode
keys and values. You must supply a valid RedisURI containing one or more sentinels.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be null@Deprecated public RedisSentinelAsyncCommands<String,String> connectSentinelAsync(RedisURI redisURI)
connectSentinel(redisURI).async()
RedisURI
that treats keys and values as
UTF-8 strings. You must supply a valid RedisURI containing a redis host or one or more sentinels.redisURI
- the Redis server to connect to, must not be null@Deprecated public <K,V> RedisSentinelAsyncCommands<K,V> connectSentinelAsync(RedisCodec<K,V> codec, RedisURI redisURI)
connectSentinel(codec, redisURI).async()
RedisURI
and use the supplied
codec
to encode/decode keys and values. You must supply a valid RedisURI containing a redis host or
one or more sentinels.K
- Key typeV
- Value typecodec
- Use this codec to encode/decode keys and values, must not be nullredisURI
- the Redis server to connect to, must not be nullpublic void setOptions(ClientOptions clientOptions)
ClientOptions
for the client.setOptions
in class AbstractRedisClient
clientOptions
- the new client optionsIllegalArgumentException
- if clientOptions is nullpublic ClientResources getResources()
ClientResources
which are used with that client.ClientResources
for this client@Deprecated protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisPubSubConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected <K,V> StatefulRedisPubSubConnectionImpl<K,V> newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
StatefulRedisPubSubConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codectimeout
- default timeoutunit
- default timeout unit@Deprecated protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisSentinelConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected <K,V> StatefulRedisSentinelConnectionImpl<K,V> newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
StatefulRedisSentinelConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codectimeout
- default timeoutunit
- default timeout unit@Deprecated protected <K,V> StatefulRedisConnectionImpl<K,V> newStatefulRedisConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected <K,V> StatefulRedisConnectionImpl<K,V> newStatefulRedisConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
StatefulRedisConnectionImpl
or a subclass.
Subclasses of RedisClient
may override that method.
K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codectimeout
- default timeoutunit
- default timeout unitprotected SocketAddress getSocketAddress(RedisURI redisURI) throws InterruptedException, TimeoutException, ExecutionException
RedisURI
to a SocketAddress
. Resolution is performed either using Redis Sentinel (if the
RedisURI
is configured with Sentinels) or via DNS resolution.redisURI
- must not be null.SocketAddress
.InterruptedException
TimeoutException
ExecutionException
ClientResources.dnsResolver()
,
RedisURI.getSentinels()
,
RedisURI.getSentinelMasterId()
protected RedisCodec<String,String> newStringStringCodec()
String
codec
.StringCodec.UTF8
Copyright © 2018 lettuce.io. All rights reserved.