public class JedisConnection extends AbstractRedisConnection
RedisConnection
implementation on top of Jedis library.RedisStringCommands.BitOperation, RedisStringCommands.SetOption
RedisListCommands.Position
RedisZSetCommands.Aggregate, RedisZSetCommands.Limit, RedisZSetCommands.Range, RedisZSetCommands.Tuple, RedisZSetCommands.Weights
RedisServerCommands.MigrateOption, RedisServerCommands.ShutdownOption
RedisGeoCommands.DistanceUnit, RedisGeoCommands.GeoLocation<T>, RedisGeoCommands.GeoRadiusCommandArgs
Modifier | Constructor and Description |
---|---|
|
JedisConnection(redis.clients.jedis.Jedis jedis)
Constructs a new
JedisConnection instance. |
|
JedisConnection(redis.clients.jedis.Jedis jedis,
redis.clients.util.Pool<redis.clients.jedis.Jedis> pool,
int dbIndex)
Constructs a new
JedisConnection instance backed by a jedis pool. |
protected |
JedisConnection(redis.clients.jedis.Jedis jedis,
redis.clients.util.Pool<redis.clients.jedis.Jedis> pool,
int dbIndex,
String clientName)
Constructs a new
JedisConnection instance backed by a jedis pool. |
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 |
convertJedisAccessException(Exception ex) |
void |
discard()
Discard all commands issued after
RedisTxCommands.multi() . |
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.
|
RedisGeoCommands |
geoCommands()
Get
RedisGeoCommands . |
redis.clients.jedis.Jedis |
getJedis() |
protected redis.clients.jedis.Jedis |
getJedis(RedisNode node) |
redis.clients.jedis.Jedis |
getNativeConnection()
Returns the native connection (the underlying library/driver object).
|
redis.clients.jedis.Pipeline |
getPipeline() |
redis.clients.jedis.Pipeline |
getRequiredPipeline() |
redis.clients.jedis.Transaction |
getRequiredTransaction() |
protected JedisSentinelConnection |
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.
|
redis.clients.jedis.Transaction |
getTransaction() |
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 results should be converted to the expected data type.
|
RedisStringCommands |
stringCommands()
Get
RedisStringCommands . |
void |
subscribe(MessageListener listener,
byte[]... channels)
Subscribes the connection to the given channels.
|
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, setSentinelConfiguration
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
append, 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, 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, zUnionStore
restore
bitPos
zRangeByLex, zRangeByLex, zRangeByScore, zRangeByScore, zRangeByScore, zRangeByScoreWithScores, zRangeByScoreWithScores, zRangeByScoreWithScores, zRevRangeByScore, zRevRangeByScore, zRevRangeByScore, zRevRangeByScoreWithScores, zRevRangeByScoreWithScores, zRevRangeByScoreWithScores
geoAdd, geoRadiusByMember
public JedisConnection(redis.clients.jedis.Jedis jedis)
JedisConnection
instance.jedis
- Jedis entitypublic JedisConnection(redis.clients.jedis.Jedis jedis, redis.clients.util.Pool<redis.clients.jedis.Jedis> pool, int dbIndex)
JedisConnection
instance backed by a jedis pool.jedis
- pool
- can be null, if no pool is useddbIndex
- protected JedisConnection(redis.clients.jedis.Jedis jedis, @Nullable redis.clients.util.Pool<redis.clients.jedis.Jedis> pool, int dbIndex, String clientName)
JedisConnection
instance backed by a jedis pool.jedis
- pool
- can be null, if no pool is useddbIndex
- clientName
- the client name, can be null.protected DataAccessException convertJedisAccessException(Exception ex)
public RedisKeyCommands keyCommands()
RedisConnection
RedisKeyCommands
.public RedisStringCommands stringCommands()
RedisConnection
RedisStringCommands
.public RedisListCommands listCommands()
RedisConnection
RedisListCommands
.public RedisSetCommands setCommands()
RedisConnection
RedisSetCommands
.public RedisZSetCommands zSetCommands()
RedisConnection
RedisZSetCommands
.public RedisHashCommands hashCommands()
RedisConnection
RedisHashCommands
.public RedisGeoCommands geoCommands()
RedisConnection
RedisGeoCommands
.public RedisScriptingCommands scriptingCommands()
RedisConnection
public RedisServerCommands serverCommands()
RedisConnection
RedisServerCommands
.public RedisHyperLogLogCommands hyperLogLogCommands()
RedisConnection
public Object execute(String command, byte[]... args)
RedisCommands
command
- Command to execute. must not be null.args
- Possible command arguments (may be empty).public void close() throws DataAccessException
RedisConnection
close
in interface RedisConnection
close
in class AbstractRedisConnection
DataAccessException
public redis.clients.jedis.Jedis getNativeConnection()
RedisConnection
public boolean isClosed()
RedisConnection
public boolean isQueueing()
RedisConnection
public boolean isPipelined()
RedisConnection
RedisConnection.openPipeline()
,
RedisConnection.isQueueing()
public void openPipeline()
RedisConnection
RedisConnection.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()
RedisConnection
public byte[] echo(byte[] message)
RedisConnectionCommands
message
via server roundtrip.message
- the message to echo.public String ping()
RedisConnectionCommands
public void discard()
RedisTxCommands
RedisTxCommands.multi()
.public List<Object> exec()
RedisTxCommands
RedisTxCommands.multi()
. #watch(byte[]...)
the operation will fail if any of watched keys has been modified.@Nullable public redis.clients.jedis.Pipeline getPipeline()
public redis.clients.jedis.Pipeline getRequiredPipeline()
@Nullable public redis.clients.jedis.Transaction getTransaction()
public redis.clients.jedis.Transaction getRequiredTransaction()
public redis.clients.jedis.Jedis getJedis()
public void multi()
RedisTxCommands
RedisTxCommands.exec()
or rolled back using RedisTxCommands.discard()
public void select(int dbIndex)
RedisConnectionCommands
dbIndex
.dbIndex
- the database index.public void unwatch()
RedisTxCommands
#watch(byte[]...)
keys.public void watch(byte[]... keys)
RedisTxCommands
keys
for modifications during transaction started with RedisTxCommands.multi()
.keys
- must not be null.public Long publish(byte[] channel, byte[] message)
RedisPubSubCommands
channel
- the channel to publish to. Must not be null.message
- message to publish. Must not be null.public Subscription getSubscription()
RedisPubSubCommands
public boolean isSubscribed()
RedisPubSubCommands
public void pSubscribe(MessageListener listener, byte[]... patterns)
RedisPubSubCommands
Note 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)
RedisPubSubCommands
Note 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 Jedis driverconvertPipelineAndTxResults
- Whether or not to convert pipeline and tx resultsprotected boolean isActive(RedisNode node)
AbstractRedisConnection
isActive
in class AbstractRedisConnection
protected JedisSentinelConnection getSentinelConnection(RedisNode sentinel)
AbstractRedisConnection
RedisSentinelCommands
connected to given node.getSentinelConnection
in class AbstractRedisConnection
protected redis.clients.jedis.Jedis getJedis(RedisNode node)
Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.