Interface ConnectionControlCommands

  • All Known Implementing Classes:
    GlideClusterClient

    public interface ConnectionControlCommands
    Supports commands for connection-level control in cluster mode, particularly for read operations on replicas and slot migration scenarios.
    See Also:
    Cluster Commands
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.String> asking()
      Allows the execution of commands in the context of a slot migration.
      java.util.concurrent.CompletableFuture<java.lang.String> readonly()
      Enables read queries for a connection to a cluster replica node.
      java.util.concurrent.CompletableFuture<java.lang.String> readwrite()
      Disables read queries for a connection to a cluster replica node.
    • Method Detail

      • readonly

        java.util.concurrent.CompletableFuture<java.lang.String> readonly()
        Enables read queries for a connection to a cluster replica node. By default, replica nodes in a cluster will redirect read commands to the primary node. This command allows read commands to be executed on the replica node itself.
        This command affects only the current connection and must be sent to a replica node.
        Returns:
        OK if read-only mode was successfully enabled for this connection.
        See Also:
        valkey.io for details.
        Example:
        
         String result = clusterClient.readonly().get();
         assert result.equals("OK");
         // Now read commands can be executed on this replica connection
         
      • readwrite

        java.util.concurrent.CompletableFuture<java.lang.String> readwrite()
        Disables read queries for a connection to a cluster replica node. This is the default mode. After calling this command, the replica node will redirect read commands to the primary node.
        This command affects only the current connection and must be sent to a replica node.
        Returns:
        OK if read-write mode was successfully restored for this connection.
        See Also:
        valkey.io for details.
        Example:
        
         String result = clusterClient.readwrite().get();
         assert result.equals("OK");
         // Now read commands will be redirected to the primary node
         
      • asking

        java.util.concurrent.CompletableFuture<java.lang.String> asking()
        Allows the execution of commands in the context of a slot migration. When a slot is being migrated from one node to another, this command signals that the current connection is aware of the migration and should allow commands targeting the migrating slot to proceed.
        This is typically used after receiving an ASK redirection error during slot migration.
        Returns:
        OK if the ASKING flag was successfully set for the next command.
        See Also:
        valkey.io for details.
        Example:
        
         // After receiving an ASK error during slot migration:
         // 1. Connect to the target node
         // 2. Execute ASKING
         String result = clusterClient.asking().get();
         assert result.equals("OK");
         // 3. Retry the command on this connection