public class JedisClusterConnection extends Object implements DefaultedRedisClusterConnection
RedisClusterConnection implementation on top of JedisCluster.JedisCluster api where possible and falls back to direct node communication using
Jedis where needed.| Modifier and Type | Class and Description |
|---|---|
protected static interface |
JedisClusterConnection.JedisClusterCommandCallback<T>
Jedis specific ClusterCommandExecutor.ClusterCommandCallback. |
static class |
JedisClusterConnection.JedisClusterTopologyProvider
Jedis specific implementation of
ClusterTopologyProvider. |
protected static interface |
JedisClusterConnection.JedisMultiKeyClusterCommandCallback<T>
Jedis specific ClusterCommandExecutor.MultiKeyClusterCommandCallback. |
RedisClusterCommands.AddSlotsRedisStringCommands.BitOperation, RedisStringCommands.SetOptionRedisListCommands.PositionRedisZSetCommands.Aggregate, RedisZSetCommands.Limit, RedisZSetCommands.Range, RedisZSetCommands.Tuple, RedisZSetCommands.WeightsRedisStreamCommands.XAddOptions, RedisStreamCommands.XClaimOptions, RedisStreamCommands.XPendingOptionsRedisGeoCommands.DistanceUnit, RedisGeoCommands.GeoLocation<T>, RedisGeoCommands.GeoRadiusCommandArgs| Constructor and Description |
|---|
JedisClusterConnection(redis.clients.jedis.JedisCluster cluster)
Create new
JedisClusterConnection utilizing native connections via JedisCluster. |
JedisClusterConnection(redis.clients.jedis.JedisCluster cluster,
ClusterCommandExecutor executor)
Create new
JedisClusterConnection utilizing native connections via JedisCluster running commands
across the cluster via given ClusterCommandExecutor. |
JedisClusterConnection(redis.clients.jedis.JedisCluster cluster,
ClusterCommandExecutor executor,
ClusterTopologyProvider topologyProvider)
Create new
JedisClusterConnection utilizing native connections via JedisCluster running commands
across the cluster via given ClusterCommandExecutor and using the given ClusterTopologyProvider. |
| 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.
|
void |
clusterAddSlots(RedisClusterNode node,
int... slots)
Assign slots to given
RedisClusterNode. |
void |
clusterAddSlots(RedisClusterNode node,
RedisClusterNode.SlotRange range)
Assign
RedisClusterNode.SlotRange.getSlotsArray() to given RedisClusterNode. |
Long |
clusterCountKeysInSlot(int slot)
Count the number of keys assigned to one slot.
|
void |
clusterDeleteSlots(RedisClusterNode node,
int... slots)
Remove slots from
RedisClusterNode. |
void |
clusterDeleteSlotsInRange(RedisClusterNode node,
RedisClusterNode.SlotRange range)
Removes
RedisClusterNode.SlotRange.getSlotsArray() from given RedisClusterNode. |
void |
clusterForget(RedisClusterNode node)
Remove given node from cluster.
|
ClusterInfo |
clusterGetClusterInfo()
Get cluster information.
|
List<byte[]> |
clusterGetKeysInSlot(int slot,
Integer count)
Get keys served by slot.
|
Map<RedisClusterNode,Collection<RedisClusterNode>> |
clusterGetMasterSlaveMap()
Retrieve information about masters and their connected slaves.
|
RedisClusterNode |
clusterGetNodeForKey(byte[] key)
Find the
RedisClusterNode serving given key. |
RedisClusterNode |
clusterGetNodeForSlot(int slot)
Find the
RedisClusterNode serving given slot. |
Set<RedisClusterNode> |
clusterGetNodes()
Retrieve cluster node information such as id, host, port and slots.
|
Set<RedisClusterNode> |
clusterGetSlaves(RedisClusterNode master)
Retrieve information about connected slaves for given master node.
|
Integer |
clusterGetSlotForKey(byte[] key)
Find the slot for a given
key. |
void |
clusterMeet(RedisClusterNode node)
Add given node to cluster.
|
void |
clusterReplicate(RedisClusterNode master,
RedisClusterNode replica)
Assign a slave to given master.
|
void |
clusterSetSlot(RedisClusterNode node,
int slot,
RedisClusterCommands.AddSlots mode) |
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.
|
<T> T |
execute(String command,
byte[] key,
Collection<byte[]> args)
Execute the given command for the
key provided potentially appending args. |
<T> List<T> |
execute(String command,
Collection<byte[]> keys,
Collection<byte[]> args)
Execute the given command for each key in
keys provided appending all args on each invocation. |
RedisGeoCommands |
geoCommands()
Get
RedisGeoCommands. |
protected redis.clients.jedis.JedisCluster |
getCluster() |
protected ClusterCommandExecutor |
getClusterCommandExecutor() |
redis.clients.jedis.JedisCluster |
getNativeConnection()
Returns the native connection (the underlying library/driver object).
|
RedisSentinelConnection |
getSentinelConnection() |
Subscription |
getSubscription()
Returns the current subscription for this connection or null if the connection is not subscribed.
|
protected ClusterTopologyProvider |
getTopologyProvider() |
RedisHashCommands |
hashCommands()
Get
RedisHashCommands. |
RedisHyperLogLogCommands |
hyperLogLogCommands()
|
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. |
Set<byte[]> |
keys(RedisClusterNode node,
byte[] pattern) |
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.
|
String |
ping(RedisClusterNode node) |
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.
|
byte[] |
randomKey(RedisClusterNode node) |
Cursor<byte[]> |
scan(RedisClusterNode node,
ScanOptions options)
Use a
Cursor to iterate over keys. |
RedisScriptingCommands |
scriptingCommands()
|
void |
select(int dbIndex)
Select the DB with given positive
dbIndex. |
RedisClusterServerCommands |
serverCommands()
|
RedisSetCommands |
setCommands()
Get
RedisSetCommands. |
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbgReWriteAof, bgSave, dbSize, flushAll, flushDb, getClientList, getConfig, info, info, lastSave, resetConfigStats, save, setConfig, shutdown, timeappend, 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, lPos, 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, xTrim, zAdd, zAdd, zCard, zCount, zCount, zIncrBy, zInterStore, zInterStore, zInterStore, zLexCount, zRange, zRangeByLex, zRangeByScore, zRangeByScore, zRangeByScore, zRangeByScoreWithScores, zRangeWithScores, zRank, zRem, zRemRange, zRemRangeByScore, zRemRangeByScore, zRevRange, zRevRangeByLex, zRevRangeByScore, zRevRangeByScoreWithScores, zRevRangeWithScores, zRevRank, zScan, zScore, zUnionStore, zUnionStore, zUnionStorestreamCommandsrestorebitPoslPoszRangeByLex, zRangeByLex, zRangeByScore, zRangeByScore, zRangeByScore, zRangeByScoreWithScores, zRangeByScoreWithScores, zRangeByScoreWithScores, zRevRangeByLex, zRevRangeByLex, zRevRangeByScore, zRevRangeByScore, zRevRangeByScore, zRevRangeByScoreWithScores, zRevRangeByScoreWithScores, zRevRangeByScoreWithScoresxAck, xAdd, xAdd, xClaim, xDel, xGroupDelConsumer, xPending, xPending, xPending, xPending, xPendinggeoAdd, geoRadiusByMemberpublic JedisClusterConnection(redis.clients.jedis.JedisCluster cluster)
JedisClusterConnection utilizing native connections via JedisCluster.cluster - must not be null.public JedisClusterConnection(redis.clients.jedis.JedisCluster cluster,
ClusterCommandExecutor executor)
JedisClusterConnection utilizing native connections via JedisCluster running commands
across the cluster via given ClusterCommandExecutor. Uses JedisClusterConnection.JedisClusterTopologyProvider by default.cluster - must not be null.executor - must not be null.public JedisClusterConnection(redis.clients.jedis.JedisCluster cluster,
ClusterCommandExecutor executor,
ClusterTopologyProvider topologyProvider)
JedisClusterConnection utilizing native connections via JedisCluster running commands
across the cluster via given ClusterCommandExecutor and using the given ClusterTopologyProvider.cluster - must not be null.executor - must not be null.topologyProvider - must not be null.@Nullable public Object execute(String command, byte[]... args)
RedisCommandsexecute in interface RedisCommandscommand - Command to execute. must not be null.args - Possible command arguments (may be empty).@Nullable public <T> T execute(String command, byte[] key, Collection<byte[]> args)
RedisClusterConnectionkey provided potentially appending args. #execute(String, byte[]...), dispatches the command to the key serving
master node.
// SET foo bar EX 10 NX
execute("SET", "foo".getBytes(), asBinaryList("bar", "EX", 10, "NX"))
execute in interface DefaultedRedisClusterConnectionexecute in interface RedisClusterConnectioncommand - must not be null.key - must not be null.args - must not be null.@Nullable public <T> List<T> execute(String command, Collection<byte[]> keys, Collection<byte[]> args)
keys provided appending all args on each invocation.
#execute(String, byte[]...), dispatches the command to the key serving
master node and appends the key as first command argument to the command. keys are not
required to share the same slot for single-key commands. Multi-key commands carrying their keys in args
still require to share the same slot as the key.
// SET foo bar EX 10 NX
execute("SET", "foo".getBytes(), asBinaryList("bar", "EX", 10, "NX"))
command - must not be null.keys - must not be null.args - must not be null.public RedisGeoCommands geoCommands()
RedisConnectionRedisGeoCommands.geoCommands in interface RedisConnectionpublic RedisHashCommands hashCommands()
RedisConnectionRedisHashCommands.hashCommands in interface RedisConnectionpublic RedisHyperLogLogCommands hyperLogLogCommands()
RedisConnectionhyperLogLogCommands in interface RedisConnectionpublic RedisKeyCommands keyCommands()
RedisConnectionRedisKeyCommands.keyCommands in interface RedisConnectionpublic RedisStringCommands stringCommands()
RedisConnectionRedisStringCommands.stringCommands in interface RedisConnectionpublic RedisListCommands listCommands()
RedisConnectionRedisListCommands.listCommands in interface RedisConnectionpublic RedisSetCommands setCommands()
RedisConnectionRedisSetCommands.setCommands in interface RedisConnectionpublic RedisZSetCommands zSetCommands()
RedisConnectionRedisZSetCommands.zSetCommands in interface RedisConnectionpublic RedisClusterServerCommands serverCommands()
RedisClusterConnectionserverCommands in interface RedisClusterConnectionserverCommands in interface RedisConnectionpublic RedisScriptingCommands scriptingCommands()
RedisConnectionscriptingCommands in interface RedisConnectionpublic Set<byte[]> keys(RedisClusterNode node, byte[] pattern)
keys in interface RedisClusterConnectionnode - must not be null.pattern - must not be null.RedisKeyCommands.keys(byte[])public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options)
RedisClusterConnectionCursor to iterate over keys.scan in interface RedisClusterConnectionnode - must not be null.options - must not be null.public byte[] randomKey(RedisClusterNode node)
randomKey in interface RedisClusterConnectionnode - must not be null.RedisKeyCommands.randomKey()public void multi()
RedisTxCommandsRedisTxCommands.exec() or rolled back using RedisTxCommands.discard()
multi in interface RedisTxCommandspublic List<Object> exec()
RedisTxCommandsRedisTxCommands.multi(). #watch(byte[]...) the operation will fail if any of watched keys has been modified.exec in interface RedisTxCommandspublic void discard()
RedisTxCommandsRedisTxCommands.multi().discard in interface RedisTxCommandspublic void watch(byte[]... keys)
RedisTxCommandskeys for modifications during transaction started with RedisTxCommands.multi().watch in interface RedisTxCommandskeys - must not be null.public void unwatch()
RedisTxCommands#watch(byte[]...) keys.unwatch in interface RedisTxCommandspublic boolean isSubscribed()
RedisPubSubCommandsisSubscribed in interface RedisPubSubCommandspublic Subscription getSubscription()
RedisPubSubCommandsgetSubscription in interface RedisPubSubCommandspublic Long publish(byte[] channel, byte[] message)
RedisPubSubCommandspublish in interface RedisPubSubCommandschannel - the channel to publish to. Must not be null.message - message to publish. 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.
subscribe in interface RedisPubSubCommandslistener - message listener, must not be null.channels - channel names, must not be null.public void pSubscribe(MessageListener listener, byte[]... patterns)
RedisPubSubCommandsNote that this operation is blocking and the current thread starts waiting for new messages immediately.
pSubscribe in interface RedisPubSubCommandslistener - message listener, must not be null.patterns - channel name patterns, must not be null.public void select(int dbIndex)
RedisConnectionCommandsdbIndex.select in interface RedisConnectionCommandsdbIndex - the database index.public byte[] echo(byte[] message)
RedisConnectionCommandsmessage via server roundtrip.echo in interface RedisConnectionCommandsmessage - the message to echo.public String ping()
RedisConnectionCommandsping in interface RedisConnectionCommandspublic String ping(RedisClusterNode node)
ping in interface RedisClusterConnectionnode - must not be null.RedisConnectionCommands.ping()public void clusterSetSlot(RedisClusterNode node, int slot, RedisClusterCommands.AddSlots mode)
clusterSetSlot in interface RedisClusterCommandsnode - must not be null.mode - must not benull.public List<byte[]> clusterGetKeysInSlot(int slot, Integer count)
RedisClusterCommandsclusterGetKeysInSlot in interface RedisClusterCommandscount - must not be null.public void clusterAddSlots(RedisClusterNode node, int... slots)
RedisClusterCommandsRedisClusterNode.clusterAddSlots in interface RedisClusterCommandsnode - must not be null.public void clusterAddSlots(RedisClusterNode node, RedisClusterNode.SlotRange range)
RedisClusterCommandsRedisClusterNode.SlotRange.getSlotsArray() to given RedisClusterNode.clusterAddSlots in interface RedisClusterCommandsnode - must not be null.range - must not be null.public Long clusterCountKeysInSlot(int slot)
RedisClusterCommandsclusterCountKeysInSlot in interface RedisClusterCommandspublic void clusterDeleteSlots(RedisClusterNode node, int... slots)
RedisClusterCommandsRedisClusterNode.clusterDeleteSlots in interface RedisClusterCommandsnode - must not be null.public void clusterDeleteSlotsInRange(RedisClusterNode node, RedisClusterNode.SlotRange range)
RedisClusterCommandsRedisClusterNode.SlotRange.getSlotsArray() from given RedisClusterNode.clusterDeleteSlotsInRange in interface RedisClusterCommandsnode - must not be null.range - must not be null.public void clusterForget(RedisClusterNode node)
RedisClusterCommandsclusterForget in interface RedisClusterCommandsnode - must not be null.public void clusterMeet(RedisClusterNode node)
RedisClusterCommandsclusterMeet in interface RedisClusterCommandsnode - must contain host and RedisNode.getPort() and must
not be null.public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica)
RedisClusterCommandsclusterReplicate in interface RedisClusterCommandsmaster - must not be null.replica - must not be null.public Integer clusterGetSlotForKey(byte[] key)
RedisClusterCommandskey.clusterGetSlotForKey in interface RedisClusterCommandskey - must not be null.public RedisClusterNode clusterGetNodeForSlot(int slot)
RedisClusterCommandsRedisClusterNode serving given slot.clusterGetNodeForSlot in interface RedisClusterCommandspublic Set<RedisClusterNode> clusterGetNodes()
RedisClusterCommandsclusterGetNodes in interface RedisClusterCommandspublic Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master)
RedisClusterCommandsclusterGetSlaves in interface RedisClusterCommandsmaster - must not be null.public Map<RedisClusterNode,Collection<RedisClusterNode>> clusterGetMasterSlaveMap()
RedisClusterCommandsclusterGetMasterSlaveMap in interface RedisClusterCommandspublic RedisClusterNode clusterGetNodeForKey(byte[] key)
RedisClusterCommandsRedisClusterNode serving given key.clusterGetNodeForKey in interface RedisClusterCommandskey - must not be null.public ClusterInfo clusterGetClusterInfo()
RedisClusterCommandsclusterGetClusterInfo in interface RedisClusterCommandsprotected DataAccessException convertJedisAccessException(Exception ex)
public void close()
throws DataAccessException
RedisConnectionclose in interface AutoCloseableclose in interface RedisConnectionDataAccessExceptionpublic boolean isClosed()
RedisConnectionisClosed in interface RedisConnectionpublic redis.clients.jedis.JedisCluster getNativeConnection()
RedisConnectiongetNativeConnection in interface RedisConnectionpublic boolean isQueueing()
RedisConnectionisQueueing in interface RedisConnectionpublic boolean isPipelined()
RedisConnectionisPipelined in interface 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.openPipeline in interface RedisConnectionRedisTxCommands.multi()public List<Object> closePipeline() throws RedisPipelineException
RedisConnectionclosePipeline in interface RedisConnectionRedisPipelineException - if the pipeline contains any incorrect/invalid statementspublic RedisSentinelConnection getSentinelConnection()
getSentinelConnection in interface RedisConnectionprotected redis.clients.jedis.JedisCluster getCluster()
protected ClusterCommandExecutor getClusterCommandExecutor()
protected ClusterTopologyProvider getTopologyProvider()
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.