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, eventLoopGroup, eventLoopGroups, genericWorkerPool, logger, timeout, timer, unit
Constructor and Description |
---|
RedisClient()
Creates a uri-less RedisClient.
|
RedisClient(RedisURI redisURI)
Create a new client that connects to the supplied host and port.
|
RedisClient(String host)
Create a new client that connects to the supplied host on the default port.
|
RedisClient(String host,
int port)
Create a new client that connects to the supplied host and port.
|
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. |
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.
|
addListener, channelType, connectAsyncImpl, connectionBuilder, getChannelCount, getOptions, getResourceCount, initializeChannel, removeListener, setDefaultTimeout, setOptions, shutdown, shutdown, syncHandler
public RedisClient()
RedisURI
on
connecting. Methods without having a RedisURI
will fail with a IllegalStateException
.public RedisClient(String host)
host
- Server hostname.public RedisClient(String host, int port)
timeout
after 60 seconds.host
- Server hostname.port
- Server port.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 unitprotected SocketAddress getSocketAddress(RedisURI redisURI) throws InterruptedException, TimeoutException, ExecutionException
protected Utf8StringCodec newStringStringCodec()
Copyright © 2015. All rights reserved.