From e91a5539959b5a66122e632ed5d3e5d4a87c3173 Mon Sep 17 00:00:00 2001 From: TJ Zhang Date: Thu, 12 Sep 2024 12:40:24 -0700 Subject: [PATCH] add ScripArgOptions for the cluster client Signed-off-by: TJ Zhang --- .../src/main/java/glide/api/BaseClient.java | 45 ++++++++ .../src/main/java/glide/api/GlideClient.java | 46 -------- .../java/glide/api/GlideClusterClient.java | 84 ++++---------- .../ScriptingAndFunctionsBaseCommands.java | 87 ++++++++++++++ .../ScriptingAndFunctionsClusterCommands.java | 106 +----------------- .../api/models/commands/ScriptArgOptions.java | 22 ++++ .../commands/ScriptArgOptionsGlideString.java | 23 ++++ .../api/models/commands/ScriptOptions.java | 14 +-- .../commands/ScriptOptionsGlideString.java | 15 +-- .../glide/api/GlideClusterClientTest.java | 11 +- .../test/java/glide/cluster/CommandTests.java | 6 +- .../java/glide/standalone/CommandTests.java | 6 +- 12 files changed, 226 insertions(+), 239 deletions(-) create mode 100644 java/client/src/main/java/glide/api/models/commands/ScriptArgOptions.java create mode 100644 java/client/src/main/java/glide/api/models/commands/ScriptArgOptionsGlideString.java diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 2da4eb6a3a..cd16811bf7 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -211,6 +211,7 @@ import glide.api.models.ClusterValue; import glide.api.models.GlideString; import glide.api.models.PubSubMessage; +import glide.api.models.Script; import glide.api.models.commands.ExpireOptions; import glide.api.models.commands.GetExOptions; import glide.api.models.commands.LInsertOptions.InsertPosition; @@ -223,6 +224,8 @@ import glide.api.models.commands.RangeOptions.ScoredRangeQuery; import glide.api.models.commands.RestoreOptions; import glide.api.models.commands.ScoreFilter; +import glide.api.models.commands.ScriptOptions; +import glide.api.models.commands.ScriptOptionsGlideString; import glide.api.models.commands.SetOptions; import glide.api.models.commands.WeightAggregateOptions.Aggregate; import glide.api.models.commands.WeightAggregateOptions.KeyArray; @@ -276,6 +279,7 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -5018,4 +5022,45 @@ public CompletableFuture wait(long numreplicas, long timeout) { new String[] {Long.toString(numreplicas), Long.toString(timeout)}, this::handleLongResponse); } + + @Override + public CompletableFuture invokeScript(@NonNull Script script) { + if (script.getBinaryOutput()) { + return commandManager.submitScript( + script, List.of(), List.of(), this::handleBinaryObjectOrNullResponse); + } else { + return commandManager.submitScript( + script, List.of(), List.of(), this::handleObjectOrNullResponse); + } + } + + @Override + public CompletableFuture invokeScript( + @NonNull Script script, @NonNull ScriptOptions options) { + if (script.getBinaryOutput()) { + return commandManager.submitScript( + script, + options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), + options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), + this::handleBinaryObjectOrNullResponse); + } else { + return commandManager.submitScript( + script, + options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), + options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), + this::handleObjectOrNullResponse); + } + } + + @Override + public CompletableFuture invokeScript( + @NonNull Script script, @NonNull ScriptOptionsGlideString options) { + if (script.getBinaryOutput()) { + return commandManager.submitScript( + script, options.getKeys(), options.getArgs(), this::handleBinaryObjectOrNullResponse); + } else { + return commandManager.submitScript( + script, options.getKeys(), options.getArgs(), this::handleObjectOrNullResponse); + } + } } diff --git a/java/client/src/main/java/glide/api/GlideClient.java b/java/client/src/main/java/glide/api/GlideClient.java index e4cc31a8be..981ac5657e 100644 --- a/java/client/src/main/java/glide/api/GlideClient.java +++ b/java/client/src/main/java/glide/api/GlideClient.java @@ -51,12 +51,9 @@ import glide.api.commands.ServerManagementCommands; import glide.api.commands.TransactionsCommands; import glide.api.models.GlideString; -import glide.api.models.Script; import glide.api.models.Transaction; import glide.api.models.commands.FlushMode; import glide.api.models.commands.InfoOptions.Section; -import glide.api.models.commands.ScriptOptions; -import glide.api.models.commands.ScriptOptionsGlideString; import glide.api.models.commands.SortOptions; import glide.api.models.commands.SortOptionsBinary; import glide.api.models.commands.function.FunctionRestorePolicy; @@ -64,10 +61,8 @@ import glide.api.models.configuration.GlideClientConfiguration; import glide.utils.ArgsBuilder; import java.util.Arrays; -import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.NonNull; import org.apache.commons.lang3.ArrayUtils; @@ -577,47 +572,6 @@ public CompletableFuture scan( return commandManager.submitNewCommand(Scan, arguments, this::handleArrayResponseBinary); } - @Override - public CompletableFuture invokeScript(@NonNull Script script) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, List.of(), List.of(), this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, List.of(), List.of(), this::handleObjectOrNullResponse); - } - } - - @Override - public CompletableFuture invokeScript( - @NonNull Script script, @NonNull ScriptOptions options) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, - options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), - options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), - this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, - options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), - options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), - this::handleObjectOrNullResponse); - } - } - - @Override - public CompletableFuture invokeScript( - @NonNull Script script, @NonNull ScriptOptionsGlideString options) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, options.getKeys(), options.getArgs(), this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, options.getKeys(), options.getArgs(), this::handleObjectOrNullResponse); - } - } - @Override public CompletableFuture scriptExists(@NonNull String[] sha1s) { return commandManager.submitNewCommand( diff --git a/java/client/src/main/java/glide/api/GlideClusterClient.java b/java/client/src/main/java/glide/api/GlideClusterClient.java index 60028550b9..a3d1e9b9a2 100644 --- a/java/client/src/main/java/glide/api/GlideClusterClient.java +++ b/java/client/src/main/java/glide/api/GlideClusterClient.java @@ -59,8 +59,8 @@ import glide.api.models.Script; import glide.api.models.commands.FlushMode; import glide.api.models.commands.InfoOptions.Section; -import glide.api.models.commands.ScriptOptions; -import glide.api.models.commands.ScriptOptionsGlideString; +import glide.api.models.commands.ScriptArgOptions; +import glide.api.models.commands.ScriptArgOptionsGlideString; import glide.api.models.commands.SortClusterOptions; import glide.api.models.commands.function.FunctionRestorePolicy; import glide.api.models.commands.scan.ClusterScanCursor; @@ -957,47 +957,6 @@ public CompletableFuture functionKill(@NonNull Route route) { FunctionKill, new String[0], route, this::handleStringResponse); } - @Override - public CompletableFuture invokeScript(@NonNull Script script) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, List.of(), List.of(), this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, List.of(), List.of(), this::handleObjectOrNullResponse); - } - } - - @Override - public CompletableFuture invokeScript( - @NonNull Script script, @NonNull ScriptOptions options) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, - options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), - options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), - this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, - options.getKeys().stream().map(GlideString::gs).collect(Collectors.toList()), - options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), - this::handleObjectOrNullResponse); - } - } - - @Override - public CompletableFuture invokeScript( - @NonNull Script script, @NonNull ScriptOptionsGlideString options) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, options.getKeys(), options.getArgs(), this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, options.getKeys(), options.getArgs(), this::handleObjectOrNullResponse); - } - } - @Override public CompletableFuture invokeScript(@NonNull Script script, @NonNull Route route) { if (script.getBinaryOutput()) { @@ -1011,31 +970,26 @@ public CompletableFuture invokeScript(@NonNull Script script, @NonNull R @Override public CompletableFuture invokeScript( - @NonNull Script script, @NonNull List args, @NonNull Route route) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, - args.stream().map(GlideString::gs).collect(Collectors.toList()), - route, - this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript( - script, - args.stream().map(GlideString::gs).collect(Collectors.toList()), - route, - this::handleObjectOrNullResponse); - } + @NonNull Script script, @NonNull ScriptArgOptions options, @NonNull Route route) { + return commandManager.submitScript( + script, + options.getArgs().stream().map(GlideString::gs).collect(Collectors.toList()), + route, + script.getBinaryOutput() + ? this::handleBinaryObjectOrNullResponse + : this::handleObjectOrNullResponse); } @Override - public CompletableFuture invokeScriptBinary( - @NonNull Script script, @NonNull List args, @NonNull Route route) { - if (script.getBinaryOutput()) { - return commandManager.submitScript( - script, args, route, this::handleBinaryObjectOrNullResponse); - } else { - return commandManager.submitScript(script, args, route, this::handleObjectOrNullResponse); - } + public CompletableFuture invokeScript( + @NonNull Script script, @NonNull ScriptArgOptionsGlideString options, @NonNull Route route) { + return commandManager.submitScript( + script, + options.getArgs(), + route, + script.getBinaryOutput() + ? this::handleBinaryObjectOrNullResponse + : this::handleObjectOrNullResponse); } @Override diff --git a/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsBaseCommands.java b/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsBaseCommands.java index fbc370a276..6ad3b23ebf 100644 --- a/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsBaseCommands.java @@ -2,6 +2,9 @@ package glide.api.commands; import glide.api.models.GlideString; +import glide.api.models.Script; +import glide.api.models.commands.ScriptOptions; +import glide.api.models.commands.ScriptOptionsGlideString; import glide.api.models.configuration.ReadFrom; import java.util.concurrent.CompletableFuture; @@ -128,4 +131,88 @@ CompletableFuture fcall( */ CompletableFuture fcallReadOnly( GlideString function, GlideString[] keys, GlideString[] arguments); + + /** + * 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. + * + * @see SCRIPT LOAD and EVALSHA for details. + * @param script The Lua script to execute. + * @return A value that depends on the script that was executed. + * @example + *
{@code
+     * try(Script luaScript = new Script("return 'Hello'", false)) {
+     *     String result = (String) client.invokeScript(luaScript).get();
+     *     assert result.equals("Hello");
+     * }
+     * }
+ */ + CompletableFuture invokeScript(Script script); + + /** + * 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. + * + * @apiNote When in cluster mode + *
    + *
  • all keys must map to the same hash slot. + *
  • if no keys are given, command will be routed to a random primary node. + *
+ * + * @see SCRIPT LOAD and EVALSHA for details. + * @param script The Lua script to execute. + * @param options The script option that contains keys and arguments for the script. + * @return A value that depends on the script that was executed. + * @example + *
{@code
+     * 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");
+     * }
+     * }
+ */ + CompletableFuture 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. + * + * @apiNote When in cluster mode + *
    + *
  • all keys must map to the same hash slot. + *
  • if no keys are given, command will be routed to a random primary node. + *
+ * + * @see SCRIPT LOAD and EVALSHA for details. + * @param script The Lua script to execute. + * @param options The script option that contains keys and arguments for the script. + * @return A value that depends on the script that was executed. + * @example + *
{@code
+     * 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"));
+     * }
+     * }
+ */ + CompletableFuture invokeScript(Script script, ScriptOptionsGlideString options); } diff --git a/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsClusterCommands.java b/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsClusterCommands.java index 06cd3c6860..de62638c45 100644 --- a/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ScriptingAndFunctionsClusterCommands.java @@ -5,12 +5,11 @@ import glide.api.models.GlideString; import glide.api.models.Script; import glide.api.models.commands.FlushMode; -import glide.api.models.commands.ScriptOptions; -import glide.api.models.commands.ScriptOptionsGlideString; +import glide.api.models.commands.ScriptArgOptions; +import glide.api.models.commands.ScriptArgOptionsGlideString; import glide.api.models.commands.function.FunctionRestorePolicy; import glide.api.models.configuration.ReadFrom; import glide.api.models.configuration.RequestRoutingConfiguration.Route; -import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -1034,90 +1033,6 @@ CompletableFuture> fcallReadOnly( CompletableFuture>>> functionStatsBinary( Route route); - /** - * 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. - * - * @see SCRIPT LOAD and EVALSHA for details. - * @param script The Lua script to execute. - * @return A value that depends on the script that was executed. - * @example - *
{@code
-     * try(Script luaScript = new Script("return 'Hello'", false)) {
-     *     String result = (String) client.invokeScript(luaScript).get();
-     *     assert result.equals("Hello");
-     * }
-     * }
- */ - CompletableFuture invokeScript(Script script); - - /** - * 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. - * - * @apiNote When in cluster mode - *
    - *
  • all keys must map to the same hash slot. - *
  • if no keys are given, command will be routed to a random primary node. - *
- * - * @see SCRIPT LOAD and EVALSHA for details. - * @param script The Lua script to execute. - * @param options The script option that contains keys and arguments for the script. - * @return A value that depends on the script that was executed. - * @example - *
{@code
-     * 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");
-     * }
-     * }
- */ - CompletableFuture 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. - * - * @apiNote When in cluster mode - *
    - *
  • all keys must map to the same hash slot. - *
  • if no keys are given, command will be routed to a random primary node. - *
- * - * @see SCRIPT LOAD and EVALSHA for details. - * @param script The Lua script to execute. - * @param options The script option that contains keys and arguments for the script. - * @return A value that depends on the script that was executed. - * @example - *
{@code
-     * 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"));
-     * }
-     * }
- */ - CompletableFuture invokeScript(Script script, ScriptOptionsGlideString options); - /** * Invokes a Lua script.
* This method simplifies the process of invoking scripts on the server by using an object that @@ -1150,12 +1065,6 @@ CompletableFuture>>> func * using the SCRIPT LOAD command. After that, it will be invoked using the * EVALSHA command. * - * @apiNote When in cluster mode - *
    - *
  • all keys must map to the same hash slot. - *
  • if no keys are given, command will be routed to a random primary node. - *
- * * @see SCRIPT LOAD and EVALSHA for details. * @param script The Lua script to execute. @@ -1171,7 +1080,7 @@ CompletableFuture>>> func * } * } */ - CompletableFuture invokeScript(Script script, List args, Route route); + CompletableFuture invokeScript(Script script, ScriptArgOptions options, Route route); /** * Invokes a Lua script with its keys and arguments.
@@ -1181,12 +1090,6 @@ CompletableFuture>>> func * using the SCRIPT LOAD command. After that, it will be invoked using the * EVALSHA command. * - * @apiNote When in cluster mode - *
    - *
  • all keys must map to the same hash slot. - *
  • if no keys are given, command will be routed to a random primary node. - *
- * * @see SCRIPT LOAD and EVALSHA for details. * @param script The Lua script to execute. @@ -1202,7 +1105,8 @@ CompletableFuture>>> func * } * } */ - CompletableFuture invokeScriptBinary(Script script, List args, Route route); + CompletableFuture invokeScript( + Script script, ScriptArgOptionsGlideString options, Route route); /** * Checks existence of scripts in the script cache by their SHA1 digest.
diff --git a/java/client/src/main/java/glide/api/models/commands/ScriptArgOptions.java b/java/client/src/main/java/glide/api/models/commands/ScriptArgOptions.java new file mode 100644 index 0000000000..89460283b3 --- /dev/null +++ b/java/client/src/main/java/glide/api/models/commands/ScriptArgOptions.java @@ -0,0 +1,22 @@ +/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.api.models.commands; + +import glide.api.commands.ScriptingAndFunctionsClusterCommands; +import glide.api.models.Script; +import java.util.List; +import lombok.Getter; +import lombok.Singular; +import lombok.experimental.SuperBuilder; + +/** + * Optional arguments for {@link ScriptingAndFunctionsClusterCommands#invokeScript(Script, + * ScriptArgOptions)} command. + * + * @see valkey.io + */ +@SuperBuilder +public class ScriptArgOptions { + + /** The arguments for the script. */ + @Singular @Getter private final List args; +} diff --git a/java/client/src/main/java/glide/api/models/commands/ScriptArgOptionsGlideString.java b/java/client/src/main/java/glide/api/models/commands/ScriptArgOptionsGlideString.java new file mode 100644 index 0000000000..3aea503124 --- /dev/null +++ b/java/client/src/main/java/glide/api/models/commands/ScriptArgOptionsGlideString.java @@ -0,0 +1,23 @@ +/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.api.models.commands; + +import glide.api.commands.ScriptingAndFunctionsClusterCommands; +import glide.api.models.GlideString; +import glide.api.models.Script; +import java.util.List; +import lombok.Getter; +import lombok.Singular; +import lombok.experimental.SuperBuilder; + +/** + * Optional arguments for {@link ScriptingAndFunctionsClusterCommands#invokeScript(Script, + * ScriptArgOptionsGlideString)} command. + * + * @see valkey.io + */ +@SuperBuilder +public class ScriptArgOptionsGlideString { + + /** The arguments for the script. */ + @Singular @Getter private final List args; +} diff --git a/java/client/src/main/java/glide/api/models/commands/ScriptOptions.java b/java/client/src/main/java/glide/api/models/commands/ScriptOptions.java index dbdba5a461..3ea43210b0 100644 --- a/java/client/src/main/java/glide/api/models/commands/ScriptOptions.java +++ b/java/client/src/main/java/glide/api/models/commands/ScriptOptions.java @@ -1,24 +1,22 @@ /** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.models.commands; -import glide.api.commands.GenericBaseCommands; +import glide.api.commands.ScriptingAndFunctionsBaseCommands; import glide.api.models.Script; import java.util.List; -import lombok.Builder; import lombok.Getter; import lombok.Singular; +import lombok.experimental.SuperBuilder; /** - * Optional arguments for {@link GenericBaseCommands#invokeScript(Script, ScriptOptions)} command. + * Optional arguments for {@link ScriptingAndFunctionsBaseCommands#invokeScript(Script, + * ScriptOptions)} command. * * @see valkey.io */ -@Builder -public final class ScriptOptions { +@SuperBuilder +public final class ScriptOptions extends ScriptArgOptions { /** The keys that are used in the script. */ @Singular @Getter private final List keys; - - /** The arguments for the script. */ - @Singular @Getter private final List args; } diff --git a/java/client/src/main/java/glide/api/models/commands/ScriptOptionsGlideString.java b/java/client/src/main/java/glide/api/models/commands/ScriptOptionsGlideString.java index 50535904f4..61847f3872 100644 --- a/java/client/src/main/java/glide/api/models/commands/ScriptOptionsGlideString.java +++ b/java/client/src/main/java/glide/api/models/commands/ScriptOptionsGlideString.java @@ -1,26 +1,23 @@ /** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.models.commands; -import glide.api.commands.GenericBaseCommands; +import glide.api.commands.ScriptingAndFunctionsBaseCommands; import glide.api.models.GlideString; import glide.api.models.Script; import java.util.List; -import lombok.Builder; import lombok.Getter; import lombok.Singular; +import lombok.experimental.SuperBuilder; /** - * Optional arguments for {@link GenericBaseCommands#invokeScript(Script, ScriptOptionsGlideString)} - * command. + * Optional arguments for {@link ScriptingAndFunctionsBaseCommands#invokeScript(Script, + * ScriptOptionsGlideString)} command. * * @see valkey.io */ -@Builder -public class ScriptOptionsGlideString { +@SuperBuilder +public class ScriptOptionsGlideString extends ScriptArgOptionsGlideString { /** The keys that are used in the script. */ @Singular @Getter private final List keys; - - /** The arguments for the script. */ - @Singular @Getter private final List args; } diff --git a/java/client/src/test/java/glide/api/GlideClusterClientTest.java b/java/client/src/test/java/glide/api/GlideClusterClientTest.java index b2d997144d..db3435afe3 100644 --- a/java/client/src/test/java/glide/api/GlideClusterClientTest.java +++ b/java/client/src/test/java/glide/api/GlideClusterClientTest.java @@ -64,6 +64,8 @@ import glide.api.models.Script; import glide.api.models.commands.FlushMode; import glide.api.models.commands.InfoOptions.Section; +import glide.api.models.commands.ScriptArgOptions; +import glide.api.models.commands.ScriptArgOptionsGlideString; import glide.api.models.commands.ScriptOptions; import glide.api.models.commands.ScriptOptionsGlideString; import glide.api.models.commands.SortBaseOptions.Limit; @@ -3417,7 +3419,7 @@ public void invokeScript_with_route_args_returns_success() { String payload = "hello"; SingleNodeRoute route = RANDOM; - List args = List.of("arg1", "arg2"); + ScriptArgOptions options = ScriptArgOptions.builder().arg("arg1").arg("arg2").build(); CompletableFuture testResponse = new CompletableFuture<>(); testResponse.complete(payload); @@ -3428,7 +3430,7 @@ public void invokeScript_with_route_args_returns_success() { .thenReturn(testResponse); // exercise - CompletableFuture response = service.invokeScript(script, args, route); + CompletableFuture response = service.invokeScript(script, options, route); // verify assertEquals(testResponse, response); @@ -3445,7 +3447,8 @@ public void invokeScriptBinary_with_route_args_returns_success() { GlideString payload = gs("hello"); SingleNodeRoute route = RANDOM; - List args = List.of(gs("arg1"), gs("arg2")); + ScriptArgOptionsGlideString options = + ScriptArgOptionsGlideString.builder().arg(gs("arg1")).arg(gs("arg2")).build(); CompletableFuture testResponse = new CompletableFuture<>(); testResponse.complete(payload); @@ -3456,7 +3459,7 @@ public void invokeScriptBinary_with_route_args_returns_success() { .thenReturn(testResponse); // exercise - CompletableFuture response = service.invokeScriptBinary(script, args, route); + CompletableFuture response = service.invokeScript(script, options, route); // verify assertEquals(testResponse, response); diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 2857fd026e..fed4ea87c8 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -3241,7 +3241,7 @@ public void scriptFlush() { @SneakyThrows public void scriptKill_with_route() { // create and load a long-running script and a primary node route - Script script = new Script(createLongRunningLuaScript(10, true), true); + Script script = new Script(createLongRunningLuaScript(5, true), true); RequestRoutingConfiguration.Route route = new RequestRoutingConfiguration.SlotKeyRoute(UUID.randomUUID().toString(), PRIMARY); @@ -3259,7 +3259,7 @@ public void scriptKill_with_route() { promise.complete(null); try (var testClient = - GlideClusterClient.createClient(commonClusterClientConfig().requestTimeout(30000).build()) + GlideClusterClient.createClient(commonClusterClientConfig().requestTimeout(10000).build()) .get()) { try { testClient.invokeScript(script, route); @@ -3315,7 +3315,7 @@ public void scriptKill_unkillable() { promise.complete(null); try (var testClient = - GlideClusterClient.createClient(commonClusterClientConfig().requestTimeout(30000).build()) + GlideClusterClient.createClient(commonClusterClientConfig().requestTimeout(10000).build()) .get()) { try { // run the script without await diff --git a/java/integTest/src/test/java/glide/standalone/CommandTests.java b/java/integTest/src/test/java/glide/standalone/CommandTests.java index d66c3d1c92..9d93f5b000 100644 --- a/java/integTest/src/test/java/glide/standalone/CommandTests.java +++ b/java/integTest/src/test/java/glide/standalone/CommandTests.java @@ -2031,10 +2031,10 @@ public void scriptKill() { promise.complete(null); // create and load a long-running script - Script script = new Script(createLongRunningLuaScript(10, true), true); + Script script = new Script(createLongRunningLuaScript(5, true), true); try (var testClient = - GlideClient.createClient(commonClientConfig().requestTimeout(30000).build()).get()) { + GlideClient.createClient(commonClientConfig().requestTimeout(10000).build()).get()) { try { testClient.invokeScript(script); @@ -2087,7 +2087,7 @@ public void scriptKill_unkillable() { promise.complete(null); try (var testClient = - GlideClient.createClient(commonClientConfig().requestTimeout(30000).build()).get()) { + GlideClient.createClient(commonClientConfig().requestTimeout(10000).build()).get()) { try { // run the script without await promise = testClient.invokeScript(script, ScriptOptions.builder().key(key).build());