public class RedisClient extends AbstractRedisClient
RedisClient
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.BUF_ALLOCATOR, channels, clientOptions, closeableResources, connectionEvents, eventLoopGroups, genericWorkerPool, logger, timeout, timer, unit
Constructor and Description |
---|
RedisClient()
Deprecated.
Use the factory method
create() |
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()
Creates a connection pool for asynchronous connections. 5 max idle connections and 20 max active connections.
|
RedisConnectionPool<RedisAsyncCommands<String,String>> |
asyncPool(int maxIdle,
int maxActive)
Creates a connection pool for asynchronous connections.
|
<K,V> RedisConnectionPool<RedisAsyncCommands<K,V>> |
asyncPool(RedisCodec<K,V> codec,
int maxIdle,
int maxActive)
Creates a connection pool for asynchronous connections.
|
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.
|
static RedisClient |
create(RedisURI redisURI)
Create a new client that connects to the supplied
uri . |
static RedisClient |
create(String uri)
Create a new client that connects to the supplied uri.
|
protected SocketAddress |
getSocketAddress(RedisURI redisURI) |
protected long |
makeTimeout() |
protected <K,V> StatefulRedisConnectionImpl<K,V> |
newStatefulRedisConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
Create a new instance of
StatefulRedisConnectionImpl or a subclass. |
protected <K,V> StatefulRedisPubSubConnectionImpl<K,V> |
newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
Create a new instance of
StatefulRedisPubSubConnectionImpl or a subclass. |
protected <K,V> StatefulRedisSentinelConnectionImpl<K,V> |
newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler,
RedisCodec<K,V> codec)
Create a new instance of
StatefulRedisSentinelConnectionImpl or a subclass. |
protected Utf8StringCodec |
newStringStringCodec() |
RedisConnectionPool<RedisCommands<String,String>> |
pool()
Creates a connection pool for synchronous connections. 5 max idle connections and 20 max active connections.
|
RedisConnectionPool<RedisCommands<String,String>> |
pool(int maxIdle,
int maxActive)
Creates a connection pool for synchronous connections.
|
<K,V> RedisConnectionPool<RedisCommands<K,V>> |
pool(RedisCodec<K,V> codec,
int maxIdle,
int maxActive)
Creates a connection pool for synchronous connections.
|
void |
setOptions(ClientOptions clientOptions)
Set the
ClientOptions for the client. |
addListener, channelType, connectAsyncImpl, connectionBuilder, getChannelCount, getOptions, getResourceCount, initializeChannel, removeListener, setDefaultTimeout, shutdown, shutdown
@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()
RedisURI
on
connecting. Methods without having a RedisURI
will fail with a IllegalStateException
.RedisClient
public static RedisClient 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 nullRedisClient
public static RedisClient create(String uri)
RedisURI
on connecting.uri
- the Redis URI, must not be nullRedisClient
public RedisConnectionPool<RedisCommands<String,String>> pool()
RedisConnectionPool
instancepublic RedisConnectionPool<RedisCommands<String,String>> pool(int maxIdle, int maxActive)
maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instancepublic <K,V> RedisConnectionPool<RedisCommands<K,V>> pool(RedisCodec<K,V> codec, int maxIdle, int maxActive)
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()
public RedisConnectionPool<RedisAsyncCommands<String,String>> asyncPool()
RedisConnectionPool
instancepublic RedisConnectionPool<RedisAsyncCommands<String,String>> asyncPool(int maxIdle, int maxActive)
maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instancepublic <K,V> RedisConnectionPool<RedisAsyncCommands<K,V>> asyncPool(RedisCodec<K,V> codec, int maxIdle, int maxActive)
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 nullprotected <K,V> StatefulRedisPubSubConnectionImpl<K,V> newStatefulRedisPubSubConnection(PubSubCommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisPubSubConnectionImpl
or a subclass.K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected <K,V> StatefulRedisSentinelConnectionImpl<K,V> newStatefulRedisSentinelConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisSentinelConnectionImpl
or a subclass.K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected <K,V> StatefulRedisConnectionImpl<K,V> newStatefulRedisConnection(CommandHandler<K,V> commandHandler, RedisCodec<K,V> codec)
StatefulRedisConnectionImpl
or a subclass.K
- Key-TypeV
- Value TypecommandHandler
- the command handlercodec
- codecprotected SocketAddress getSocketAddress(RedisURI redisURI) throws InterruptedException, TimeoutException, ExecutionException
protected Utf8StringCodec newStringStringCodec()
public void setOptions(ClientOptions clientOptions)
ClientOptions
for the client.setOptions
in class AbstractRedisClient
clientOptions
- the new client optionsIllegalArgumentException
- if clientOptions is nullCopyright © 2015. All rights reserved.