public class LettuceConnection extends AbstractRedisConnection
RedisConnection implementation on top of Lettuce Redis
client.| Modifier and Type | Class and Description |
|---|---|
static interface |
LettuceConnection.PipeliningFlushPolicy
Strategy interface to control pipelining flush behavior.
|
static interface |
LettuceConnection.PipeliningFlushState
State object associated with flushing of the currently ongoing pipeline.
|
RedisStringCommands.BitOperation, RedisStringCommands.SetOptionRedisListCommands.PositionRedisZSetCommands.Aggregate, RedisZSetCommands.Limit, RedisZSetCommands.Range, RedisZSetCommands.Tuple, RedisZSetCommands.WeightsRedisServerCommands.MigrateOption, RedisServerCommands.ShutdownOptionRedisStreamCommands.XAddOptions, RedisStreamCommands.XClaimOptions, RedisStreamCommands.XPendingOptionsRedisGeoCommands.DistanceUnit, RedisGeoCommands.GeoLocation<T>, RedisGeoCommands.GeoRadiusCommandArgs| Constructor and Description |
|---|
LettuceConnection(long timeout,
io.lettuce.core.RedisClient client)
Instantiates a new lettuce connection.
|
LettuceConnection(long timeout,
io.lettuce.core.RedisClient client,
LettucePool pool)
Deprecated.
since 2.0, use pooling via
LettucePoolingClientConfiguration. |
LettuceConnection(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection,
LettuceConnectionProvider connectionProvider,
long timeout,
int defaultDbIndex) |
LettuceConnection(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection,
long timeout,
io.lettuce.core.AbstractRedisClient client,
LettucePool pool,
int defaultDbIndex)
Deprecated.
|
LettuceConnection(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection,
long timeout,
io.lettuce.core.RedisClient client)
Instantiates a new lettuce connection.
|
LettuceConnection(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection,
long timeout,
io.lettuce.core.RedisClient client,
LettucePool pool)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes (or quits) the connection.
|
List<Object> |
closePipeline()
Executes the commands in the pipeline and returns their result.
|
protected DataAccessException |
convertLettuceAccessException(Exception ex) |
void |
discard()
Discard all commands issued after
RedisTxCommands.multi(). |
protected LettuceSubscription |
doCreateSubscription(MessageListener listener,
io.lettuce.core.pubsub.StatefulRedisPubSubConnection<byte[],byte[]> connection,
LettuceConnectionProvider connectionProvider)
Customization hook to create a
LettuceSubscription. |
protected io.lettuce.core.api.StatefulConnection<byte[],byte[]> |
doGetAsyncDedicatedConnection() |
byte[] |
echo(byte[] message)
Returns
message via server roundtrip. |
List<Object> |
exec()
Executes all queued commands in a transaction started with
RedisTxCommands.multi(). |
Object |
execute(String command,
byte[]... args)
'Native' or 'raw' execution of the given command along-side the given arguments.
|
Object |
execute(String command,
io.lettuce.core.output.CommandOutput commandOutputTypeHint,
byte[]... args)
'Native' or 'raw' execution of the given command along-side the given arguments.
|
RedisGeoCommands |
geoCommands()
Get
RedisGeoCommands. |
protected io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands<byte[],byte[]> |
getAsyncDedicatedConnection() |
protected io.lettuce.core.cluster.api.sync.RedisClusterCommands<byte[],byte[]> |
getConnection() |
io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands<byte[],byte[]> |
getNativeConnection()
Returns the native connection (the underlying library/driver object).
|
protected RedisSentinelConnection |
getSentinelConnection(RedisNode sentinel)
Get
RedisSentinelCommands connected to given node. |
Subscription |
getSubscription()
Returns the current subscription for this connection or null if the connection is not subscribed.
|
RedisHashCommands |
hashCommands()
Get
RedisHashCommands. |
RedisHyperLogLogCommands |
hyperLogLogCommands()
|
protected boolean |
isActive(RedisNode node)
Check if node is active by sending ping.
|
boolean |
isClosed()
Indicates whether the underlying connection is closed or not.
|
boolean |
isPipelined()
Indicates whether the connection is currently pipelined or not.
|
boolean |
isQueueing()
Indicates whether the connection is in "queue"(or "MULTI") mode or not.
|
boolean |
isSubscribed()
Indicates whether the current connection is subscribed (to at least one channel) or not.
|
RedisKeyCommands |
keyCommands()
Get
RedisKeyCommands. |
RedisListCommands |
listCommands()
Get
RedisListCommands. |
void |
multi()
Mark the start of a transaction block.
|
void |
openPipeline()
Activates the pipeline mode for this connection.
|
String |
ping()
Test connection.
|
void |
pSubscribe(MessageListener listener,
byte[]... patterns)
Subscribes the connection to all channels matching the given patterns.
|
Long |
publish(byte[] channel,
byte[] message)
Publishes the given message to the given channel.
|
RedisScriptingCommands |
scriptingCommands()
|
void |
select(int dbIndex)
Select the DB with given positive
dbIndex. |
RedisServerCommands |
serverCommands()
Get
RedisServerCommands. |
RedisSetCommands |
setCommands()
Get
RedisSetCommands. |
void |
setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults)
Specifies if pipelined and transaction results should be converted to the expected data type.
|
void |
setPipeliningFlushPolicy(LettuceConnection.PipeliningFlushPolicy pipeliningFlushPolicy)
Configures the flushing policy when using pipelining.
|
RedisStreamCommands |
streamCommands()
Get
RedisStreamCommands. |
RedisStringCommands |
stringCommands()
Get
RedisStringCommands. |
void |
subscribe(MessageListener listener,
byte[]... channels)
Subscribes the connection to the given channels.
|
protected io.lettuce.core.pubsub.StatefulRedisPubSubConnection<byte[],byte[]> |
switchToPubSub()
close() the current connection and open a new pub/sub connection to the Redis server. |
void |
unwatch()
Flushes all the previously
#watch(byte[]...) keys. |
void |
watch(byte[]... keys)
Watch given
keys for modifications during transaction started with RedisTxCommands.multi(). |
RedisZSetCommands |
zSetCommands()
Get
RedisZSetCommands. |
getSentinelConnection, hasRedisSentinelConfigured, setSentinelConfigurationclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitappend, bgReWriteAof, bgSave, bgWriteAof, bitCount, bitCount, bitField, bitOp, bitPos, bLPop, bRPop, bRPopLPush, dbSize, decr, decrBy, del, dump, encodingOf, eval, evalSha, evalSha, exists, exists, expire, expireAt, flushAll, flushDb, geoAdd, geoAdd, geoAdd, geoDist, geoDist, geoHash, geoPos, geoRadius, geoRadius, geoRadiusByMember, geoRadiusByMember, geoRemove, get, getBit, getClientList, getClientName, getConfig, getRange, getSet, hDel, hExists, hGet, hGetAll, hIncrBy, hIncrBy, hKeys, hLen, hMGet, hMSet, hScan, hSet, hSetNX, hStrLen, hVals, idletime, incr, incrBy, incrBy, info, info, keys, killClient, lastSave, lIndex, lInsert, lLen, lPop, lPush, lPushX, lRange, lRem, lSet, lTrim, mGet, migrate, migrate, move, mSet, mSetNX, persist, pExpire, pExpireAt, pfAdd, pfCount, pfMerge, pSetEx, pTtl, pTtl, randomKey, refcount, rename, renameNX, resetConfigStats, restore, rPop, rPopLPush, rPush, rPushX, sAdd, save, scan, sCard, scriptExists, scriptFlush, scriptKill, scriptLoad, sDiff, sDiffStore, set, set, setBit, setClientName, setConfig, setEx, setNX, setRange, shutdown, shutdown, sInter, sInterStore, sIsMember, slaveOf, slaveOfNoOne, sMembers, sMove, sort, sort, sPop, sPop, sRandMember, sRandMember, sRem, sScan, strLen, sUnion, sUnionStore, time, touch, ttl, ttl, type, unlink, xAck, xAdd, xClaim, xClaimJustId, xDel, xGroupCreate, xGroupCreate, xGroupDelConsumer, xGroupDestroy, xInfo, xInfoConsumers, xInfoGroups, xLen, xPending, xPending, xRange, xRange, xRead, xRead, xReadGroup, xReadGroup, xRevRange, xRevRange, xTrim, zAdd, zAdd, zCard, zCount, zCount, zIncrBy, zInterStore, zInterStore, zInterStore, zRange, zRangeByLex, zRangeByScore, zRangeByScore, zRangeByScore, zRangeByScoreWithScores, zRangeWithScores, zRank, zRem, zRemRange, zRemRangeByScore, zRemRangeByScore, zRevRange, zRevRangeByScore, zRevRangeByScoreWithScores, zRevRangeWithScores, zRevRank, zScan, zScore, zUnionStore, zUnionStore, zUnionStorerestorebitPoszRangeByLex, zRangeByLex, zRangeByScore, zRangeByScore, zRangeByScore, zRangeByScoreWithScores, zRangeByScoreWithScores, zRangeByScoreWithScores, zRevRangeByScore, zRevRangeByScore, zRevRangeByScore, zRevRangeByScoreWithScores, zRevRangeByScoreWithScores, zRevRangeByScoreWithScoresxAck, xAdd, xAdd, xClaim, xDel, xGroupDelConsumer, xPending, xPending, xPending, xPending, xPendinggeoAdd, geoRadiusByMemberpublic LettuceConnection(long timeout,
io.lettuce.core.RedisClient client)
timeout - The connection timeout (in milliseconds)client - The RedisClient to use when instantiating a native connection@Deprecated public LettuceConnection(long timeout, io.lettuce.core.RedisClient client, LettucePool pool)
LettucePoolingClientConfiguration.timeout - The connection timeout (in milliseconds) * @param client The RedisClient to use when
instantiating a pub/sub connectionpool - The connection pool to use for all other native connectionspublic LettuceConnection(@Nullable io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection, long timeout, io.lettuce.core.RedisClient client)
sharedConnection - A native connection that is shared with other LettuceConnections. Will not be used
for transactions or blocking operationstimeout - The connection timeout (in milliseconds)client - The RedisClient to use when making pub/sub, blocking, and tx connections@Deprecated public LettuceConnection(@Nullable io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection, long timeout, io.lettuce.core.RedisClient client, @Nullable LettucePool pool)
LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)sharedConnection - A native connection that is shared with other LettuceConnections. Should not be
used for transactions or blocking operationstimeout - The connection timeout (in milliseconds)client - The RedisClient to use when making pub/sub connectionspool - The connection pool to use for blocking and tx operations@Deprecated public LettuceConnection(@Nullable io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection, long timeout, @Nullable io.lettuce.core.AbstractRedisClient client, @Nullable LettucePool pool, int defaultDbIndex)
LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)sharedConnection - A native connection that is shared with other LettuceConnections. Should not be
used for transactions or blocking operations.timeout - The connection timeout (in milliseconds)client - The RedisClient to use when making pub/sub connections.pool - The connection pool to use for blocking and tx operations.defaultDbIndex - The db index to use along with RedisClient when establishing a dedicated connection.public LettuceConnection(@Nullable io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, long timeout, int defaultDbIndex)
sharedConnection - A native connection that is shared with other LettuceConnections. Should not be
used for transactions or blocking operations.connectionProvider - connection provider to obtain and release native connections.timeout - The connection timeout (in milliseconds)defaultDbIndex - The db index to use along with RedisClient when establishing a dedicated connection.protected DataAccessException convertLettuceAccessException(Exception ex)
public RedisGeoCommands geoCommands()
RedisConnectionRedisGeoCommands.public RedisHashCommands hashCommands()
RedisConnectionRedisHashCommands.public RedisHyperLogLogCommands hyperLogLogCommands()
RedisConnectionpublic RedisKeyCommands keyCommands()
RedisConnectionRedisKeyCommands.public RedisListCommands listCommands()
RedisConnectionRedisListCommands.public RedisSetCommands setCommands()
RedisConnectionRedisSetCommands.public RedisScriptingCommands scriptingCommands()
RedisConnectionpublic RedisStreamCommands streamCommands()
RedisConnectionRedisStreamCommands.public RedisStringCommands stringCommands()
RedisConnectionRedisStringCommands.public RedisServerCommands serverCommands()
RedisConnectionRedisServerCommands.public RedisZSetCommands zSetCommands()
RedisConnectionRedisZSetCommands.public Object execute(String command, byte[]... args)
RedisCommandscommand - Command to execute. must not be null.args - Possible command arguments (may be empty).@Nullable public Object execute(String command, @Nullable io.lettuce.core.output.CommandOutput commandOutputTypeHint, byte[]... args)
command - Command to executecommandOutputTypeHint - Type of Output to use, may be (may be null).args - Possible command arguments (may be null)RedisConnection#execute(String, byte[]...)public void close()
throws DataAccessException
RedisConnectionclose in interface AutoCloseableclose in interface RedisConnectionclose in class AbstractRedisConnectionDataAccessExceptionpublic boolean isClosed()
RedisConnectionpublic io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands<byte[],byte[]> getNativeConnection()
RedisConnectionpublic boolean isQueueing()
RedisConnectionpublic boolean isPipelined()
RedisConnectionRedisConnection.openPipeline(),
RedisConnection.isQueueing()public void openPipeline()
RedisConnectionRedisConnection.closePipeline(). Calling this method when the connection is already pipelined has no effect.
Pipelining is used for issuing commands without requesting the response right away but rather at the end of the
batch. While somewhat similar to MULTI, pipelining does not guarantee atomicity - it only tries to improve
performance when issuing a lot of commands (such as in batching scenarios).
Note:
Consider doing some performance testing before using this feature since in many cases the performance benefits are minimal yet the impact on usage are not.RedisTxCommands.multi()public List<Object> closePipeline()
RedisConnectionpublic byte[] echo(byte[] message)
RedisConnectionCommandsmessage via server roundtrip.message - the message to echo.public String ping()
RedisConnectionCommandspublic void discard()
RedisTxCommandsRedisTxCommands.multi().public List<Object> exec()
RedisTxCommandsRedisTxCommands.multi(). #watch(byte[]...) the operation will fail if any of watched keys has been modified.public void multi()
RedisTxCommandsRedisTxCommands.exec() or rolled back using RedisTxCommands.discard()
public void select(int dbIndex)
RedisConnectionCommandsdbIndex.dbIndex - the database index.public void unwatch()
RedisTxCommands#watch(byte[]...) keys.public void watch(byte[]... keys)
RedisTxCommandskeys for modifications during transaction started with RedisTxCommands.multi().keys - must not be null.public Long publish(byte[] channel, byte[] message)
RedisPubSubCommandschannel - the channel to publish to. Must not be null.message - message to publish. Must not be null.public Subscription getSubscription()
RedisPubSubCommandspublic boolean isSubscribed()
RedisPubSubCommandspublic void pSubscribe(MessageListener listener, byte[]... patterns)
RedisPubSubCommandsNote that this operation is blocking and the current thread starts waiting for new messages immediately.
listener - message listener, must not be null.patterns - channel name patterns, must not be null.public void subscribe(MessageListener listener, byte[]... channels)
RedisPubSubCommandsNote that this operation is blocking and the current thread starts waiting for new messages immediately.
listener - message listener, must not be null.channels - channel names, must not be null.public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults)
closePipeline() and exec() will be of the type returned by the Lettuce driverconvertPipelineAndTxResults - Whether or not to convert pipeline and tx resultspublic void setPipeliningFlushPolicy(LettuceConnection.PipeliningFlushPolicy pipeliningFlushPolicy)
pipeliningFlushPolicy - the flushing policy to control when commands get written to the Redis connection.LettuceConnection.PipeliningFlushPolicy.flushEachCommand(),
openPipeline(),
StatefulConnection.flushCommands()protected io.lettuce.core.pubsub.StatefulRedisPubSubConnection<byte[],byte[]> switchToPubSub()
close() the current connection and open a new pub/sub connection to the Redis server.protected LettuceSubscription doCreateSubscription(MessageListener listener, io.lettuce.core.pubsub.StatefulRedisPubSubConnection<byte[],byte[]> connection, LettuceConnectionProvider connectionProvider)
LettuceSubscription.listener - the MessageListener to notify.connection - Pub/Sub connection.connectionProvider - the LettuceConnectionProvider for connection release.LettuceSubscription.protected io.lettuce.core.cluster.api.sync.RedisClusterCommands<byte[],byte[]> getConnection()
protected io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands<byte[],byte[]> getAsyncDedicatedConnection()
protected io.lettuce.core.api.StatefulConnection<byte[],byte[]> doGetAsyncDedicatedConnection()
protected boolean isActive(RedisNode node)
AbstractRedisConnectionisActive in class AbstractRedisConnectionprotected RedisSentinelConnection getSentinelConnection(RedisNode sentinel)
AbstractRedisConnectionRedisSentinelCommands connected to given node.getSentinelConnection in class AbstractRedisConnectionCopyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.