@Override public void clusterAddSlots(RedisClusterNode node, SlotRange range) { Assert.notNull(range, "Range must not be null."); clusterAddSlots(node, range.getSlotsArray()); }
@Override public void clusterDeleteSlotsInRange(RedisClusterNode node, SlotRange range) { Assert.notNull(range, "Range must not be null."); clusterDeleteSlots(node, range.getSlotsArray()); }
@Nullable @Override public Long refcount(byte[] key) { Assert.notNull(key, "Key must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key), connection.clusterGetNodeForKey(key)) .getValue(); }
@Override public RedisClusterNode clusterGetNodeForKey(byte[] key) { return clusterGetNodeForSlot(clusterGetSlotForKey(key)); }
@Override public List<byte[]> mGet(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return connection.getCluster().mget(keys); } return connection.getClusterCommandExecutor() .executeMultiKeyCommand((JedisMultiKeyClusterCommandCallback<byte[]>) BinaryJedis::get, Arrays.asList(keys)) .resultsAsListSortBy(keys); }
@Override public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolean replace) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(serializedValue, "Serialized value must not be null!"); if (ttlInMillis > Integer.MAX_VALUE) { throw new UnsupportedOperationException("Jedis does not support ttlInMillis exceeding Integer.MAX_VALUE."); } connection.getClusterCommandExecutor().executeCommandOnSingleNode((JedisClusterCommandCallback<String>) client -> { if (!replace) { return client.restore(key, Long.valueOf(ttlInMillis).intValue(), serializedValue); } return JedisConverters.toString(this.connection.execute("RESTORE", key, Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes ("REPLACE")))); }, connection.clusterGetNodeForKey(key)); }
@Override public Long zInterStore(byte[] destKey, byte[]... sets) { Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(sets, "Source sets must not be null!"); Assert.noNullElements(sets, "Source sets must not contain null elements!"); byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets); if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) { try { return connection.getCluster().zinterstore(destKey, sets); } catch (Exception ex) { throw convertJedisAccessException(ex); } } throw new InvalidDataAccessApiUsageException("ZINTERSTORE can only be executed when all keys map to the same slot"); }
@Override public Long zUnionStore(byte[] destKey, byte[]... sets) { Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(sets, "Source sets must not be null!"); Assert.noNullElements(sets, "Source sets must not contain null elements!"); byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets); if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) { try { return connection.getCluster().zunionstore(destKey, sets); } catch (Exception ex) { throw convertJedisAccessException(ex); } } throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot"); }
@Override public List<Long> bitField(byte[] key, BitFieldSubCommands subCommands) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(subCommands, "Command must not be null!"); byte[][] args = JedisConverters.toBitfieldCommandArguments(subCommands); try { return connection.execute("BITFIELD", key, Arrays.asList(args), Connection::getIntegerMultiBulkReply); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<byte[]> zRangeByScore(byte[] key, String min, String max) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().zrangeByScore(key, JedisConverters.toBytes(min), JedisConverters.toBytes(max)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toTupleSet(connection.getCluster().zrangeByScoreWithScores(key, min, max)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long zRemRangeByScore(byte[] key, double min, double max) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().zremrangeByScore(key, min, max); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<byte[]> zRange(byte[] key, long start, long end) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().zrange(key, start, end); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toTupleSet(connection.getCluster().zrangeWithScores(key, start, end)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long zRemRange(byte[] key, long start, long end) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().zremrangeByRank(key, start, end); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toTupleSet(connection.getCluster().zrevrangeByScoreWithScores(key, max, min)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toTupleSet(connection.getCluster().zrevrangeWithScores(key, start, end)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean zAdd(byte[] key, double score, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().zadd(key, score, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(tuples, "Tuples must not be null!"); try { return connection.getCluster().zadd(key, JedisConverters.toTupleMap(tuples)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }