Interface ClusterManagementClusterCommands

  • All Known Implementing Classes:
    GlideClusterClient

    public interface ClusterManagementClusterCommands
    Supports commands for cluster management and information retrieval for cluster clients.

    These commands provide comprehensive control over Valkey cluster operations, enabling applications to inspect cluster state, view topology information, and retrieve node details.

    See Also:
    Cluster Commands
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.String> clusterAddSlots​(long[] slots)
      Assigns hash slots to the current node.
      The command will be routed to the node executing the command.
      java.util.concurrent.CompletableFuture<java.lang.String> clusterAddSlotsRange​(long[][] slotRanges)
      Assigns hash slot ranges to the current node.
      The command will be routed to the node executing the command.
      java.util.concurrent.CompletableFuture<java.lang.Long> clusterCountKeysInSlot​(long slot)
      Returns the number of keys in the specified hash slot.
      The command will be routed to the node responsible for the specified slot.
      java.util.concurrent.CompletableFuture<java.lang.String> clusterDelSlots​(long[] slots)
      Removes hash slots from the current node.
      The command will be routed to the node executing the command.
      java.util.concurrent.CompletableFuture<java.lang.String> clusterDelSlotsRange​(long[][] slotRanges)
      Removes hash slot ranges from the current node.
      The command will be routed to the node executing the command.
      java.util.concurrent.CompletableFuture<java.lang.String[]> clusterGetKeysInSlot​(long slot, long count)
      Returns an array of keys in the specified hash slot.
      The command will be routed to the node responsible for the specified slot.
      java.util.concurrent.CompletableFuture<GlideString[]> clusterGetKeysInSlotBinary​(long slot, long count)
      Returns an array of binary keys in the specified hash slot.
      The command will be routed to the node responsible for the specified slot.
      java.util.concurrent.CompletableFuture<java.lang.String> clusterInfo()
      Gets information and statistics about the cluster state.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterInfo​(RequestRoutingConfiguration.Route route)
      Gets information and statistics about the cluster state.
      java.util.concurrent.CompletableFuture<java.lang.Long> clusterKeySlot​(GlideString key)
      Returns the hash slot number for the given binary key.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<java.lang.Long> clusterKeySlot​(java.lang.String key)
      Returns the hash slot number for the given key.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<java.lang.Object[]> clusterLinks()
      Returns information about the TCP links to and from each node in the cluster.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object[]>> clusterLinks​(RequestRoutingConfiguration.Route route)
      Returns information about the TCP links to and from each node in the cluster.
      java.util.concurrent.CompletableFuture<java.lang.String> clusterMyId()
      Returns the unique identifier (ID) of the current node.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterMyId​(RequestRoutingConfiguration.Route route)
      Returns the unique identifier (ID) of the node(s).
      java.util.concurrent.CompletableFuture<java.lang.String> clusterMyShardId()
      Returns the shard ID of the current node.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterMyShardId​(RequestRoutingConfiguration.Route route)
      Returns the shard ID of the node(s).
      java.util.concurrent.CompletableFuture<java.lang.String> clusterNodes()
      Gets a list of all nodes in the cluster and their attributes.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterNodes​(RequestRoutingConfiguration.Route route)
      Gets a list of all nodes in the cluster and their attributes.
      java.util.concurrent.CompletableFuture<java.lang.Object[]> clusterShards()
      Returns details about the shards of the cluster.
      The command will be routed to a random node.
      java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object[]>> clusterShards​(RequestRoutingConfiguration.Route route)
      Returns details about the shards of the cluster.
    • Method Detail

      • clusterInfo

        java.util.concurrent.CompletableFuture<java.lang.String> clusterInfo()
        Gets information and statistics about the cluster state.
        The command will be routed to a random node.
        Returns:
        A String containing cluster state information with key-value pairs separated by newlines. Key fields include:
        • cluster_state - State of the cluster (ok or fail)
        • cluster_slots_assigned - Number of slots assigned
        • cluster_slots_ok - Number of slots in OK state
        • cluster_slots_pfail - Number of slots in PFAIL state
        • cluster_slots_fail - Number of slots in FAIL state
        • cluster_known_nodes - Total number of known nodes
        • cluster_size - Number of primary nodes serving at least one slot
        • cluster_current_epoch - Current cluster epoch
        • cluster_my_epoch - Config epoch of the current node
        • cluster_stats_messages_sent - Number of messages sent
        • cluster_stats_messages_received - Number of messages received
        See Also:
        valkey.io for details.
        Example:
        
         String info = clusterClient.clusterInfo().get();
         System.out.println(info);
         // Output:
         // cluster_state:ok
         // cluster_slots_assigned:16384
         // cluster_slots_ok:16384
         // cluster_slots_pfail:0
         // cluster_slots_fail:0
         // cluster_known_nodes:3
         // cluster_size:3
         // ...
         
      • clusterInfo

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterInfo​(RequestRoutingConfiguration.Route route)
        Gets information and statistics about the cluster state.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns a String containing cluster state information. When specifying a multi-node route, returns a Map<String, String> with each node address as the key and its cluster state information as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<String> infoResult = clusterClient.clusterInfo(ALL_PRIMARIES).get();
         // Command sent to all primary nodes, expecting MultiValue result
         for (Map.Entry<String, String> entry : infoResult.getMultiValue().entrySet()) {
             System.out.println("Node [" + entry.getKey() + "]:");
             System.out.println(entry.getValue());
         }
         
      • clusterNodes

        java.util.concurrent.CompletableFuture<java.lang.String> clusterNodes()
        Gets a list of all nodes in the cluster and their attributes.
        The command will be routed to a random node.
        Returns:
        A String containing information about all nodes in the cluster. Each line represents a node with space-separated fields:
        • node-id - 40-character hex string identifier
        • ip:port@cport - Node address (IPv4, IPv6, or hostname). The @cport is the cluster port used for node-to-node communication
        • flags - Comma-separated list (myself, master, slave, fail?, fail, handshake, noaddr, nofailover, noflags)
        • master-id - Node ID of the master (or "-" if this node is a master)
        • ping-sent - Milliseconds unix time of last ping sent (0 if no ping sent)
        • pong-recv - Milliseconds unix time of last pong received
        • config-epoch - Config epoch of this node
        • link-state - State of the node-to-node link (connected or disconnected)
        • slots - Hash slots served by this node (e.g., 0-5460 or individual slots like 1 2 3)
        See Also:
        valkey.io for details.
        Example:
        
         String nodes = clusterClient.clusterNodes().get();
         System.out.println(nodes);
         // Output (example):
         // 07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1:30004@31004 slave
         // e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca 0 1426238317239 4 connected
         // 67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1:30002@31002 master - 0
         // 1426238316232 2 connected 5461-10922
         // ...
         
      • clusterNodes

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterNodes​(RequestRoutingConfiguration.Route route)
        Gets a list of all nodes in the cluster and their attributes.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns a String containing node information. When specifying a multi-node route, returns a Map<String, String> with each node address as the key and its node listing as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<String> nodesResult = clusterClient.clusterNodes(RANDOM).get();
         // Command sent to a random node, expecting SingleValue result
         System.out.println(nodesResult.getSingleValue());
         
      • clusterShards

        java.util.concurrent.CompletableFuture<java.lang.Object[]> clusterShards()
        Returns details about the shards of the cluster.
        The command will be routed to a random node.
        Returns:
        An array of maps, where each map represents a shard and contains the following keys:
        • "slots" - An array of slot ranges (each range is a two-element array [start, end])
        • "nodes" - An array of node objects in this shard, each containing:
          • "id" - Node ID (40-character hex string)
          • "endpoint" - Node address (IP and port)
          • "ip" - Node IP address (IPv4 or IPv6)
          • "port" - Node port number
          • "role" - Node role ("master" or "replica")
          • "replication-offset" - Replication offset
          • "health" - Node health status ("online", "failed", "loading")
        See Also:
        valkey.io for details.
        Example:
        
         Object[] shards = clusterClient.clusterShards().get();
         for (Object shardObj : shards) {
             Map<String, Object> shard = (Map<String, Object>) shardObj;
             Object[] slots = (Object[]) shard.get("slots");
             System.out.println("Shard slots: ");
             for (Object slotRange : slots) {
                 Object[] range = (Object[]) slotRange;
                 System.out.println("  " + range[0] + "-" + range[1]);
             }
        
             Object[] nodes = (Object[]) shard.get("nodes");
             for (Object nodeObj : nodes) {
                 Map<String, Object> node = (Map<String, Object>) nodeObj;
                 System.out.println("  Node: " + node.get("id"));
                 System.out.println("    Endpoint: " + node.get("endpoint"));
                 System.out.println("    Role: " + node.get("role"));
             }
         }
         
      • clusterShards

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object[]>> clusterShards​(RequestRoutingConfiguration.Route route)
        Returns details about the shards of the cluster.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns an array of shard information maps. When specifying a multi-node route, returns a Map<String, Object[]> with each node address as the key and its shard details array as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<Object[]> shardsResult = clusterClient.clusterShards(ALL_NODES).get();
         // Command sent to all nodes, expecting MultiValue result
         for (Map.Entry<String, Object[]> entry : shardsResult.getMultiValue().entrySet()) {
             System.out.println("Node [" + entry.getKey() + "] shards: " + Arrays.toString(entry.getValue()));
         }
         
      • clusterLinks

        java.util.concurrent.CompletableFuture<java.lang.Object[]> clusterLinks()
        Returns information about the TCP links to and from each node in the cluster.
        The command will be routed to a random node.
        Returns:
        An array of maps, where each map represents a cluster link and contains the following keys:
        • "direction" - Link direction ("to" or "from")
        • "node" - Node ID (40-character hex string) at the other end of the link
        • "create-time" - Timestamp when the link was created (milliseconds)
        • "events" - Event flags for the link (e.g., "r" for readable, "w" for writable)
        • "send-buffer-allocated" - Allocated size of the send buffer
        • "send-buffer-used" - Size of the send buffer currently in use
        • "recv-buffer-allocated" - Allocated size of the receive buffer
        • "recv-buffer-used" - Size of the receive buffer currently in use
        See Also:
        valkey.io for details.
        Example:
        
         Object[] links = clusterClient.clusterLinks().get();
         for (Object linkObj : links) {
             Map<String, Object> link = (Map<String, Object>) linkObj;
             System.out.println("Link direction: " + link.get("direction"));
             System.out.println("  Node: " + link.get("node"));
             System.out.println("  Send buffer used: " + link.get("send-buffer-used"));
             System.out.println("  Recv buffer used: " + link.get("recv-buffer-used"));
         }
         
      • clusterLinks

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object[]>> clusterLinks​(RequestRoutingConfiguration.Route route)
        Returns information about the TCP links to and from each node in the cluster.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns an array of link information maps. When specifying a multi-node route, returns a Map<String, Object[]> with each node address as the key and its link details array as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<Object[]> linksResult = clusterClient.clusterLinks(ALL_PRIMARIES).get();
         // Command sent to all primary nodes, expecting MultiValue result
         for (Map.Entry<String, Object[]> entry : linksResult.getMultiValue().entrySet()) {
             System.out.println("Node [" + entry.getKey() + "] has " + entry.getValue().length + " links");
         }
         
      • clusterMyId

        java.util.concurrent.CompletableFuture<java.lang.String> clusterMyId()
        Returns the unique identifier (ID) of the current node.
        The command will be routed to a random node.
        Returns:
        A String containing the unique 40-character identifier of the node executing the command. This ID remains constant for the lifetime of the node and is used in various cluster commands to reference this specific node.
        See Also:
        valkey.io for details.
        Example:
        
         String nodeId = clusterClient.clusterMyId().get();
         System.out.println("Current node ID: " + nodeId);
         // Output: Current node ID: 07c37dfeb235213a872192d90877d0cd55635b91
         
      • clusterMyId

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterMyId​(RequestRoutingConfiguration.Route route)
        Returns the unique identifier (ID) of the node(s).
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns a String containing the node ID. When specifying a multi-node route, returns a Map<String, String> with each node address as the key and its node ID as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<String> idsResult = clusterClient.clusterMyId(ALL_NODES).get();
         // Command sent to all nodes, expecting MultiValue result
         for (Map.Entry<String, String> entry : idsResult.getMultiValue().entrySet()) {
             System.out.println("Node [" + entry.getKey() + "] ID: " + entry.getValue());
         }
         
      • clusterMyShardId

        java.util.concurrent.CompletableFuture<java.lang.String> clusterMyShardId()
        Returns the shard ID of the current node.
        The command will be routed to a random node.

        In Valkey, a shard is a set of nodes that replicate the same data (one primary and zero or more replicas). The shard ID is a unique identifier for this replication group and remains constant even during failovers when the primary role transfers to a replica.

        Returns:
        A String containing the unique shard identifier of the current node. All nodes in the same shard (primary and replicas) share the same shard ID.
        See Also:
        valkey.io for details.
        Example:
        
         String shardId = clusterClient.clusterMyShardId().get();
         System.out.println("Current shard ID: " + shardId);
         // Output: Current shard ID: 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e
         
      • clusterMyShardId

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.String>> clusterMyShardId​(RequestRoutingConfiguration.Route route)
        Returns the shard ID of the node(s).

        In Valkey, a shard is a set of nodes that replicate the same data (one primary and zero or more replicas). The shard ID is a unique identifier for this replication group and remains constant even during failovers when the primary role transfers to a replica.

        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        When specifying a single-node route, returns a String containing the shard ID. When specifying a multi-node route, returns a Map<String, String> with each node address as the key and its shard ID as the value.
        See Also:
        valkey.io for details.
        Example:
        
         ClusterValue<String> shardIdsResult = clusterClient.clusterMyShardId(ALL_PRIMARIES).get();
         // Command sent to all primary nodes, expecting MultiValue result
         for (Map.Entry<String, String> entry : shardIdsResult.getMultiValue().entrySet()) {
             System.out.println("Node [" + entry.getKey() + "] Shard ID: " + entry.getValue());
         }
         
      • clusterKeySlot

        java.util.concurrent.CompletableFuture<java.lang.Long> clusterKeySlot​(java.lang.String key)
        Returns the hash slot number for the given key.
        The command will be routed to a random node.

        The hash slot determines which node in a cluster is responsible for a given key. Valkey Cluster uses 16384 hash slots (0-16383). Keys are mapped to slots using CRC16 of the key modulo 16384.

        Parameters:
        key - The key to get the hash slot for.
        Returns:
        The hash slot number (0-16383) for the given key.
        See Also:
        valkey.io for details.
        Example:
        
         long slot = clusterClient.clusterKeySlot("mykey").get();
         System.out.println("Key 'mykey' belongs to slot: " + slot);
         // Output: Key 'mykey' belongs to slot: 14687
         
      • clusterKeySlot

        java.util.concurrent.CompletableFuture<java.lang.Long> clusterKeySlot​(GlideString key)
        Returns the hash slot number for the given binary key.
        The command will be routed to a random node.
        Parameters:
        key - The binary key to get the hash slot for.
        Returns:
        The hash slot number (0-16383) for the given key.
        See Also:
        valkey.io for details.
        Example:
        
         long slot = clusterClient.clusterKeySlot(gs("mykey")).get();
         System.out.println("Binary key belongs to slot: " + slot);
         
      • clusterCountKeysInSlot

        java.util.concurrent.CompletableFuture<java.lang.Long> clusterCountKeysInSlot​(long slot)
        Returns the number of keys in the specified hash slot.
        The command will be routed to the node responsible for the specified slot.
        Parameters:
        slot - The hash slot number (0-16383) to count keys in.
        Returns:
        The number of keys in the specified slot.
        See Also:
        valkey.io for details.
        Example:
        
         long keyCount = clusterClient.clusterCountKeysInSlot(12345).get();
         System.out.println("Number of keys in slot 12345: " + keyCount);
         // Output: Number of keys in slot 12345: 42
         
      • clusterGetKeysInSlot

        java.util.concurrent.CompletableFuture<java.lang.String[]> clusterGetKeysInSlot​(long slot,
                                                                                        long count)
        Returns an array of keys in the specified hash slot.
        The command will be routed to the node responsible for the specified slot.
        Parameters:
        slot - The hash slot number (0-16383) to retrieve keys from.
        count - The maximum number of keys to return. Must be positive.
        Returns:
        An array of up to count keys belonging to the specified slot. Returns an empty array if the slot is empty or does not exist.
        See Also:
        valkey.io for details.
        Example:
        
         String[] keys = clusterClient.clusterGetKeysInSlot(12345, 10).get();
         System.out.println("First 10 keys in slot 12345:");
         for (String key : keys) {
             System.out.println("  " + key);
         }
         
      • clusterGetKeysInSlotBinary

        java.util.concurrent.CompletableFuture<GlideString[]> clusterGetKeysInSlotBinary​(long slot,
                                                                                         long count)
        Returns an array of binary keys in the specified hash slot.
        The command will be routed to the node responsible for the specified slot.
        Parameters:
        slot - The hash slot number (0-16383) to retrieve keys from.
        count - The maximum number of keys to return. Must be positive.
        Returns:
        An array of up to count binary keys belonging to the specified slot. Returns an empty array if the slot is empty or does not exist.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString[] keys = clusterClient.clusterGetKeysInSlotBinary(12345, 10).get();
         System.out.println("First 10 binary keys in slot 12345: " + keys.length + " keys");
         
      • clusterAddSlots

        java.util.concurrent.CompletableFuture<java.lang.String> clusterAddSlots​(long[] slots)
        Assigns hash slots to the current node.
        The command will be routed to the node executing the command.
        Parameters:
        slots - An array of hash slot numbers (0-16383) to assign to the node. Slots must not already be assigned to any node.
        Returns:
        "OK" if the slots were successfully assigned.
        See Also:
        valkey.io for details.
        Example:
        
         String result = clusterClient.clusterAddSlots(new long[]{1, 2, 3, 4, 5}).get();
         System.out.println("Slots assigned: " + result); // Output: Slots assigned: OK
         
      • clusterAddSlotsRange

        java.util.concurrent.CompletableFuture<java.lang.String> clusterAddSlotsRange​(long[][] slotRanges)
        Assigns hash slot ranges to the current node.
        The command will be routed to the node executing the command.

        This command is more efficient than clusterAddSlots(long[]) when assigning multiple contiguous slot ranges, as it uses the CLUSTER ADDSLOTSRANGE command introduced in Valkey 7.0.

        Parameters:
        slotRanges - A 2D array where each sub-array contains two elements: [start_slot, end_slot] representing an inclusive range of slots to assign. All slots must be between 0-16383 and not already assigned.
        Returns:
        "OK" if the slot ranges were successfully assigned.
        See Also:
        valkey.io for details.
        Example:
        
         // Assign slots 0-100, 1000-2000, and 5000-5999
         long[][] ranges = {{0, 100}, {1000, 2000}, {5000, 5999}};
         String result = clusterClient.clusterAddSlotsRange(ranges).get();
         System.out.println("Slot ranges assigned: " + result); // Output: Slot ranges assigned: OK
         
      • clusterDelSlots

        java.util.concurrent.CompletableFuture<java.lang.String> clusterDelSlots​(long[] slots)
        Removes hash slots from the current node.
        The command will be routed to the node executing the command.

        Once a slot is removed, it becomes unassigned and can be assigned to another node or reassigned to the current node. This is typically used during cluster reconfiguration or before removing a node from the cluster.

        Parameters:
        slots - An array of hash slot numbers (0-16383) to remove from the node. Slots must currently be assigned to this node.
        Returns:
        "OK" if the slots were successfully removed.
        See Also:
        valkey.io for details.
        Example:
        
         String result = clusterClient.clusterDelSlots(new long[]{1, 2, 3, 4, 5}).get();
         System.out.println("Slots removed: " + result); // Output: Slots removed: OK
         
      • clusterDelSlotsRange

        java.util.concurrent.CompletableFuture<java.lang.String> clusterDelSlotsRange​(long[][] slotRanges)
        Removes hash slot ranges from the current node.
        The command will be routed to the node executing the command.

        This command is more efficient than clusterDelSlots(long[]) when removing multiple contiguous slot ranges, as it uses the CLUSTER DELSLOTSRANGE command introduced in Valkey 7.0.

        Parameters:
        slotRanges - A 2D array where each sub-array contains two elements: [start_slot, end_slot] representing an inclusive range of slots to remove. All slots must be between 0-16383 and currently assigned to this node.
        Returns:
        "OK" if the slot ranges were successfully removed.
        See Also:
        valkey.io for details.
        Example:
        
         // Remove slots 0-100, 1000-2000, and 5000-5999
         long[][] ranges = {{0, 100}, {1000, 2000}, {5000, 5999}};
         String result = clusterClient.clusterDelSlotsRange(ranges).get();
         System.out.println("Slot ranges removed: " + result); // Output: Slot ranges removed: OK