/** * Run {@link ClusterCommandCallback} on given {@link RedisClusterNode}. * * @param cmd must not be {@literal null}. * @param node must not be {@literal null}. * @throws IllegalArgumentException in case no resource can be acquired for given node. * @return */ public <S, T> NodeResult<T> executeCommandOnSingleNode(ClusterCommandCallback<S, T> cmd, RedisClusterNode node) { return executeCommandOnSingleNode(cmd, node, 0); }
@Override public String ping(RedisClusterNode node) { return clusterCommandExecutor .executeCommandOnSingleNode((JedisClusterCommandCallback<String>) BinaryJedis::ping, node).getValue(); }
@Override public void clusterDeleteSlots(RedisClusterNode node, int... slots) { clusterCommandExecutor.executeCommandOnSingleNode( (JedisClusterCommandCallback<String>) client -> client.clusterDelSlots(slots), node); }
@Override public void clusterAddSlots(RedisClusterNode node, int... slots) { clusterCommandExecutor.executeCommandOnSingleNode( (LettuceClusterCommandCallback<String>) client -> client.clusterAddSlots(slots), node); }
@Override public void clusterDeleteSlots(RedisClusterNode node, int... slots) { clusterCommandExecutor.executeCommandOnSingleNode( (LettuceClusterCommandCallback<String>) client -> client.clusterDelSlots(slots), node); }
@Override public String ping(RedisClusterNode node) { return clusterCommandExecutor .executeCommandOnSingleNode((LettuceClusterCommandCallback<String>) BaseRedisCommands::ping, node).getValue(); }
@Override public void clusterAddSlots(RedisClusterNode node, int... slots) { clusterCommandExecutor.executeCommandOnSingleNode( (JedisClusterCommandCallback<String>) client -> client.clusterAddSlots(slots), node); }
public byte[] randomKey(RedisClusterNode node) { Assert.notNull(node, "RedisClusterNode must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.randomBinaryKey(), node) .getValue(); }
@Nullable public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) { Assert.notNull(pattern, "Pattern must not be null!"); return LettuceConverters.toBytesSet(connection.getClusterCommandExecutor() .executeCommandOnSingleNode((LettuceClusterCommandCallback<List<byte[]>>) client -> client.keys(pattern), node) .getValue()); }
@Nullable <T> T execute(String command, byte[] key, Collection<byte[]> args, Function<Client, T> responseMapper) { Assert.notNull(command, "Command must not be null!"); Assert.notNull(key, "Key must not be null!"); Assert.notNull(args, "Args must not be null!"); byte[][] commandArgs = getCommandArguments(key, args); RedisClusterNode keyMaster = topologyProvider.getTopology().getKeyServingMasterNode(key); return clusterCommandExecutor.executeCommandOnSingleNode((JedisClusterCommandCallback<T>) client -> JedisClientUtils .execute(command, EMPTY_2D_BYTE_ARRAY, commandArgs, () -> client, responseMapper), keyMaster).getValue(); }
@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 Long clusterCountKeysInSlot(int slot) { RedisClusterNode node = clusterGetNodeForSlot(slot); return clusterCommandExecutor.executeCommandOnSingleNode( (JedisClusterCommandCallback<Long>) client -> client.clusterCountKeysInSlot(slot), node).getValue(); }
@Override public Properties getConfig(RedisClusterNode node, String pattern) { Assert.notNull(pattern, "Pattern must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<Properties>) client -> Converters.toProperties(client.configGet(pattern)), node) .getValue(); }
@Override public Long time(RedisClusterNode node) { return convertListOfStringToTime(connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, node).getValue()); }
@Override public List<byte[]> clusterGetKeysInSlot(int slot, Integer count) { RedisClusterNode node = clusterGetNodeForSlot(slot); clusterCommandExecutor .executeCommandOnSingleNode( (JedisClusterCommandCallback<List<byte[]>>) client -> JedisConverters.stringListToByteList() .convert(client.clusterGetKeysInSlot(slot, count != null ? count.intValue() : Integer.MAX_VALUE)), node); return null; }
@Override public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica) { RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master); clusterCommandExecutor.executeCommandOnSingleNode( (LettuceClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()), replica); }
@Override public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica) { RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master); clusterCommandExecutor.executeCommandOnSingleNode( (JedisClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()), replica); }
@Override public Long pTtl(byte[] key) { Assert.notNull(key, "Key must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.pttl(key), connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .getValue(); }
@Override public Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master) { Assert.notNull(master, "Master cannot be null!"); RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master); return JedisConverters.toSetOfRedisClusterNodes(clusterCommandExecutor .executeCommandOnSingleNode( (JedisClusterCommandCallback<List<String>>) client -> client.clusterSlaves(nodeToUse.getId()), master) .getValue()); }
@Override public Long pTtl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<Long>) client -> Converters.millisecondsToTimeUnit(client.pttl(key), timeUnit), connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .getValue(); }