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, 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<RedisAsyncConnection<String,String>> |
asyncPool()
Creates a connection pool for asynchronous connections. 5 max idle connections and 20 max active connections.
|
RedisConnectionPool<RedisAsyncConnection<String,String>> |
asyncPool(int maxIdle,
int maxActive)
Creates a connection pool for asynchronous connections.
|
<K,V> RedisConnectionPool<RedisAsyncConnection<K,V>> |
asyncPool(RedisCodec<K,V> codec,
int maxIdle,
int maxActive)
Creates a connection pool for asynchronous connections.
|
RedisConnection<String,String> |
connect()
Open a new synchronous connection to a Redis server that treats keys and values as UTF-8 strings.
|
<K,V> RedisConnection<K,V> |
connect(RedisCodec<K,V> codec)
Open a new synchronous connection to a Redis server.
|
<K,V> RedisConnection |
connect(RedisCodec<K,V> codec,
RedisURI redisURI)
|
RedisConnection<String,String> |
connect(RedisURI redisURI)
Open a new synchronous connection to a Redis server using the supplied
RedisURI that treats keys and values as
UTF-8 strings. |
RedisAsyncConnection<String,String> |
connectAsync()
Open a new asynchronous connection to a Redis server that treats keys and values as UTF-8 strings.
|
<K,V> RedisAsyncConnection<K,V> |
connectAsync(RedisCodec<K,V> codec)
Open a new asynchronous connection to a Redis server.
|
<K,V> RedisAsyncConnection<K,V> |
connectAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
|
RedisAsyncConnection<String,String> |
connectAsync(RedisURI redisURI)
Open a new asynchronous connection to a Redis server using the supplied
RedisURI that treats keys and values as
UTF-8 strings. |
RedisPubSubConnection<String,String> |
connectPubSub()
Open a new pub/sub connection to a Redis server that treats keys and values as UTF-8 strings.
|
<K,V> RedisPubSubConnection<K,V> |
connectPubSub(RedisCodec<K,V> codec)
|
<K,V> RedisPubSubConnection<K,V> |
connectPubSub(RedisCodec<K,V> codec,
RedisURI redisURI)
|
RedisPubSubConnection<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. |
RedisSentinelAsyncConnection<String,String> |
connectSentinelAsync()
Open a new asynchronous connection to a Redis Sentinel that treats keys and values as UTF-8 strings.
|
<K,V> RedisSentinelAsyncConnection<K,V> |
connectSentinelAsync(RedisCodec<K,V> codec)
Open a new asynchronous connection to a Redis Sentinela nd use the supplied
codec to encode/decode
keys and values. |
<K,V> RedisSentinelAsyncConnection<K,V> |
connectSentinelAsync(RedisCodec<K,V> codec,
RedisURI redisURI)
|
RedisSentinelAsyncConnection<String,String> |
connectSentinelAsync(RedisURI redisURI)
Open a new asynchronous connection to a Redis Sentinel using the supplied
RedisURI that treats keys and values as
UTF-8 strings. |
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) |
protected long |
makeTimeout() |
protected <K,V> RedisAsyncConnectionImpl<K,V> |
newRedisAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Construct a new
RedisAsyncConnectionImpl . |
protected <K,V> RedisPubSubConnectionImpl<K,V> |
newRedisPubSubConnectionImpl(RedisChannelWriter<K,V> channelWriter,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Construct a new
RedisPubSubConnectionImpl . |
protected <K,V> com.lambdaworks.redis.RedisSentinelAsyncConnectionImpl<K,V> |
newRedisSentinelAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Construct a new
RedisSentinelAsyncConnectionImpl . |
protected Utf8StringCodec |
newStringStringCodec() |
RedisConnectionPool<RedisConnection<String,String>> |
pool()
Creates a connection pool for synchronous connections. 5 max idle connections and 20 max active connections.
|
RedisConnectionPool<RedisConnection<String,String>> |
pool(int maxIdle,
int maxActive)
Creates a connection pool for synchronous connections.
|
<K,V> RedisConnectionPool<RedisConnection<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, syncHandler
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
public RedisConnectionPool<RedisConnection<String,String>> pool()
RedisConnectionPool
instancepublic RedisConnectionPool<RedisConnection<String,String>> pool(int maxIdle, int maxActive)
maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instancepublic <K,V> RedisConnectionPool<RedisConnection<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<RedisAsyncConnection<String,String>> asyncPool()
RedisConnectionPool
instancepublic RedisConnectionPool<RedisAsyncConnection<String,String>> asyncPool(int maxIdle, int maxActive)
maxIdle
- max idle connections in poolmaxActive
- max active connections in poolRedisConnectionPool
instancepublic <K,V> RedisConnectionPool<RedisAsyncConnection<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 RedisConnection<String,String> connect()
public <K,V> RedisConnection<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 RedisConnection<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> RedisConnection 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 nullpublic RedisAsyncConnection<String,String> connectAsync()
public <K,V> RedisAsyncConnection<K,V> connectAsync(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 RedisAsyncConnection<String,String> connectAsync(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> RedisAsyncConnection<K,V> connectAsync(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 nullpublic RedisPubSubConnection<String,String> connectPubSub()
public RedisPubSubConnection<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> RedisPubSubConnection<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> RedisPubSubConnection<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 RedisSentinelAsyncConnection<String,String> connectSentinelAsync()
public <K,V> RedisSentinelAsyncConnection<K,V> connectSentinelAsync(RedisCodec<K,V> codec)
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 nullpublic RedisSentinelAsyncConnection<String,String> connectSentinelAsync(RedisURI redisURI)
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 nullpublic <K,V> RedisSentinelAsyncConnection<K,V> connectSentinelAsync(RedisCodec<K,V> codec, RedisURI redisURI)
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> 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
K
- Key type.V
- Value type.channelWriter
- the channel writercodec
- the codec to usetimeout
- Timeout valueunit
- Timeout unitprotected <K,V> com.lambdaworks.redis.RedisSentinelAsyncConnectionImpl<K,V> newRedisSentinelAsyncConnectionImpl(RedisChannelWriter<K,V> channelWriter, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
RedisSentinelAsyncConnectionImpl
. Can be overridden in order to construct a subclass of
RedisSentinelAsyncConnectionImpl
K
- Key type.V
- Value type.channelWriter
- the channel writercodec
- the codec to usetimeout
- Timeout valueunit
- Timeout unitprotected <K,V> RedisPubSubConnectionImpl<K,V> newRedisPubSubConnectionImpl(RedisChannelWriter<K,V> channelWriter, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
RedisPubSubConnectionImpl
. Can be overridden in order to construct a subclass of
RedisPubSubConnectionImpl
K
- Key type.V
- Value type.channelWriter
- the channel writercodec
- the codec to usetimeout
- Timeout valueunit
- Timeout unitpublic ClientResources getResources()
ClientResources
which are used with that client.ClientResources
for this clientprotected 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 © 2016. All rights reserved.