@Override public void bgReWriteAof() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::bgrewriteaof); }
@Override public void shutdown() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::shutdown); }
@Override public void resetConfigStats() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::configResetStat); }
private <T> NodeResult<T> executeCommandOnSingleNode(JedisClusterCommandCallback<T> cmd, RedisClusterNode node) { return connection.getClusterCommandExecutor().executeCommandOnSingleNode(cmd, node); }
@Override public void bgSave() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::bgsave); }
@Override public void flushAll() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::flushAll); }
@Override public void setConfig(String param, String value) { Assert.notNull(param, "Parameter must not be null!"); Assert.notNull(value, "Value must not be null!"); connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) client -> client.configSet(param, value)); }
@Override public void killClient(String host, int port) { Assert.hasText(host, "Host for 'CLIENT KILL' must not be 'null' or 'empty'."); String hostAndPort = String.format("%s:%s", host, port); connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) client -> client.clientKill(hostAndPort)); }
@Override public Set<byte[]> keys(byte[] pattern) { Assert.notNull(pattern, "Pattern must not be null!"); Collection<Set<byte[]>> keysPerNode = connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<Set<byte[]>>) client -> client.keys(pattern)) .resultsAsList(); Set<byte[]> keys = new HashSet<>(); for (Set<byte[]> keySet : keysPerNode) { keys.addAll(keySet); } return keys; }
@Override public List<RedisClientInfo> getClientList() { Collection<String> map = connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback<String>) Jedis::clientList).resultsAsList(); ArrayList<RedisClientInfo> result = new ArrayList<>(); for (String infos : map) { result.addAll(JedisConverters.toListOfRedisClientInformation(infos)); } return result; }
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 @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(); }
@Nullable @Override public ValueEncoding encodingOf(byte[] key) { Assert.notNull(key, "Key must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key), connection.clusterGetNodeForKey(key)) .mapValue(JedisConverters::toEncoding); }
@Override public Long time() { return convertListOfStringToTime(connection.getClusterCommandExecutor() .executeCommandOnArbitraryNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time).getValue()); }
@Override public Long time(RedisClusterNode node) { return convertListOfStringToTime(connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, 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 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 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 Boolean pSetEx(byte[] key, long milliseconds, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); return Converters.stringToBoolean(connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<String>) client -> client.psetex(key, milliseconds, value), connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .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(); }