Package glide.api

Class GlideClient

    • Constructor Detail

      • GlideClient

        protected GlideClient​(BaseClient.ClientBuilder builder)
        Constructor using ClientParams from BaseClient.
    • Method Detail

      • createClient

        public static java.util.concurrent.CompletableFuture<GlideClient> createClient​(@NonNull
                                                                                       @NonNull GlideClientConfiguration config)
        Creates a new GlideClient instance and establishes a connection to a standalone Valkey
        Parameters:
        config - The configuration options for the client, including server addresses, authentication credentials, TLS settings, database selection, reconnection strategy, and Pub/Sub subscriptions.
        Returns:
        A Future that resolves to a connected GlideClient instance.
        Example:
        
         GlideClientConfiguration config =
             GlideClientConfiguration.builder()
                 .address(node1address)
                 .address(node2address)
                 .useTLS(true)
                 .readFrom(ReadFrom.PREFER_REPLICA)
                 .credentials(credentialsConfiguration)
                 .requestTimeout(2000)
                 .clientName("GLIDE")
                 .subscriptionConfiguration(
                     StandaloneSubscriptionConfiguration.builder()
                         .subscription(EXACT, "notifications")
                         .subscription(EXACT, "news")
                         .callback(callback)
                         .build())
                 .inflightRequestsLimit(1000)
                 .build();
         GlideClient client = GlideClient.createClient(config).get();
         
      • customCommand

        public java.util.concurrent.CompletableFuture<java.lang.Object> customCommand​(@NonNull
                                                                                      @NonNull java.lang.String[] args)
        Description copied from interface: GenericCommands
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        Specified by:
        customCommand in interface GenericCommands
        Parameters:
        args - Arguments for the custom command.
        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.
      • customCommand

        public java.util.concurrent.CompletableFuture<java.lang.Object> customCommand​(@NonNull
                                                                                      @NonNull GlideString[] args)
        Description copied from interface: GenericCommands
        Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value in args.
        Specified by:
        customCommand in interface GenericCommands
        Parameters:
        args - Arguments for the custom command.
        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.
      • exec

        @Deprecated
        public java.util.concurrent.CompletableFuture<java.lang.Object[]> exec​(@NonNull
                                                                               @NonNull Transaction transaction)
        Deprecated.
        Specified by:
        exec in interface TransactionsCommands
        Parameters:
        transaction - A Transaction object containing a list of commands to be executed.
        Returns:
        A list of results corresponding to the execution of each command in the transaction.
        See Also:
        TransactionsCommands.exec(Batch, boolean), valkey.io for details on Transactions.
      • exec

        public java.util.concurrent.CompletableFuture<java.lang.Object[]> exec​(@NonNull
                                                                               @NonNull Batch batch,
                                                                               boolean raiseOnError)
        Description copied from interface: TransactionsCommands
        Executes a batch by processing the queued commands.

        Notes:

        • Atomic Batches - Transactions: If the transaction fails due to a WATCH command, EXEC will return null.
        Specified by:
        exec in interface TransactionsCommands
        Parameters:
        batch - A Batch containing the commands to execute.
        raiseOnError - Determines how errors are handled within the batch response.

        When set to true, the first encountered error in the batch will be raised as an exception of type RequestException after all retries and reconnections have been executed.

        When set to false, errors will be included as part of the batch response, allowing the caller to process both successful and failed commands together. In this case, error details will be provided as instances of RequestException.

        Returns:
        A CompletableFuture resolving to an array of results, where each entry corresponds to a command’s execution result.
        See Also:
        Valkey Transactions (Atomic Batches), Valkey Pipelines (Non-Atomic Batches)
      • exec

        public java.util.concurrent.CompletableFuture<java.lang.Object[]> exec​(@NonNull
                                                                               @NonNull Batch batch,
                                                                               boolean raiseOnError,
                                                                               @NonNull
                                                                               @NonNull BatchOptions options)
        Description copied from interface: TransactionsCommands
        Executes a batch by processing the queued commands with additional options.

        Notes:

        • Atomic Batches - Transactions: If the transaction fails due to a WATCH command, EXEC will return null.
        Specified by:
        exec in interface TransactionsCommands
        Parameters:
        batch - A Batch containing the commands to execute.
        raiseOnError - Determines how errors are handled within the batch response.

        When set to true, the first encountered error in the batch will be raised as an exception of type RequestException after all retries and reconnections have been executed.

        When set to false, errors will be included as part of the batch response, allowing the caller to process both successful and failed commands together. In this case, error details will be provided as instances of RequestException.

        options - A BatchOptions object containing execution options.
        Returns:
        A CompletableFuture resolving to an array of results, where each entry corresponds to a command’s execution result.
        See Also:
        Valkey Transactions (Atomic Batches), Valkey Pipelines (Non-Atomic Batches)
      • ping

        public java.util.concurrent.CompletableFuture<java.lang.String> ping​(@NonNull
                                                                             @NonNull java.lang.String message)
        Description copied from interface: ConnectionManagementCommands
        Pings the server.
        Specified by:
        ping in interface ConnectionManagementCommands
        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.
      • info

        public java.util.concurrent.CompletableFuture<java.lang.String> info​(@NonNull
                                                                             @NonNull InfoOptions.Section[] sections)
        Description copied from interface: ServerManagementCommands
        Get information and statistics about the server.
        Starting from server version 7, command supports multiple section arguments.
        Specified by:
        info in interface ServerManagementCommands
        Parameters:
        sections - A list of InfoOptions.Section values specifying which sections of information to retrieve. When no parameter is provided, the InfoOptions.Section.DEFAULT option is assumed.
        Returns:
        A String containing the information for the sections requested.
        See Also:
        valkey.io for details.
      • select

        public java.util.concurrent.CompletableFuture<java.lang.String> select​(long index)
        Description copied from interface: ConnectionManagementCommands
        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();
         
        Specified by:
        select in interface ConnectionManagementCommands
        Parameters:
        index - The index of the database to select.
        Returns:
        A simple OK response.
        See Also:
        valkey.io for details.
      • clientGetName

        public java.util.concurrent.CompletableFuture<java.lang.String> clientGetName()
        Description copied from interface: ConnectionManagementCommands
        Gets the name of the current connection.
        Specified by:
        clientGetName in interface ConnectionManagementCommands
        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.
      • configRewrite

        public java.util.concurrent.CompletableFuture<java.lang.String> configRewrite()
        Description copied from interface: ServerManagementCommands
        Rewrites the configuration file with the current configuration.
        Specified by:
        configRewrite in interface ServerManagementCommands
        Returns:
        OK when the configuration was rewritten properly, otherwise an error is thrown.
        See Also:
        valkey.io for details.
      • configGet

        public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.String>> configGet​(@NonNull
                                                                                                                        @NonNull java.lang.String[] parameters)
        Description copied from interface: ServerManagementCommands
        Get the values of configuration parameters.
        Starting from server version 7, command supports multiple parameters.
        Specified by:
        configGet in interface ServerManagementCommands
        Parameters:
        parameters - An array of configuration parameter names to retrieve values for.
        Returns:
        A map of values corresponding to the configuration parameters.
        See Also:
        valkey.io for details.
      • configSet

        public java.util.concurrent.CompletableFuture<java.lang.String> configSet​(@NonNull
                                                                                  @NonNull java.util.Map<java.lang.String,​java.lang.String> parameters)
        Description copied from interface: ServerManagementCommands
        Sets configuration parameters to the specified values.
        Starting from server version 7, command supports multiple parameters.
        Specified by:
        configSet in interface ServerManagementCommands
        Parameters:
        parameters - A map consisting of configuration parameters and their respective values to set.
        Returns:
        OK if all configurations have been successfully set. Otherwise, raises an error.
        See Also:
        valkey.io for details.
      • echo

        public java.util.concurrent.CompletableFuture<java.lang.String> echo​(@NonNull
                                                                             @NonNull java.lang.String message)
        Description copied from interface: ConnectionManagementCommands
        Echoes the provided message back.
        Specified by:
        echo in interface ConnectionManagementCommands
        Parameters:
        message - The message to be echoed back.
        Returns:
        The provided message.
        See Also:
        • echo

          public java.util.concurrent.CompletableFuture<GlideString> echo​(@NonNull
                                                                          @NonNull GlideString message)
          Description copied from interface: ConnectionManagementCommands
          Echoes the provided message back.
          Specified by:
          echo in interface ConnectionManagementCommands
          Parameters:
          message - The message to be echoed back.
          Returns:
          The provided message.
          See Also:
          • time

            public java.util.concurrent.CompletableFuture<java.lang.String[]> time()
            Description copied from interface: ServerManagementCommands
            Returns the server time.
            Specified by:
            time in interface ServerManagementCommands
            Returns:
            The current server time as a String array with two elements: A UNIX TIME and the amount of microseconds already elapsed in the current second. The returned array is in a [UNIX TIME, Microseconds already elapsed] format.
            See Also:
            valkey.io for details.
          • lastsave

            public java.util.concurrent.CompletableFuture<java.lang.Long> lastsave()
            Description copied from interface: ServerManagementCommands
            Returns UNIX TIME of the last DB save timestamp or startup timestamp if no save was made since then.
            Specified by:
            lastsave in interface ServerManagementCommands
            Returns:
            UNIX TIME of the last DB save executed with success.
            See Also:
            valkey.io for details.
          • flushall

            public java.util.concurrent.CompletableFuture<java.lang.String> flushall()
            Description copied from interface: ServerManagementCommands
            Deletes all the keys of all the existing databases. This command never fails.
            Specified by:
            flushall in interface ServerManagementCommands
            Returns:
            OK.
            See Also:
            valkey.io for details.
          • flushdb

            public java.util.concurrent.CompletableFuture<java.lang.String> flushdb()
            Description copied from interface: ServerManagementCommands
            Deletes all the keys of the currently selected database. This command never fails.
            Specified by:
            flushdb in interface ServerManagementCommands
            Returns:
            OK.
            See Also:
            valkey.io for details.
          • lolwut

            public java.util.concurrent.CompletableFuture<java.lang.String> lolwut()
            Description copied from interface: ServerManagementCommands
            Displays a piece of generative computer art and the Valkey version.
            Specified by:
            lolwut in interface ServerManagementCommands
            Returns:
            A piece of generative computer art along with the current Valkey version.
            See Also:
            valkey.io for details.
          • lolwut

            public java.util.concurrent.CompletableFuture<java.lang.String> lolwut​(int @NonNull [] parameters)
            Description copied from interface: ServerManagementCommands
            Displays a piece of generative computer art and the Valkey version.
            Specified by:
            lolwut in interface ServerManagementCommands
            Parameters:
            parameters - Additional set of arguments in order to change the output:
            • On Valkey version 5, those are length of the line, number of squares per row, and number of squares per column.
            • On Valkey version 6, those are number of columns and number of lines.
            • On other versions parameters are ignored.
            Returns:
            A piece of generative computer art along with the current Valkey version.
            See Also:
            valkey.io for details.
          • lolwut

            public java.util.concurrent.CompletableFuture<java.lang.String> lolwut​(int version)
            Description copied from interface: ServerManagementCommands
            Displays a piece of generative computer art and the Valkey version.
            Specified by:
            lolwut in interface ServerManagementCommands
            Parameters:
            version - Version of computer art to generate.
            Returns:
            A piece of generative computer art along with the current Valkey version.
            See Also:
            valkey.io for details.
          • lolwut

            public java.util.concurrent.CompletableFuture<java.lang.String> lolwut​(int version,
                                                                                   int @NonNull [] parameters)
            Description copied from interface: ServerManagementCommands
            Displays a piece of generative computer art and the Valkey version.
            Specified by:
            lolwut in interface ServerManagementCommands
            Parameters:
            version - Version of computer art to generate.
            parameters - Additional set of arguments in order to change the output:
            • For version 5, those are length of the line, number of squares per row, and number of squares per column.
            • For version 6, those are number of columns and number of lines.
            Returns:
            A piece of generative computer art along with the current Valkey version.
            See Also:
            valkey.io for details.
          • dbsize

            public java.util.concurrent.CompletableFuture<java.lang.Long> dbsize()
            Description copied from interface: ServerManagementCommands
            Returns the number of keys in the currently selected database.
            Specified by:
            dbsize in interface ServerManagementCommands
            Returns:
            The number of keys in the currently selected database.
            See Also:
            valkey.io for details.
          • functionLoad

            public java.util.concurrent.CompletableFuture<java.lang.String> functionLoad​(@NonNull
                                                                                         @NonNull java.lang.String libraryCode,
                                                                                         boolean replace)
            Description copied from interface: ScriptingAndFunctionsCommands
            Loads a library to Valkey.
            Specified by:
            functionLoad in interface ScriptingAndFunctionsCommands
            Parameters:
            libraryCode - The source code that implements the library.
            replace - Whether the given library should overwrite a library with the same name if it already exists.
            Returns:
            The library name that was loaded.
            See Also:
            valkey.io for details.
          • functionLoad

            public java.util.concurrent.CompletableFuture<GlideString> functionLoad​(@NonNull
                                                                                    @NonNull GlideString libraryCode,
                                                                                    boolean replace)
            Description copied from interface: ScriptingAndFunctionsCommands
            Loads a library to Valkey.
            Specified by:
            functionLoad in interface ScriptingAndFunctionsCommands
            Parameters:
            libraryCode - The source code that implements the library.
            replace - Whether the given library should overwrite a library with the same name if it already exists.
            Returns:
            The library name that was loaded.
            See Also:
            valkey.io for details.
          • functionList

            public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>[]> functionList​(boolean withCode)
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the functions and libraries.
            Specified by:
            functionList in interface ScriptingAndFunctionsCommands
            Parameters:
            withCode - Specifies whether to request the library code from the server or not.
            Returns:
            Info about all libraries and their functions.
            See Also:
            valkey.io for details.
          • functionListBinary

            public java.util.concurrent.CompletableFuture<java.util.Map<GlideString,​java.lang.Object>[]> functionListBinary​(boolean withCode)
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the functions and libraries.
            Specified by:
            functionListBinary in interface ScriptingAndFunctionsCommands
            Parameters:
            withCode - Specifies whether to request the library code from the server or not.
            Returns:
            Info about all libraries and their functions.
            See Also:
            valkey.io for details.
          • functionList

            public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>[]> functionList​(@NonNull
                                                                                                                                 @NonNull java.lang.String libNamePattern,
                                                                                                                                 boolean withCode)
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the functions and libraries.
            Specified by:
            functionList in interface ScriptingAndFunctionsCommands
            Parameters:
            libNamePattern - A wildcard pattern for matching library names.
            withCode - Specifies whether to request the library code from the server or not.
            Returns:
            Info about queried libraries and their functions.
            See Also:
            valkey.io for details.
          • functionListBinary

            public java.util.concurrent.CompletableFuture<java.util.Map<GlideString,​java.lang.Object>[]> functionListBinary​(@NonNull
                                                                                                                                  @NonNull GlideString libNamePattern,
                                                                                                                                  boolean withCode)
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the functions and libraries.
            Specified by:
            functionListBinary in interface ScriptingAndFunctionsCommands
            Parameters:
            libNamePattern - A wildcard pattern for matching library names.
            withCode - Specifies whether to request the library code from the server or not.
            Returns:
            Info about queried libraries and their functions.
            See Also:
            valkey.io for details.
          • functionDelete

            public java.util.concurrent.CompletableFuture<java.lang.String> functionDelete​(@NonNull
                                                                                           @NonNull java.lang.String libName)
            Description copied from interface: ScriptingAndFunctionsCommands
            Deletes a library and all its functions.
            Specified by:
            functionDelete in interface ScriptingAndFunctionsCommands
            Parameters:
            libName - The library name to delete.
            Returns:
            OK.
            See Also:
            valkey.io for details.
          • fcallReadOnly

            public java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(@NonNull
                                                                                          @NonNull java.lang.String function)
            Description copied from interface: ScriptingAndFunctionsCommands
            Invokes a previously loaded read-only function.
            This command is routed depending on the client's ReadFrom strategy.
            Specified by:
            fcallReadOnly in interface ScriptingAndFunctionsCommands
            Parameters:
            function - The function name.
            Returns:
            The invoked function's return value.
            See Also:
            valkey.io for details.
          • fcallReadOnly

            public java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(@NonNull
                                                                                          @NonNull GlideString function)
            Description copied from interface: ScriptingAndFunctionsCommands
            Invokes a previously loaded read-only function.
            This command is routed depending on the client's ReadFrom strategy.
            Specified by:
            fcallReadOnly in interface ScriptingAndFunctionsCommands
            Parameters:
            function - The function name.
            Returns:
            The invoked function's return value.
            See Also:
            valkey.io for details.
          • functionKill

            public java.util.concurrent.CompletableFuture<java.lang.String> functionKill()
            Description copied from interface: ScriptingAndFunctionsCommands
            Kills a function that is currently executing.
            FUNCTION KILL terminates read-only functions only. FUNCTION KILL runs on all nodes of the server, including primary and replicas.
            Specified by:
            functionKill in interface ScriptingAndFunctionsCommands
            Returns:
            OK if function is terminated. Otherwise, throws an error.
            See Also:
            valkey.io for details.
          • functionStats

            public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.Object>>>> functionStats()
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the function that's currently running and information about the available execution engines.
            FUNCTION STATS runs on all nodes of the server, including primary and replicas. The response includes a mapping from node address to the command response for that node.
            Specified by:
            functionStats in interface ScriptingAndFunctionsCommands
            Returns:
            A Map from node address to the command response for that node, where the command contains a Map with two keys:
            • running_script with information about the running script.
            • engines with information about available engines and their stats.
            See example for more details.
            See Also:
            valkey.io for details.
          • functionStatsBinary

            public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.util.Map<GlideString,​java.util.Map<GlideString,​java.lang.Object>>>> functionStatsBinary()
            Description copied from interface: ScriptingAndFunctionsCommands
            Returns information about the function that's currently running and information about the available execution engines.
            FUNCTION STATS runs on all nodes of the server, including primary and replicas. The response includes a mapping from node address to the command response for that node.
            Specified by:
            functionStatsBinary in interface ScriptingAndFunctionsCommands
            Returns:
            A Map from node address to the command response for that node, where the command contains a Map with two keys:
            • running_script with information about the running script.
            • engines with information about available engines and their stats.
            See example for more details.
            See Also:
            valkey.io for details.
          • unwatch

            public java.util.concurrent.CompletableFuture<java.lang.String> unwatch()
            Description copied from interface: TransactionsCommands
            Flushes all the previously watched keys for a transaction. Executing a transaction will automatically flush all previously watched keys.
            Specified by:
            unwatch in interface TransactionsCommands
            Returns:
            OK.
            See Also:
            valkey.io for details.
          • randomKey

            public java.util.concurrent.CompletableFuture<java.lang.String> randomKey()
            Description copied from interface: GenericCommands
            Returns a random key from currently selected database.
            Specified by:
            randomKey in interface GenericCommands
            Returns:
            A random key from the database.
            See Also:
            valkey.io for details.
          • randomKeyBinary

            public java.util.concurrent.CompletableFuture<GlideString> randomKeyBinary()
            Description copied from interface: GenericCommands
            Returns a random key from currently selected database.
            Specified by:
            randomKeyBinary in interface GenericCommands
            Returns:
            A random key from the database.
            See Also:
            valkey.io for details.
          • scan

            public java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(@NonNull
                                                                                   @NonNull java.lang.String cursor)
            Description copied from interface: GenericCommands
            Iterates incrementally over a database for matching keys.
            Specified by:
            scan in interface GenericCommands
            Parameters:
            cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.
            Returns:
            An Array of Objects. The first element is always the cursor for the next iteration of results. "0" will be the cursor returned on the last iteration of the scan.
            The second element is always an Array of matched keys from the database.
            See Also:
            valkey.io for details.
          • scan

            public java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(@NonNull
                                                                                   @NonNull GlideString cursor)
            Description copied from interface: GenericCommands
            Iterates incrementally over a database for matching keys.
            Specified by:
            scan in interface GenericCommands
            Parameters:
            cursor - The cursor that points to the next iteration of results. A value of gs("0") indicates the start of the search.
            Returns:
            An Array of Objects. The first element is always the cursor for the next iteration of results. gs("0") will be the cursor returned on the last iteration of the scan.
            The second element is always an Array of matched keys from the database.
            See Also:
            valkey.io for details.
          • scan

            public java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(@NonNull
                                                                                   @NonNull java.lang.String cursor,
                                                                                   @NonNull
                                                                                   @NonNull ScanOptions options)
            Description copied from interface: GenericCommands
            Iterates incrementally over a database for matching keys.
            Specified by:
            scan in interface GenericCommands
            Parameters:
            cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.
            options - The ScanOptions.
            Returns:
            An Array of Objects. The first element is always the cursor for the next iteration of results. "0" will be the cursor returned on the last iteration of the scan.
            The second element is always an Array of matched keys from the database.
            See Also:
            valkey.io for details.
          • scan

            public java.util.concurrent.CompletableFuture<java.lang.Object[]> scan​(@NonNull
                                                                                   @NonNull GlideString cursor,
                                                                                   @NonNull
                                                                                   @NonNull ScanOptions options)
            Description copied from interface: GenericCommands
            Iterates incrementally over a database for matching keys.
            Specified by:
            scan in interface GenericCommands
            Parameters:
            cursor - The cursor that points to the next iteration of results. A value of gs("0") indicates the start of the search.
            options - The ScanOptions.
            Returns:
            An Array of Objects. The first element is always the cursor for the next iteration of results. gs("0") will be the cursor returned on the last iteration of the scan.
            The second element is always an Array of matched keys from the database.
            See Also:
            valkey.io for details.