Interface ScriptingAndFunctionsBaseCommands

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(GlideString script)
      Executes a read-only Lua script.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(GlideString script, GlideString[] keys, GlideString[] args)
      Executes a read-only Lua script with keys and arguments.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(java.lang.String script)
      Executes a read-only Lua script.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(java.lang.String script, java.lang.String[] keys, java.lang.String[] args)
      Executes a read-only Lua script with keys and arguments.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(GlideString sha1)
      Executes a read-only Lua script by its SHA1 digest.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(GlideString sha1, GlideString[] keys, GlideString[] args)
      Executes a read-only Lua script by its SHA1 digest with keys and arguments.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(java.lang.String sha1)
      Executes a read-only Lua script by its SHA1 digest.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(java.lang.String sha1, java.lang.String[] keys, java.lang.String[] args)
      Executes a read-only Lua script by its SHA1 digest with keys and arguments.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> fcall​(GlideString function, GlideString[] keys, GlideString[] arguments)
      Invokes a previously loaded function.
      This command is routed to primary nodes only.
      To route to a replica please refer to fcallReadOnly(java.lang.String, java.lang.String[], java.lang.String[]).
      java.util.concurrent.CompletableFuture<java.lang.Object> fcall​(java.lang.String function, java.lang.String[] keys, java.lang.String[] arguments)
      Invokes a previously loaded function.
      This command is routed to primary nodes only.
      To route to a replica please refer to fcallReadOnly(java.lang.String, java.lang.String[], java.lang.String[]).
      java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(GlideString function, GlideString[] keys, GlideString[] arguments)
      Invokes a previously loaded read-only function.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(java.lang.String function, java.lang.String[] keys, java.lang.String[] arguments)
      Invokes a previously loaded read-only function.
      This command is routed depending on the client's ReadFrom strategy.
      java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script)
      Invokes a Lua script.
      This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script.
      java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script, ScriptOptions options)
      Invokes a Lua script with its keys and arguments.
      This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script.
      java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script, ScriptOptionsGlideString options)
      Invokes a Lua script with its keys and arguments.
      This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script.
      java.util.concurrent.CompletableFuture<java.lang.String> scriptDebug​(ScriptDebugMode mode)
      Sets the debugging mode for executed scripts.
      java.util.concurrent.CompletableFuture<GlideString> scriptShow​(GlideString sha1)
      Returns the original source code of a script in the script cache.
      java.util.concurrent.CompletableFuture<java.lang.String> scriptShow​(java.lang.String sha1)
      Returns the original source code of a script in the script cache.
    • Method Detail

      • fcall

        java.util.concurrent.CompletableFuture<java.lang.Object> fcall​(java.lang.String function,
                                                                       java.lang.String[] keys,
                                                                       java.lang.String[] arguments)
        Invokes a previously loaded function.
        This command is routed to primary nodes only.
        To route to a replica please refer to fcallReadOnly(java.lang.String, java.lang.String[], java.lang.String[]).
        Parameters:
        function - The function name.
        keys - An array of keys accessed by the function. To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as keys.
        arguments - An array of function arguments. arguments should not represent names of keys.
        Returns:
        The invoked function's return value.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String[] args = new String[] { "Answer", "to", "the", "Ultimate", "Question", "of", "Life,", "the", "Universe,", "and", "Everything"};
         Object response = client.fcall("Deep_Thought", new String[0], args).get();
         assert response == 42L;
         
      • fcall

        java.util.concurrent.CompletableFuture<java.lang.Object> fcall​(GlideString function,
                                                                       GlideString[] keys,
                                                                       GlideString[] arguments)
        Invokes a previously loaded function.
        This command is routed to primary nodes only.
        To route to a replica please refer to fcallReadOnly(java.lang.String, java.lang.String[], java.lang.String[]).
        Parameters:
        function - The function name.
        keys - An array of keys accessed by the function. To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as keys.
        arguments - An array of function arguments. arguments should not represent names of keys.
        Returns:
        The invoked function's return value.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString[] args = new GlideString[] { gs("Answer"), gs("to"), gs("the"), gs("Ultimate"), gs("Question"), gs("of"), gs("Life,"), gs("the"), gs("Universe,"), gs("and"), gs("Everything")};
         Object response = client.fcall(gs("Deep_Thought"), new GlideString[0], args).get();
         assert response == 42L;
         
      • fcallReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(java.lang.String function,
                                                                               java.lang.String[] keys,
                                                                               java.lang.String[] arguments)
        Invokes a previously loaded read-only function.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        function - The function name.
        keys - An array of keys accessed by the function. To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as keys.
        arguments - An array of function arguments. arguments should not represent names of keys.
        Returns:
        The invoked function's return value.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String[] args = new String[] { "Answer", "to", "the", "Ultimate", "Question", "of", "Life,", "the", "Universe,", "and", "Everything"};
         Object response = client.fcallReadOnly("Deep_Thought", new String[0], args).get();
         assert response == 42L;
         
      • fcallReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> fcallReadOnly​(GlideString function,
                                                                               GlideString[] keys,
                                                                               GlideString[] arguments)
        Invokes a previously loaded read-only function.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        function - The function name.
        keys - An array of keys accessed by the function. To ensure the correct execution of functions, both in standalone and clustered deployments, all names of keys that a function accesses must be explicitly provided as keys.
        arguments - An array of function arguments. arguments should not represent names of keys.
        Returns:
        The invoked function's return value.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString[] args = new GlideString[] { gs("Answer"), gs("to"), gs("the"), gs("Ultimate"), gs("Question"), gs("of"), gs("Life,"), gs("the"), gs("Universe,"), gs("and"), gs("Everything")};
         Object response = client.fcallReadOnly(gs("Deep_Thought"), new GlideString[0], args).get();
         assert response == 42L;
         
      • scriptShow

        java.util.concurrent.CompletableFuture<java.lang.String> scriptShow​(java.lang.String sha1)
        Returns the original source code of a script in the script cache.
        Parameters:
        sha1 - The SHA1 digest of the script.
        Returns:
        The original source code of the script, if present in the cache. If the script is not found in the cache, an error is thrown.
        Since:
        Valkey 8.0.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String scriptSource = client.scriptShow(luaScript.getHash()).get();
         assert scriptSource.equals("return { KEYS[1], ARGV[1] }");
         
      • scriptShow

        java.util.concurrent.CompletableFuture<GlideString> scriptShow​(GlideString sha1)
        Returns the original source code of a script in the script cache.
        Parameters:
        sha1 - The SHA1 digest of the script.
        Returns:
        The original source code of the script, if present in the cache. If the script is not found in the cache, an error is thrown.
        Since:
        Valkey 8.0.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String scriptSource = client.scriptShow(gs(luaScript.getHash())).get();
         assert scriptSource.equals(gs("return { KEYS[1], ARGV[1] }"));
         
      • invokeScript

        java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script)
        Invokes a Lua script.
        This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script. The script loading and execution will all be handled internally. If the script has not already been loaded, it will be loaded automatically using the SCRIPT LOAD command. After that, it will be invoked using the EVALSHA command.
        Parameters:
        script - The Lua script to execute.
        Returns:
        A value that depends on the script that was executed.
        See Also:
        SCRIPT LOAD and EVALSHA for details.
        Example:
        
         try(Script luaScript = new Script("return 'Hello'", false)) {
             String result = (String) client.invokeScript(luaScript).get();
             assert result.equals("Hello");
         }
         
      • invokeScript

        java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script,
                                                                              ScriptOptions options)
        Invokes a Lua script with its keys and arguments.
        This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script. The script loading, argument preparation, and execution will all be handled internally. If the script has not already been loaded, it will be loaded automatically using the SCRIPT LOAD command. After that, it will be invoked using the EVALSHA command.
        Parameters:
        script - The Lua script to execute.
        options - The script option that contains keys and arguments for the script.
        Returns:
        A value that depends on the script that was executed.
        See Also:
        SCRIPT LOAD and EVALSHA for details.
        Example:
        
         try(Script luaScript = new Script("return { KEYS[1], ARGV[1] }", false)) {
             ScriptOptions scriptOptions = ScriptOptions.builder().key("foo").arg("bar").build();
             Object[] result = (Object[]) client.invokeScript(luaScript, scriptOptions).get();
             assert result[0].equals("foo");
             assert result[1].equals("bar");
         }
         
      • invokeScript

        java.util.concurrent.CompletableFuture<java.lang.Object> invokeScript​(Script script,
                                                                              ScriptOptionsGlideString options)
        Invokes a Lua script with its keys and arguments.
        This method simplifies the process of invoking scripts on the server by using an object that represents a Lua script. The script loading, argument preparation, and execution will all be handled internally. If the script has not already been loaded, it will be loaded automatically using the SCRIPT LOAD command. After that, it will be invoked using the EVALSHA command.
        Parameters:
        script - The Lua script to execute.
        options - The script option that contains keys and arguments for the script.
        Returns:
        A value that depends on the script that was executed.
        See Also:
        SCRIPT LOAD and EVALSHA for details.
        Example:
        
         try(Script luaScript = new Script(gs("return { KEYS[1], ARGV[1] }", true))) {
             ScriptOptionsGlideString scriptOptions = ScriptOptionsGlideString.builder().key(gs("foo")).arg(gs("bar")).build();
             Object[] result = (Object[]) client.invokeScript(luaScript, scriptOptions).get();
             assert result[0].equals(gs("foo"));
             assert result[1].equals(gs("bar"));
         }
         
      • evalReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(java.lang.String script)
        Executes a read-only Lua script.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        script - The Lua script to execute.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String script = "return 'Hello, World!'";
         String result = (String) client.evalReadOnly(script).get();
         assert result.equals("Hello, World!");
         
      • evalReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(java.lang.String script,
                                                                              java.lang.String[] keys,
                                                                              java.lang.String[] args)
        Executes a read-only Lua script with keys and arguments.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        script - The Lua script to execute.
        keys - An array of keys accessed by the script.
        args - An array of script arguments.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String script = "return {KEYS[1], ARGV[1]}";
         Object[] result = (Object[]) client.evalReadOnly(script, new String[]{"key1"}, new String[]{"arg1"}).get();
         assert result[0].equals("key1");
         assert result[1].equals("arg1");
         
      • evalReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(GlideString script)
        Executes a read-only Lua script.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        script - The Lua script to execute.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString script = gs("return 'Hello, World!'");
         GlideString result = (GlideString) client.evalReadOnly(script).get();
         assert result.equals(gs("Hello, World!"));
         
      • evalReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalReadOnly​(GlideString script,
                                                                              GlideString[] keys,
                                                                              GlideString[] args)
        Executes a read-only Lua script with keys and arguments.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        script - The Lua script to execute.
        keys - An array of keys accessed by the script.
        args - An array of script arguments.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString script = gs("return {KEYS[1], ARGV[1]}");
         Object[] result = (Object[]) client.evalReadOnly(script, new GlideString[]{gs("key1")}, new GlideString[]{gs("arg1")}).get();
         assert result[0].equals(gs("key1"));
         assert result[1].equals(gs("arg1"));
         
      • evalshaReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(java.lang.String sha1)
        Executes a read-only Lua script by its SHA1 digest.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        sha1 - The SHA1 digest of the script to execute.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String sha1 = client.scriptLoad("return 'Hello from SHA!'").get();
         String result = (String) client.evalshaReadOnly(sha1).get();
         assert result.equals("Hello from SHA!");
         
      • evalshaReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(java.lang.String sha1,
                                                                                 java.lang.String[] keys,
                                                                                 java.lang.String[] args)
        Executes a read-only Lua script by its SHA1 digest with keys and arguments.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        sha1 - The SHA1 digest of the script to execute.
        keys - An array of keys accessed by the script.
        args - An array of script arguments.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String sha1 = client.scriptLoad("return {KEYS[1], ARGV[1]}").get();
         Object[] result = (Object[]) client.evalshaReadOnly(sha1, new String[]{"key1"}, new String[]{"arg1"}).get();
         assert result[0].equals("key1");
         assert result[1].equals("arg1");
         
      • evalshaReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(GlideString sha1)
        Executes a read-only Lua script by its SHA1 digest.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        sha1 - The SHA1 digest of the script to execute.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString sha1 = client.scriptLoad(gs("return 'Hello from SHA!'")).get();
         GlideString result = (GlideString) client.evalshaReadOnly(sha1).get();
         assert result.equals(gs("Hello from SHA!"));
         
      • evalshaReadOnly

        java.util.concurrent.CompletableFuture<java.lang.Object> evalshaReadOnly​(GlideString sha1,
                                                                                 GlideString[] keys,
                                                                                 GlideString[] args)
        Executes a read-only Lua script by its SHA1 digest with keys and arguments.
        This command is routed depending on the client's ReadFrom strategy.
        Parameters:
        sha1 - The SHA1 digest of the script to execute.
        keys - An array of keys accessed by the script.
        args - An array of script arguments.
        Returns:
        A value that depends on the script that was executed.
        Since:
        Valkey 7.0 and above.
        See Also:
        valkey.io for details.
        Example:
        
         GlideString sha1 = client.scriptLoad(gs("return {KEYS[1], ARGV[1]}")).get();
         Object[] result = (Object[]) client.evalshaReadOnly(sha1, new GlideString[]{gs("key1")}, new GlideString[]{gs("arg1")}).get();
         assert result[0].equals(gs("key1"));
         assert result[1].equals(gs("arg1"));
         
      • scriptDebug

        java.util.concurrent.CompletableFuture<java.lang.String> scriptDebug​(ScriptDebugMode mode)
        Sets the debugging mode for executed scripts.
        Parameters:
        mode - The debugging mode to set.
        Returns:
        OK.
        Since:
        Redis 3.2 and above.
        See Also:
        valkey.io for details.
        Example:
        
         String response = client.scriptDebug(ScriptDebugMode.YES).get();
         assert response.equals("OK");