Interface ConnectionManagementCommands

  • All Known Implementing Classes:
    GlideClient

    public interface ConnectionManagementCommands
    Supports commands for the "Connection Management" group for a standalone client.
    See Also:
    Connection Management Commands
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.String> clientGetName()
      Gets the name of the current connection.
      java.util.concurrent.CompletableFuture<java.lang.Long> clientId()
      Gets the current connection id.
      java.util.concurrent.CompletableFuture<java.lang.String> clientPause​(long timeout)
      Suspends all clients for the specified timeout.
      java.util.concurrent.CompletableFuture<java.lang.String> clientPause​(long timeout, ClientPauseMode mode)
      Suspends all clients for the specified timeout.
      java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> clientTrackingInfo()
      Returns information about the current client connection's use of the server assisted client side caching feature.
      java.util.concurrent.CompletableFuture<java.lang.String> clientUnpause()
      Resumes processing commands on all clients.
      java.util.concurrent.CompletableFuture<GlideString> echo​(GlideString message)
      Echoes the provided message back.
      java.util.concurrent.CompletableFuture<java.lang.String> echo​(java.lang.String message)
      Echoes the provided message back.
      java.util.concurrent.CompletableFuture<java.lang.String> ping()
      Pings the server.
      java.util.concurrent.CompletableFuture<GlideString> ping​(GlideString message)
      Pings the server.
      java.util.concurrent.CompletableFuture<java.lang.String> ping​(java.lang.String message)
      Pings the server.
      java.util.concurrent.CompletableFuture<java.lang.String> reset()
      Resets the connection state.
      java.util.concurrent.CompletableFuture<java.lang.String> select​(long index)
      Changes the currently selected database.
    • Method Detail

      • ping

        java.util.concurrent.CompletableFuture<java.lang.String> ping()
        Pings the server.
        Returns:
        String with "PONG".
        See Also:
        valkey.io for details.
        Example:
        
         String payload = client.ping().get();
         assert payload.equals("PONG");
         
      • ping

        java.util.concurrent.CompletableFuture<java.lang.String> ping​(java.lang.String message)
        Pings the server.
        Parameters:
        message - The server will respond with a copy of the message.
        Returns:
        String with a copy of the argument message.
        See Also:
        valkey.io for details.
        Example:
        
         String payload = client.ping("GLIDE").get();
         assert payload.equals("GLIDE");
         
      • ping

        java.util.concurrent.CompletableFuture<GlideString> ping​(GlideString message)
        Pings the server.
        Parameters:
        message - The server will respond with a copy of the message.
        Returns:
        GlideString with a copy of the argument message.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString payload = client.ping(gs("GLIDE")).get();
         assert payload.equals(gs("GLIDE"));
         
      • clientId

        java.util.concurrent.CompletableFuture<java.lang.Long> clientId()
        Gets the current connection id.
        Returns:
        The id of the client.
        See Also:
        valkey.io for details.
        Example:
        
         Long id = client.clientId().get();
         assert id > 0;
         
      • clientGetName

        java.util.concurrent.CompletableFuture<java.lang.String> clientGetName()
        Gets the name of the current connection.
        Returns:
        The name of the client connection as a string if a name is set, or null if no name is assigned.
        See Also:
        valkey.io for details.
        Example:
        
         String clientName = client.clientGetName().get();
         assert clientName != null;
         
      • echo

        java.util.concurrent.CompletableFuture<java.lang.String> echo​(java.lang.String message)
        Echoes the provided message back.
        Parameters:
        message - The message to be echoed back.
        Returns:
        The provided message.
        See Also:
        valkey.io for details.
        Example:
        
         String payload = client.echo("GLIDE").get();
         assert payload.equals("GLIDE");
         
      • echo

        java.util.concurrent.CompletableFuture<GlideString> echo​(GlideString message)
        Echoes the provided message back.
        Parameters:
        message - The message to be echoed back.
        Returns:
        The provided message.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString payload = client.echo(gs("GLIDE")).get();
         assert payload.equals(gs("GLIDE"));
         
      • select

        java.util.concurrent.CompletableFuture<java.lang.String> select​(long index)
        Changes the currently selected database.

        WARNING: This command is NOT RECOMMENDED for production use. Upon reconnection, the client will revert to the database_id specified in the client configuration (default: 0), NOT the database selected via this command.

        RECOMMENDED APPROACH: Use the database_id parameter in client configuration instead:

        RECOMMENDED EXAMPLE:

        
         GlideClient client = GlideClient.createClient(
             GlideClientConfiguration.builder()
                 .address(NodeAddress.builder().host("localhost").port(6379).build())
                 .databaseId(5)  // Recommended: persists across reconnections
                 .build()
         ).get();
         
        Parameters:
        index - The index of the database to select.
        Returns:
        A simple OK response.
        See Also:
        valkey.io for details.
        Example:
        
         String response = regularClient.select(0).get();
         assert response.equals("OK");
         
      • clientPause

        java.util.concurrent.CompletableFuture<java.lang.String> clientPause​(long timeout)
        Suspends all clients for the specified timeout.
        Parameters:
        timeout - The time in milliseconds to suspend clients.
        Returns:
        "OK" response on success.
        See Also:
        valkey.io for details.
        Example:
        
         String result = client.clientPause(1000).get();
         assert result.equals("OK");
         
      • clientPause

        java.util.concurrent.CompletableFuture<java.lang.String> clientPause​(long timeout,
                                                                             ClientPauseMode mode)
        Suspends all clients for the specified timeout.
        Parameters:
        timeout - The time in milliseconds to pause clients.
        mode - The pause mode to use.
        Returns:
        "OK" response on success.
        See Also:
        valkey.io for details.
        Example:
        
         String result = client.clientPause(1000, ClientPauseMode.WRITE).get();
         assert result.equals("OK");
         
      • clientUnpause

        java.util.concurrent.CompletableFuture<java.lang.String> clientUnpause()
        Resumes processing commands on all clients.
        Returns:
        "OK" response on success.
        See Also:
        valkey.io for details.
        Example:
        
         String result = client.clientUnpause().get();
         assert result.equals("OK");
         
      • reset

        java.util.concurrent.CompletableFuture<java.lang.String> reset()
        Resets the connection state.
        Returns:
        String with "RESET".
        See Also:
        valkey.io for details.
        Example:
        
         String payload = client.reset().get();
         assert payload.equals("RESET");
         
      • clientTrackingInfo

        java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> clientTrackingInfo()
        Returns information about the current client connection's use of the server assisted client side caching feature.
        Returns:
        A Map with the client's tracking state. The map contains:
        • flags: a Set of tracking flags. See valkey.io for the full list.
        • redirect: a Long with the client ID receiving invalidation messages, or -1 if not redirecting
        • prefixes: an Object[] of key prefixes monitored for invalidation
        See Also:
        valkey.io for details.
        Example:
        
         // Tracking off (default):
         Map<String, Object> info = client.clientTrackingInfo().get();
         Set<String> flags = (Set<String>) info.get("flags");     // e.g. {"off"}
         Long redirect = (Long) info.get("redirect");              // e.g. -1L
         Object[] prefixes = (Object[]) info.get("prefixes");     // e.g. []
         // Tracking on with prefix:
         // {"flags": {"on", "noloop"}, "redirect": -1L, "prefixes": ["key:"]}
         for (Object prefix : (Object[]) info.get("prefixes")) {
             System.out.println((String) prefix);
         }