Interface GenericClusterCommands

  • All Known Implementing Classes:
    GlideClusterClient

    public interface GenericClusterCommands
    Supports commands for the "Generic Commands" group for a cluster client.
    See Also:
    Generic Commands
    • Method Detail

      • customCommand

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand​(java.lang.String[] args)
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        The command will be routed automatically based on the passed command's default request policy.
        Parameters:
        args - Arguments for the custom command including the command name.
        Returns:
        The returned value for the custom command.
        See Also:
        Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
        Example:
        
         ClusterValue<Object> data = client.customCommand(new String[] {"ping"}).get();
         assert data.getSingleValue().equals("PONG");
         
      • customCommand

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand​(GlideString[] args)
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        The command will be routed automatically based on the passed command's default request policy.
        Parameters:
        args - Arguments for the custom command including the command name.
        Returns:
        The returned value for the custom command.
        See Also:
        Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
        Example:
        
         ClusterValue<Object> data = client.customCommand(new GlideString[] {gs("ping")}).get();
         assert data.getSingleValue().equals(gs("PONG"));
         
      • customCommand

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand​(java.lang.String[] args,
                                                                                             RequestRoutingConfiguration.Route route)
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        Parameters:
        args - Arguments for the custom command including the command name
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        The returning value depends on the executed command and route.
        See Also:
        Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
        Example:
        
         ClusterValue<Object> result = clusterClient.customCommand(new String[]{ "CONFIG", "GET", "maxmemory"}, ALL_NODES).get();
         Map<String, Object> payload = result.getMultiValue();
         assert payload.get("node1").equals("1GB");
         assert payload.get("node2").equals("100MB");
         
      • customCommand

        java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand​(GlideString[] args,
                                                                                             RequestRoutingConfiguration.Route route)
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        Parameters:
        args - Arguments for the custom command including the command name
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
        Returns:
        The returning value depends on the executed command and route.
        See Also:
        Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
        Example:
        
         ClusterValue<Object> result = clusterClient.customCommand(new GlideString[] { gs("CONFIG"), gs("GET"), gs("maxmemory") }, ALL_NODES).get();
         Map<String, Object> payload = result.getMultiValue();
         assert payload.get(gs("node1")).equals(gs("1GB"));
         assert payload.get(gs("node2")).equals(gs("100MB"));
         
      • randomKey

        java.util.concurrent.CompletableFuture<java.lang.String> randomKey​(RequestRoutingConfiguration.Route route)
        Returns a random key.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route, and will return the first successful result.
        Returns:
        A random key from the database.
        See Also:
        valkey.io for details.
        Example:
        
         String value = client.set("key", "value").get();
         String value_1 = client.set("key1", "value_1").get();
         String key = client.randomKey(RANDOM).get();
         System.out.println("The random key is: " + key);
         // The value of key is either "key" or "key1"
         
      • randomKeyBinary

        java.util.concurrent.CompletableFuture<GlideString> randomKeyBinary​(RequestRoutingConfiguration.Route route)
        Returns a random key.
        Parameters:
        route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route, and will return the first successful result.
        Returns:
        A random key from the database.
        See Also:
        valkey.io for details.
        Example:
        
         String value = client.set("key", "value").get();
         String value_1 = client.set("key1", "value_1").get();
         GlideString key = client.randomKeyBinary(RANDOM).get();
         System.out.println("The random key is: " + key);
         // The value of key is either "key" or "key1"
         
      • randomKey

        java.util.concurrent.CompletableFuture<java.lang.String> randomKey()
        Returns a random key.
        The command will be routed to all primary nodes, and will return the first successful result.
        Returns:
        A random key from the database.
        See Also:
        valkey.io for details.
        Example:
        
         String value = client.set("key", "value").get();
         String value_1 = client.set("key1", "value_1").get();
         String key = client.randomKey().get();
         System.out.println("The random key is: " + key);
         // The value of key is either "key" or "key1"
         
      • randomKeyBinary

        java.util.concurrent.CompletableFuture<GlideString> randomKeyBinary()
        Returns a random key.
        The command will be routed to all primary nodes, and will return the first successful result.
        Returns:
        A random key from the database.
        See Also:
        valkey.io for details.
        Example:
        
         String value = client.set(gs("key"),gs( "value")).get();
         String value_1 = client.set(gs("key1"), gs("value_1")).get();
         GlideString key = client.randomKeyBinary().get();
         System.out.println("The random key is: " + key);
         // The value of key is either "key" or "key1"
         
      • scan

        java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(ClusterScanCursor cursor)
        Incrementally iterates over the keys in the Cluster.

        This command is similar to the SCAN command, but it is designed to work in a Cluster environment. The main difference is that this command uses a ClusterScanCursor object to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.

        As with the SCAN command, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as the cursor argument in the next call. The iteration terminates when the returned cursor ClusterScanCursor.isFinished() returns true.

        This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.

        Note that the same key may be returned in multiple scan iterations.

        How to use the ClusterScanCursor:
        For each iteration, the previous scan ClusterScanCursor object should be used to continue the SCAN by passing it in the cursor argument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.

        When the cursor is no longer needed, call ClusterScanCursor.releaseCursorHandle() to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls to SCAN.

        Parameters:
        cursor - The ClusterScanCursor object that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor using ClusterScanCursor.initialCursor().
        Returns:
        An Array with two elements. The first element is always the ClusterScanCursor for the next iteration of results. To see if there is more data on the given cursor, call ClusterScanCursor.isFinished(). To release resources for the current cursor immediately, call ClusterScanCursor.releaseCursorHandle() after using the cursor in a call to this method. The cursor cannot be used in a scan again after ClusterScanCursor.releaseCursorHandle() has been called. The second element is an Array of String elements each representing a key.
        See Also:
        valkey.io for details.
        Example:
        
         // Assume key contains a set with 200 keys
         ClusterScanCursor cursor = ClusterScanCursor.initialCursor();
         Object[] result;
         while (!cursor.isFinished()) {
           result = client.scan(cursor).get();
           cursor.releaseCursorHandle();
           cursor = (ClusterScanCursor) result[0];
           Object[] stringResults = (Object[]) result[1];
           System.out.println("\nSCAN iteration:");
           Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", "));
         }
         
      • scanBinary

        java.util.concurrent.CompletableFuture<java.lang.Object[]> scanBinary​(ClusterScanCursor cursor)
        Incrementally iterates over the keys in the Cluster.

        This command is similar to the SCAN command, but it is designed to work in a Cluster environment. The main difference is that this command uses a ClusterScanCursor object to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.

        As with the SCAN command, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as the cursor argument in the next call. The iteration terminates when the returned cursor ClusterScanCursor.isFinished() returns true.

        This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.

        Note that the same key may be returned in multiple scan iterations.

        How to use the ClusterScanCursor:
        For each iteration, the previous scan ClusterScanCursor object should be used to continue the SCAN by passing it in the cursor argument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.

        When the cursor is no longer needed, call ClusterScanCursor.releaseCursorHandle() to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls to SCAN.

        Parameters:
        cursor - The ClusterScanCursor object that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor using ClusterScanCursor.initialCursor().
        Returns:
        An Array with two elements. The first element is always the ClusterScanCursor for the next iteration of results. To see if there is more data on the given cursor, call ClusterScanCursor.isFinished(). To release resources for the current cursor immediately, call ClusterScanCursor.releaseCursorHandle() after using the cursor in a call to this method. The cursor cannot be used in a scan again after ClusterScanCursor.releaseCursorHandle() has been called. The second element is an Array of GlideString elements each representing a key.
        See Also:
        valkey.io for details.
        Example:
        
         // Assume key contains a set with 200 keys
         ClusterScanCursor cursor = ClusterScanCursor.initialCursor();
         Object[] result;
         while (!cursor.isFinished()) {
           result = client.scan(cursor).get();
           cursor.releaseCursorHandle();
           cursor = (ClusterScanCursor) result[0];
           Object[] glideStringResults = (Object[]) result[1];
           System.out.println("\nSCAN iteration:");
           Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", "));
         }
         
      • scan

        java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(ClusterScanCursor cursor,
                                                                        ScanOptions options)
        Incrementally iterates over the keys in the Cluster.

        This command is similar to the SCAN command, but it is designed to work in a Cluster environment. The main difference is that this command uses a ClusterScanCursor object to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.

        As with the SCAN command, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as the cursor argument in the next call. The iteration terminates when the returned cursor ClusterScanCursor.isFinished() returns true.

        This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.

        Note that the same key may be returned in multiple scan iterations.

        How to use the ClusterScanCursor:
        For each iteration, the previous scan ClusterScanCursor object should be used to continue the SCAN by passing it in the cursor argument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.

        When the cursor is no longer needed, call ClusterScanCursor.releaseCursorHandle() to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls to SCAN.

        Parameters:
        cursor - The ClusterScanCursor object that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor using ClusterScanCursor.initialCursor().
        options - The ScanOptions.
        Returns:
        An Array with two elements. The first element is always the ClusterScanCursor for the next iteration of results. To see if there is more data on the given cursor, call ClusterScanCursor.isFinished(). To release resources for the current cursor immediately, call ClusterScanCursor.releaseCursorHandle() after using the cursor in a call to this method. The cursor cannot be used in a scan again after ClusterScanCursor.releaseCursorHandle() has been called. The second element is an Array of String elements each representing a key.
        See Also:
        valkey.io for details.
        Example:
        
         // Assume key contains a set with 200 keys
         ClusterScanCursor cursor = ClusterScanCursor.initialCursor();
         // Scan for keys with archived in the name
         ScanOptions options = ScanOptions.builder().matchPattern("*archived*").build();
         Object[] result;
         while (!cursor.isFinished()) {
           result = client.scan(cursor, options).get();
           cursor.releaseCursorHandle();
           cursor = (ClusterScanCursor) result[0];
           Object[] stringResults = (Object[]) result[1];
           System.out.println("\nSCAN iteration:");
           Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", "));
         }
         
      • scanBinary

        java.util.concurrent.CompletableFuture<java.lang.Object[]> scanBinary​(ClusterScanCursor cursor,
                                                                              ScanOptions options)
        Incrementally iterates over the keys in the Cluster.

        This command is similar to the SCAN command, but it is designed to work in a Cluster environment. The main difference is that this command uses a ClusterScanCursor object to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.

        As with the SCAN command, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as the cursor argument in the next call. The iteration terminates when the returned cursor ClusterScanCursor.isFinished() returns true.

        This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.

        Note that the same key may be returned in multiple scan iterations.

        How to use the ClusterScanCursor:
        For each iteration, the previous scan ClusterScanCursor object should be used to continue the SCAN by passing it in the cursor argument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.

        When the cursor is no longer needed, call ClusterScanCursor.releaseCursorHandle() to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls to SCAN.

        Parameters:
        cursor - The ClusterScanCursor object that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor using ClusterScanCursor.initialCursor().
        options - The ScanOptions.
        Returns:
        An Array with two elements. The first element is always the ClusterScanCursor for the next iteration of results. To see if there is more data on the given cursor, call ClusterScanCursor.isFinished(). To release resources for the current cursor immediately, call ClusterScanCursor.releaseCursorHandle() after using the cursor in a call to this method. The cursor cannot be used in a scan again after ClusterScanCursor.releaseCursorHandle() has been called. The second element is an Array of GlideString elements each representing a key.
        See Also:
        valkey.io for details.
        Example:
        
         // Assume key contains a set with 200 keys
         ClusterScanCursor cursor = ClusterScanCursor.initialCursor();
         // Scan for keys with archived in the name
         ScanOptions options = ScanOptions.builder().matchPattern("*archived*").build();
         Object[] result;
         while (!cursor.isFinished()) {
           result = client.scan(cursor, options).get();
           cursor.releaseCursorHandle();
           cursor = (ClusterScanCursor) result[0];
           Object[] glideStringResults = (Object[]) result[1];
           System.out.println("\nSCAN iteration:");
           Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", "));
         }