public class RedisClusterClient extends UnifiedJedis
This class is intended as a modern replacement for the deprecated JedisCluster class. It
supports all cluster operations and is designed to work seamlessly with the UnifiedJedis
API, allowing for consistent usage patterns across standalone, sentinel, and cluster deployments.
Usage:
Set<HostAndPort> clusterNodes = new HashSet<>();
clusterNodes.add(new HostAndPort("127.0.0.1", 7000));
RedisClusterClient client = RedisClusterClient.create(clusterNodes);
client.set("key", "value");
String value = client.get("key");
Migration: Users of JedisCluster are encouraged to migrate to this class for
improved API consistency, better resource management, and enhanced support for future Redis
features.
Thread-safety: This client is thread-safe and can be shared across multiple threads.
Configuration: Use the builder() method for advanced configuration, or the
create(HostAndPort) and create(Set) factory methods for simple use cases.
| Modifier and Type | Class and Description |
|---|---|
static class |
RedisClusterClient.Builder
Fluent builder for
RedisClusterClient (Redis Cluster). |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_ATTEMPTS
Default amount of attempts for executing a command
|
static int |
DEFAULT_TIMEOUT
Default timeout in milliseconds.
|
static java.lang.String |
INIT_NO_ERROR_PROPERTY |
commandObjects, executor, provider| Modifier and Type | Method and Description |
|---|---|
<T> T |
broadcastCommand(CommandObject<T> commandObject)
Broadcast a command to all primary nodes in the cluster.
|
static RedisClusterClient.Builder |
builder()
Create a new builder for configuring RedisClusterClient instances.
|
static RedisClusterClient |
create(HostAndPort node)
Creates a RedisClusterClient instance.
|
static RedisClusterClient |
create(java.util.Set<HostAndPort> nodes)
Creates a RedisClusterClient with multiple entry points.
|
static RedisClusterClient |
create(java.util.Set<HostAndPort> nodes,
java.lang.String user,
java.lang.String password)
Creates a RedisClusterClient with multiple entry points and authentication.
|
long |
del(byte[]... keys)
This override automatically splits the keys by hash slot and executes DEL on each shard,
aggregating the results (sum of deleted keys).
|
long |
del(java.lang.String... keys)
Remove the specified keys.
|
<T> T |
executeCommandToReplica(CommandObject<T> commandObject) |
long |
exists(byte[]... keys)
This override automatically splits the keys by hash slot and executes EXISTS on each shard,
aggregating the results (sum of existing keys).
|
long |
exists(java.lang.String... keys)
Exists Command
Test if the specified keys exist.
|
java.util.Map<java.lang.String,ConnectionPool> |
getClusterNodes()
Returns all nodes that were configured to connect to in key-value pairs (
Map). |
Connection |
getConnectionFromSlot(int slot)
Returns the connection for one of the 16,384 slots.
|
java.util.List<byte[]> |
mget(byte[]... keys)
Get the values of all the specified keys.
|
java.util.List<java.lang.String> |
mget(java.lang.String... keys)
MGet Command
Get the values of all the specified keys.
|
java.lang.String |
mset(byte[]... keysvalues)
This override automatically splits the key-value pairs by hash slot and executes MSET
on each shard.
|
java.lang.String |
mset(java.lang.String... keysvalues)
MSet Command
Set the respective keys to the respective values.
|
boolean |
msetex(MSetExParams params,
byte[]... keysvalues)
Multi-set with optional condition and expiration.
|
boolean |
msetex(MSetExParams params,
java.lang.String... keysvalues)
Multi-set with optional condition and expiration.
|
protected CommandObjects |
newCommandObjects(RedisProtocol protocol)
Factory hook for the
CommandObjects instance held by this client. |
ClusterPipeline |
pipelined()
Creates a new pipeline for executing commands in a Redis Cluster.
|
ClusterPipeline |
pipelined(java.util.concurrent.ExecutorService executorService)
Creates a new pipeline for executing commands in a Redis Cluster using the provided executor.
|
void |
refreshClusterTopology()
Forces an immediate refresh of the in-memory Redis Cluster topology
(node map, primary and replica slot assignments).
|
long |
spublish(byte[] channel,
byte[] message) |
long |
spublish(java.lang.String channel,
java.lang.String message) |
void |
ssubscribe(BinaryJedisShardedPubSub jedisPubSub,
byte[]... channels) |
void |
ssubscribe(JedisShardedPubSub jedisPubSub,
java.lang.String... channels) |
long |
touch(byte[]... keys)
This override automatically splits the keys by hash slot and executes TOUCH on each shard,
aggregating the results (sum of touched keys).
|
long |
touch(java.lang.String... keys)
Touch Command
Alters the last access time of a key(s).
|
AbstractTransaction |
transaction(boolean doMulti) |
long |
unlink(byte[]... keys)
This override automatically splits the keys by hash slot and executes UNLINK on each shard,
aggregating the results (sum of unlinked keys).
|
long |
unlink(java.lang.String... keys)
Similar to
SORT but can be used with multiple keys. |
append, append, arcount, arcount, ardel, ardel, ardel, ardel, ardelrange, ardelrange, ardelrange, ardelrange, arget, arget, argetrange, argetrange, argrep, argrep, argrepWithValues, argrepWithValues, arinfo, arinfo, arinfoFull, arinfoFull, arinsert, arinsert, arinsert, arinsert, arlastitems, arlastitems, arlastitems, arlastitems, arlen, arlen, armget, armget, armset, armset, arnext, arnext, aropAggregate, aropAggregate, aropBitwise, aropBitwise, aropCount, aropCount, aropCount, aropCount, arring, arring, arring, arring, arscan, arscan, arscan, arscan, arseek, arseek, arset, arset, arset, arset, bfAdd, bfCard, bfExists, bfInfo, bfInsert, bfInsert, bfLoadChunk, bfMAdd, bfMExists, bfReserve, bfReserve, bfScanDump, bitcount, bitcount, bitcount, bitcount, bitcount, bitcount, bitfield, bitfield, bitfieldReadonly, bitfieldReadonly, bitop, bitop, bitpos, bitpos, bitpos, bitpos, blmove, blmove, blmovem, blmovem, blmovem, blmovem, blmpop, blmpop, blmpop, blmpop, blpop, blpop, blpop, blpop, blpop, blpop, brpop, brpop, brpop, brpop, brpop, brpop, brpoplpush, brpoplpush, bzmpop, bzmpop, bzmpop, bzmpop, bzpopmax, bzpopmax, bzpopmin, bzpopmin, cfAdd, cfAddNx, cfCount, cfDel, cfExists, cfInfo, cfInsert, cfInsert, cfInsertNx, cfInsertNx, cfLoadChunk, cfMExists, cfReserve, cfReserve, cfScanDump, close, cmsIncrBy, cmsInfo, cmsInitByDim, cmsInitByProb, cmsMerge, cmsMerge, cmsQuery, configGet, configGet, configSet, configSet, copy, copy, dbSize, decr, decr, decrBy, decrBy, del, del, delex, delex, digestKey, digestKey, dump, dump, echo, eval, eval, eval, eval, eval, eval, eval, eval, evalReadonly, evalReadonly, evalsha, evalsha, evalsha, evalsha, evalsha, evalsha, evalsha, evalsha, evalshaReadonly, evalshaReadonly, executeCommand, executeCommand, exists, exists, expire, expire, expire, expire, expireAt, expireAt, expireAt, expireAt, expireTime, expireTime, fcall, fcall, fcallReadonly, fcallReadonly, flushAll, flushDB, ftAggregate, ftAggregateIteration, ftAggregateIterator, ftAliasAdd, ftAliasDel, ftAliasList, ftAliasUpdate, ftAlter, ftAlter, ftConfigGet, ftConfigGet, ftConfigSet, ftConfigSet, ftCreate, ftCreate, ftCursorDel, ftCursorRead, ftDictAdd, ftDictAddBySampleKey, ftDictDel, ftDictDelBySampleKey, ftDictDump, ftDictDumpBySampleKey, ftDropIndex, ftDropIndexDD, ftExplain, ftExplainCLI, ftHybrid, ftInfo, ftList, ftProfileAggregate, ftProfileSearch, ftProfileSearch, ftSearch, ftSearch, ftSearch, ftSearch, ftSearchIteration, ftSearchIteration, ftSpellCheck, ftSpellCheck, ftSugAdd, ftSugAddIncr, ftSugDel, ftSugGet, ftSugGet, ftSugGetWithScores, ftSugGetWithScores, ftSugLen, ftSynDump, ftSynUpdate, ftTagVals, functionDelete, functionDelete, functionDump, functionFlush, functionFlush, functionKill, functionList, functionList, functionList, functionListBinary, functionListWithCode, functionListWithCode, functionListWithCode, functionListWithCodeBinary, functionLoad, functionLoad, functionLoadReplace, functionLoadReplace, functionRestore, functionRestore, functionStats, functionStatsBinary, geoadd, geoadd, geoadd, geoadd, geoadd, geoadd, geodist, geodist, geodist, geodist, geohash, geohash, geopos, geopos, georadius, georadius, georadius, georadius, georadiusByMember, georadiusByMember, georadiusByMember, georadiusByMember, georadiusByMemberReadonly, georadiusByMemberReadonly, georadiusByMemberReadonly, georadiusByMemberReadonly, georadiusByMemberStore, georadiusByMemberStore, georadiusReadonly, georadiusReadonly, georadiusReadonly, georadiusReadonly, georadiusStore, georadiusStore, geosearch, geosearch, geosearch, geosearch, geosearch, geosearch, geosearch, geosearch, geosearch, geosearch, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStore, geosearchStoreStoreDist, geosearchStoreStoreDist, get, get, getbit, getbit, getCache, getDel, getDel, getEx, getEx, getrange, getrange, getSet, getSet, hdel, hdel, hexists, hexists, hexpire, hexpire, hexpire, hexpire, hexpireAt, hexpireAt, hexpireAt, hexpireAt, hexpireTime, hexpireTime, hget, hget, hgetAll, hgetAll, hgetdel, hgetdel, hgetex, hgetex, himportSet, himportSet, hincrBy, hincrBy, hincrByFloat, hincrByFloat, hkeys, hkeys, hlen, hlen, hmget, hmget, hmset, hmset, hotkeysGet, hotkeysReset, hotkeysStart, hotkeysStop, hpersist, hpersist, hpexpire, hpexpire, hpexpire, hpexpire, hpexpireAt, hpexpireAt, hpexpireAt, hpexpireAt, hpexpireTime, hpexpireTime, hpttl, hpttl, hrandfield, hrandfield, hrandfield, hrandfield, hrandfieldWithValues, hrandfieldWithValues, hscan, hscan, hscanNoValues, hscanNoValues, hset, hset, hset, hset, hsetex, hsetex, hsetex, hsetex, hsetnx, hsetnx, hsetObject, hsetObject, hstrlen, hstrlen, httl, httl, hvals, hvals, incr, incr, incrBy, incrBy, incrByFloat, incrByFloat, increx, increx, increx, increx, increx, increx, info, info, jsonArrAppend, jsonArrAppend, jsonArrAppendWithEscape, jsonArrIndex, jsonArrIndex, jsonArrIndexWithEscape, jsonArrInsert, jsonArrInsert, jsonArrInsertWithEscape, jsonArrLen, jsonArrLen, jsonArrLen, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrPop, jsonArrTrim, jsonArrTrim, jsonClear, jsonClear, jsonClear, jsonDebugMemory, jsonDebugMemory, jsonDebugMemory, jsonDel, jsonDel, jsonDel, jsonGet, jsonGet, jsonGet, jsonGet, jsonGet, jsonGetAsPlainString, jsonMerge, jsonMerge, jsonMGet, jsonMGet, jsonNumIncrBy, jsonNumIncrBy, jsonObjKeys, jsonObjKeys, jsonObjKeys, jsonObjLen, jsonObjLen, jsonObjLen, jsonSet, jsonSet, jsonSet, jsonSet, jsonSetWithEscape, jsonSetWithEscape, jsonSetWithPlainString, jsonStrAppend, jsonStrAppend, jsonStrAppend, jsonStrLen, jsonStrLen, jsonStrLen, jsonToggle, jsonToggle, jsonType, jsonType, jsonType, keys, keys, lcs, lcs, lindex, lindex, linsert, linsert, llen, llen, lmove, lmove, lmovem, lmovem, lmovem, lmovem, lmpop, lmpop, lmpop, lmpop, lpop, lpop, lpop, lpop, lpos, lpos, lpos, lpos, lpos, lpos, lpush, lpush, lpushx, lpushx, lrange, lrange, lrem, lrem, lset, lset, ltrim, ltrim, memoryUsage, memoryUsage, memoryUsage, memoryUsage, migrate, migrate, migrate, migrate, msetnx, msetnx, multi, objectEncoding, objectEncoding, objectFreq, objectFreq, objectIdletime, objectIdletime, objectRefcount, objectRefcount, persist, persist, pexpire, pexpire, pexpire, pexpire, pexpireAt, pexpireAt, pexpireAt, pexpireAt, pexpireTime, pexpireTime, pfadd, pfadd, pfcount, pfcount, pfcount, pfcount, pfmerge, pfmerge, ping, psetex, psetex, psubscribe, psubscribe, pttl, pttl, publish, publish, randomBinaryKey, randomKey, rename, rename, renamenx, renamenx, restore, restore, restore, restore, rpop, rpop, rpop, rpop, rpoplpush, rpoplpush, rpush, rpush, rpushx, rpushx, sadd, sadd, scan, scan, scan, scan, scan, scan, scanIteration, scanIteration, scard, scard, scriptExists, scriptExists, scriptExists, scriptExists, scriptExists, scriptFlush, scriptFlush, scriptFlush, scriptFlush, scriptFlush, scriptKill, scriptKill, scriptKill, scriptLoad, scriptLoad, scriptLoad, sdiff, sdiff, sdiffcard, sdiffcard, sdiffcard, sdiffcard, sdiffcard, sdiffcard, sdiffcard, sdiffstore, sdiffstore, sendBlockingCommand, sendBlockingCommand, sendBlockingCommand, sendBlockingCommand, sendCommand, sendCommand, sendCommand, sendCommand, sendCommand, set, set, set, set, setbit, setbit, setDefaultSearchDialect, setex, setex, setGet, setGet, setGet, setGet, setJsonObjectMapper, setKeyArgumentPreProcessor, setnx, setnx, setrange, setrange, sinter, sinter, sintercard, sintercard, sintercard, sintercard, sinterstore, sinterstore, sismember, sismember, slowlogReset, smembers, smembers, smismember, smismember, smove, smove, sort, sort, sort, sort, sort, sort, sort, sort, sortReadonly, sortReadonly, spop, spop, spop, spop, srandmember, srandmember, srandmember, srandmember, srem, srem, sscan, sscan, strlen, strlen, subscribe, subscribe, substr, substr, sunion, sunion, sunioncard, sunioncard, sunioncard, sunioncard, sunioncard, sunioncard, sunioncard, sunionstore, sunionstore, tdigestAdd, tdigestByRank, tdigestByRevRank, tdigestCDF, tdigestCreate, tdigestCreate, tdigestInfo, tdigestMax, tdigestMerge, tdigestMerge, tdigestMin, tdigestQuantile, tdigestRank, tdigestReset, tdigestRevRank, tdigestTrimmedMean, topkAdd, topkIncrBy, topkInfo, topkList, topkListWithCount, topkQuery, topkReserve, topkReserve, touch, touch, tsAdd, tsAdd, tsAdd, tsAdd, tsAlter, tsCreate, tsCreate, tsCreateRule, tsCreateRule, tsDecrBy, tsDecrBy, tsDecrBy, tsDel, tsDeleteRule, tsGet, tsGet, tsIncrBy, tsIncrBy, tsIncrBy, tsInfo, tsInfoDebug, tsMAdd, tsMGet, tsMRange, tsMRange, tsMRevRange, tsMRevRange, tsNRange, tsNRange, tsNRevRange, tsNRevRange, tsQueryIndex, tsQueryLabels, tsQueryLabelValues, tsRange, tsRange, tsRead, tsRead, tsRevRange, tsRevRange, ttl, ttl, type, type, unlink, unlink, vadd, vadd, vadd, vadd, vadd, vadd, vaddFP32, vaddFP32, vaddFP32, vaddFP32, vaddFP32, vaddFP32, vcard, vcard, vdim, vdim, vemb, vemb, vembRaw, vembRaw, vgetattr, vgetattr, vinfo, vismember, vismember, vlinks, vlinks, vlinksWithScores, vlinksWithScores, vrandmember, vrandmember, vrandmember, vrandmember, vrem, vrem, vsetattr, vsetattr, vsim, vsim, vsim, vsim, vsimByElement, vsimByElement, vsimByElement, vsimByElement, vsimByElementWithScores, vsimByElementWithScores, vsimByElementWithScoresAndAttribs, vsimByElementWithScoresAndAttribs, vsimWithScores, vsimWithScores, vsimWithScoresAndAttribs, vsimWithScoresAndAttribs, waitAOF, waitAOF, waitReplicas, waitReplicas, xack, xack, xackdel, xackdel, xackdel, xackdel, xadd, xadd, xadd, xautoclaim, xautoclaim, xautoclaimJustId, xautoclaimJustId, xcfgset, xcfgset, xclaim, xclaim, xclaimJustId, xclaimJustId, xdel, xdel, xdelex, xdelex, xdelex, xdelex, xgroupCreate, xgroupCreate, xgroupCreateConsumer, xgroupCreateConsumer, xgroupDelConsumer, xgroupDelConsumer, xgroupDestroy, xgroupDestroy, xgroupSetID, xgroupSetID, xinfoConsumers, xinfoConsumers, xinfoConsumers2, xinfoGroups, xinfoGroups, xinfoStream, xinfoStream, xinfoStreamFull, xinfoStreamFull, xinfoStreamFull, xinfoStreamFull, xlen, xlen, xnack, xnack, xpending, xpending, xpending, xpending, xrange, xrange, xrange, xrange, xrange, xrange, xread, xread, xreadAsMap, xreadBinary, xreadBinaryAsMap, xreadGroup, xreadGroup, xreadGroupAsMap, xreadGroupBinary, xreadGroupBinaryAsMap, xrevrange, xrevrange, xrevrange, xrevrange, xrevrange, xrevrange, xtrim, xtrim, xtrim, xtrim, zadd, zadd, zadd, zadd, zadd, zadd, zadd, zadd, zaddIncr, zaddIncr, zcard, zcard, zcount, zcount, zcount, zcount, zdiff, zdiff, zdiffstore, zdiffStore, zdiffstore, zdiffStore, zdiffWithScores, zdiffWithScores, zincrby, zincrby, zincrby, zincrby, zinter, zinter, zintercard, zintercard, zintercard, zintercard, zinterstore, zinterstore, zinterstore, zinterstore, zinterWithScores, zinterWithScores, zlexcount, zlexcount, zmpop, zmpop, zmpop, zmpop, zmscore, zmscore, zpopmax, zpopmax, zpopmax, zpopmax, zpopmin, zpopmin, zpopmin, zpopmin, zrandmember, zrandmember, zrandmember, zrandmember, zrandmemberWithScores, zrandmemberWithScores, zrange, zrange, zrange, zrange, zrangeByLex, zrangeByLex, zrangeByLex, zrangeByLex, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScore, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangeByScoreWithScores, zrangestore, zrangestore, zrangeWithScores, zrangeWithScores, zrangeWithScores, zrangeWithScores, zrank, zrank, zrankWithScore, zrankWithScore, zrem, zrem, zremrangeByLex, zremrangeByLex, zremrangeByRank, zremrangeByRank, zremrangeByScore, zremrangeByScore, zremrangeByScore, zremrangeByScore, zrevrange, zrevrange, zrevrangeByLex, zrevrangeByLex, zrevrangeByLex, zrevrangeByLex, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScore, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeByScoreWithScores, zrevrangeWithScores, zrevrangeWithScores, zrevrank, zrevrank, zrevrankWithScore, zrevrankWithScore, zscan, zscan, zscore, zscore, zunion, zunion, zunionstore, zunionstore, zunionstore, zunionstore, zunionWithScores, zunionWithScoresclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithscan, hscanNoValuessscanzscanxaddhscan, hscanNoValuessscanzscanxaddftAlter, ftAlter, ftCreate, ftCreate, ftCreate, ftSearchjsonMGet, jsonSetLegacy, jsonSetLegacyjsonMGet, jsonSet, jsonSet, jsonSetWithEscape, jsonSetWithEscapecmsIncrBytopkIncrBypublic static final java.lang.String INIT_NO_ERROR_PROPERTY
public static final int DEFAULT_TIMEOUT
public static final int DEFAULT_MAX_ATTEMPTS
protected CommandObjects newCommandObjects(RedisProtocol protocol)
UnifiedJedisCommandObjects instance held by this client. Subclasses (e.g.
JedisCluster) override to return their specialized subtype. Called from the
UnifiedJedis constructor — must not depend on subclass instance state.newCommandObjects in class UnifiedJedispublic static RedisClusterClient create(HostAndPort node)
Here, the default timeout of 2000 ms is being used with 5 maximum attempts.
This is a convenience factory method that uses the builder pattern internally.
node - Node to first connect to.RedisClusterClient instancepublic static RedisClusterClient create(java.util.Set<HostAndPort> nodes)
Here, the default timeout of 2000 ms is being used with 5 maximum attempts.
This is a convenience factory method that uses the builder pattern internally.
nodes - Nodes to connect to.RedisClusterClient instancepublic static RedisClusterClient create(java.util.Set<HostAndPort> nodes, java.lang.String user, java.lang.String password)
Here, the default timeout of 2000 ms is being used with 5 maximum attempts.
This is a convenience factory method that uses the builder pattern internally.
nodes - Nodes to connect to.user - Username for authentication.password - Password for authentication.RedisClusterClient instancepublic static RedisClusterClient.Builder builder()
RedisClusterClient.Builder instancepublic java.util.Map<java.lang.String,ConnectionPool> getClusterNodes()
Map).public Connection getConnectionFromSlot(int slot)
slot - the slot to retrieve the connection for.close() of this connection must be called
after use.public void refreshClusterTopology()
Useful before getConnectionFromSlot(int) when stale topology is
detected outside the command retry path. Best-effort; a no-op if a refresh
is already in progress.
public long spublish(java.lang.String channel,
java.lang.String message)
public long spublish(byte[] channel,
byte[] message)
public void ssubscribe(JedisShardedPubSub jedisPubSub, java.lang.String... channels)
public void ssubscribe(BinaryJedisShardedPubSub jedisPubSub, byte[]... channels)
public ClusterPipeline pipelined()
Pipelining allows batching multiple commands for more efficient execution by reducing network round-trips. In a cluster environment, commands are routed to the appropriate nodes based on key hash slots.
If the pipeline spans multiple nodes, a dedicated ExecutorService is
created internally to execute requests in parallel and shutdown when the pipeline
is synced.
pipelined in class UnifiedJedisClusterPipeline instancepipelined(ExecutorService)public ClusterPipeline pipelined(java.util.concurrent.ExecutorService executorService)
Pipelining allows batching multiple commands for more efficient execution by reducing network round-trips. In a cluster environment, commands are routed to the appropriate nodes based on key hash slots.
If the pipeline spans multiple nodes, the provided ExecutorService is
used to execute requests in parallel. The caller is responsible for managing
the lifecycle of this executor (creation, shutdown, etc.).
If null is provided, a dedicated executor is created and managed
internally, similar to pipelined().
executorService - the executor to use for multi-node execution, or nullClusterPipeline instancepublic AbstractTransaction transaction(boolean doMulti)
transaction in class UnifiedJedisdoMulti - paramjava.lang.UnsupportedOperationExceptionpublic final <T> T executeCommandToReplica(CommandObject<T> commandObject)
public final <T> T broadcastCommand(CommandObject<T> commandObject)
This method is useful for administrative commands that need to be executed on all primary nodes,
such as PING, CONFIG SET, FLUSHALL, etc.
T - the return type of the commandcommandObject - the command to broadcastjava.lang.UnsupportedOperationException - if the executor is not a ClusterCommandExecutorpublic long del(java.lang.String... keys)
Time complexity: O(N)
This override automatically splits the keys by hash slot and executes DEL on each shard, aggregating the results (sum of deleted keys).
del in interface KeyCommandsdel in class UnifiedJedispublic long del(byte[]... keys)
This override automatically splits the keys by hash slot and executes DEL on each shard, aggregating the results (sum of deleted keys).
del in interface KeyBinaryCommandsdel in class UnifiedJedispublic long exists(java.lang.String... keys)
Time complexity: O(N)
This override automatically splits the keys by hash slot and executes EXISTS on each shard, aggregating the results (sum of existing keys).
exists in interface KeyCommandsexists in class UnifiedJediskeys.public long exists(byte[]... keys)
This override automatically splits the keys by hash slot and executes EXISTS on each shard, aggregating the results (sum of existing keys).
exists in interface KeyBinaryCommandsexists in class UnifiedJedispublic java.util.List<java.lang.String> mget(java.lang.String... keys)
At least one key must be supplied; otherwise the server returns an error.
Time complexity: O(1) for every key
This override automatically splits the keys by hash slot and executes MGET on each shard, concatenating the results.
Order Guarantee: The returned values are in the same order as the input keys.
Each values.get(i) corresponds to keys[i].
Performance Tip: For better performance, pre-sort keys by hash slot before calling this method. This minimizes the number of separate Redis commands by allowing consecutive keys with the same slot to be batched together. Example:
// Sort keys by hash slot for optimal batching
String[] sortedKeys = Arrays.stream(keys)
.sorted(Comparator.comparingInt(JedisClusterCRC16::getSlot))
.toArray(String[]::new);
List<String> values = client.mget(sortedKeys);
mget in interface StringCommandsmget in class UnifiedJediskeys - the keys to getkeys;
entries are null for keys that do not exist or do not hold a string valuepublic java.util.List<byte[]> mget(byte[]... keys)
At least one key must be supplied; otherwise the server returns an error.
This override automatically splits the keys by hash slot and executes MGET on each shard, concatenating the results.
Order Guarantee: The returned values are in the same order as the input keys.
Each values.get(i) corresponds to keys[i].
Performance Tip: For better performance, pre-sort keys by hash slot before calling this method. This minimizes the number of separate Redis commands by allowing consecutive keys with the same slot to be batched together. Example:
// Sort keys by hash slot for optimal batching
byte[][] sortedKeys = Arrays.stream(keys)
.sorted(Comparator.comparingInt(JedisClusterCRC16::getSlot))
.toArray(byte[][]::new);
List<byte[]> values = client.mget(sortedKeys);
mget in interface StringBinaryCommandsmget in class UnifiedJediskeys - the keys to getkeys;
entries are null for keys that do not exist or do not hold a string valueStringCommands.mget(String...)public java.lang.String mset(java.lang.String... keysvalues)
MSETNX will not perform any operation at all even
if just a single key already exists.
Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.
Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another connection talking to Redis can either see the changes to both A and B at once, or no modification at all.
This override automatically splits the key-value pairs by hash slot and executes MSET on each shard.
mset in interface StringCommandsmset in class UnifiedJediskeysvalues - pairs of keys and their values
e.g mset("foo", "foovalue", "bar", "barvalue")public java.lang.String mset(byte[]... keysvalues)
This override automatically splits the key-value pairs by hash slot and executes MSET on each shard.
mset in interface StringBinaryCommandsmset in class UnifiedJedispublic long touch(java.lang.String... keys)
Time complexity: O(N) where N is the number of keys that will be touched.
This override automatically splits the keys by hash slot and executes TOUCH on each shard, aggregating the results (sum of touched keys).
touch in interface KeyCommandstouch in class UnifiedJedispublic long touch(byte[]... keys)
This override automatically splits the keys by hash slot and executes TOUCH on each shard, aggregating the results (sum of touched keys).
touch in interface KeyBinaryCommandstouch in class UnifiedJedispublic long unlink(java.lang.String... keys)
SORT but can be used with multiple keys.
This override automatically splits the keys by hash slot and executes UNLINK on each shard, aggregating the results (sum of unlinked keys).
unlink in interface KeyCommandsunlink in class UnifiedJedisKeyCommands.unlink(String)public long unlink(byte[]... keys)
This override automatically splits the keys by hash slot and executes UNLINK on each shard, aggregating the results (sum of unlinked keys).
unlink in interface KeyBinaryCommandsunlink in class UnifiedJedispublic boolean msetex(MSetExParams params, java.lang.String... keysvalues)
Sets the respective keys to the respective values, similar to MSET,
but allows conditional set (NX|XX) and expiration options via MSetExParams.
If the condition is not met for any key, no key is set.
Both MSET and MSETEX are atomic operations. This means that if multiple keys are provided, another client will either see the changes for all keys at once, or no changes at all.
Options (in MSetExParams): NX or XX, and expiration: EX seconds | PX milliseconds |
EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL.
Time complexity: O(N) where N is the number of keys to set.
This override automatically splits the key-value pairs by hash slot and executes MSETEX on each shard with the provided parameters.
msetex in interface StringCommandsmsetex in class UnifiedJedisparams - condition and expiration parameterskeysvalues - pairs of keys and their values, e.g. msetex(params, "foo", "foovalue", "bar", "barvalue")true if all the keys were set, false if none were set (condition not satisfied)StringCommands.mset(String...),
StringCommands.msetnx(String...)public boolean msetex(MSetExParams params, byte[]... keysvalues)
Sets the respective keys to the respective values, similar to MSET,
but allows conditional set (NX|XX) and expiration options via MSetExParams.
If the condition is not met for any key, no key is set.
Both MSET and MSETEX are atomic operations. This means that if multiple keys are provided, another client will either see the changes for all keys at once, or no changes at all.
Options (in MSetExParams): NX or XX, and expiration: EX seconds | PX milliseconds |
EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL.
Time complexity: O(N) where N is the number of keys to set.
This override automatically splits the key-value pairs by hash slot and executes MSETEX on each shard with the provided parameters.
msetex in interface StringBinaryCommandsmsetex in class UnifiedJedisparams - condition and expiration parameterskeysvalues - pairs of keys and their values, e.g. msetex(params, "foo".getBytes(), "foovalue".getBytes(), "bar".getBytes(), "barvalue".getBytes())true if all the keys were set, false if none were set (condition not satisfied)#mset(byte[]...),
#msetnx(byte[]...)Copyright © 2026. All rights reserved.