Skip to content

Commit

Permalink
fixing conflict resolving changes
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Zhang <[email protected]>
  • Loading branch information
TJ Zhang committed Sep 12, 2024
1 parent 5a46a00 commit 3038c53
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 254 deletions.
41 changes: 0 additions & 41 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5142,45 +5142,4 @@ public CompletableFuture<Long> wait(long numreplicas, long timeout) {
new String[] {Long.toString(numreplicas), Long.toString(timeout)},
this::handleLongResponse);
}

@Override
public CompletableFuture<Object> 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<Object> 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<Object> 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);
}
}
}
2 changes: 0 additions & 2 deletions java/client/src/main/java/glide/api/GlideClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import glide.api.models.Transaction;
import glide.api.models.commands.FlushMode;
import glide.api.models.commands.InfoOptions.Section;
import glide.api.models.commands.SortOptions;
import glide.api.models.commands.SortOptionsBinary;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.commands.scan.ScanOptions;
import glide.api.models.configuration.GlideClientConfiguration;
Expand Down
3 changes: 0 additions & 3 deletions java/client/src/main/java/glide/api/GlideClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import static command_request.CommandRequestOuterClass.RequestType.ScriptExists;
import static command_request.CommandRequestOuterClass.RequestType.ScriptFlush;
import static command_request.CommandRequestOuterClass.RequestType.ScriptKill;
import static command_request.CommandRequestOuterClass.RequestType.Sort;
import static command_request.CommandRequestOuterClass.RequestType.SortReadOnly;
import static command_request.CommandRequestOuterClass.RequestType.Time;
import static command_request.CommandRequestOuterClass.RequestType.UnWatch;
import static glide.api.commands.ServerManagementCommands.VERSION_VALKEY_API;
Expand Down Expand Up @@ -62,7 +60,6 @@
import glide.api.models.commands.InfoOptions.Section;
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;
import glide.api.models.commands.scan.ScanOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import glide.api.models.GlideString;
import glide.api.models.commands.ExpireOptions;
import glide.api.models.commands.RestoreOptions;
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.configuration.ReadFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
package glide.api.commands;

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.function.FunctionRestorePolicy;
import glide.api.models.configuration.ReadFrom;
import java.util.Map;
Expand Down Expand Up @@ -417,90 +414,6 @@ CompletableFuture<Map<GlideString, Object>[]> functionListBinary(
*/
CompletableFuture<Map<String, Map<GlideString, Map<GlideString, Object>>>> functionStatsBinary();

/**
* Invokes a Lua script.<br>
* 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 <code>
* SCRIPT LOAD</code> command. After that, it will be invoked using the <code>EVALSHA </code>
* command.
*
* @see <a href="https://valkey.io/commands/script-load/">SCRIPT LOAD</a> and <a
* href="https://valkey.io/commands/evalsha/">EVALSHA</a> for details.
* @param script The Lua script to execute.
* @return A value that depends on the script that was executed.
* @example
* <pre>{@code
* try(Script luaScript = new Script("return 'Hello'", false)) {
* String result = (String) client.invokeScript(luaScript).get();
* assert result.equals("Hello");
* }
* }</pre>
*/
CompletableFuture<Object> invokeScript(Script script);

/**
* Invokes a Lua script with its keys and arguments.<br>
* 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 <code>SCRIPT LOAD</code> command. After that, it will be invoked using the <code>
* EVALSHA</code> command.
*
* @apiNote When in cluster mode
* <ul>
* <li>all <code>keys</code> must map to the same hash slot.
* <li>if no <code>keys</code> are given, command will be routed to a random primary node.
* </ul>
*
* @see <a href="https://valkey.io/commands/script-load/">SCRIPT LOAD</a> and <a
* href="https://valkey.io/commands/evalsha/">EVALSHA</a> 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
* <pre>{@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");
* }
* }</pre>
*/
CompletableFuture<Object> invokeScript(Script script, ScriptOptions options);

/**
* Invokes a Lua script with its keys and arguments.<br>
* 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 <code>SCRIPT LOAD</code> command. After that, it will be invoked using the <code>
* EVALSHA</code> command.
*
* @apiNote When in cluster mode
* <ul>
* <li>all <code>keys</code> must map to the same hash slot.
* <li>if no <code>keys</code> are given, command will be routed to a random primary node.
* </ul>
*
* @see <a href="https://valkey.io/commands/script-load/">SCRIPT LOAD</a> and <a
* href="https://valkey.io/commands/evalsha/">EVALSHA</a> 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
* <pre>{@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"));
* }
* }</pre>
*/
CompletableFuture<Object> invokeScript(Script script, ScriptOptionsGlideString options);

/**
* Checks existence of scripts in the script cache by their SHA1 digest.
*
Expand Down
2 changes: 1 addition & 1 deletion java/client/src/test/java/glide/api/GlideClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@
import static command_request.CommandRequestOuterClass.RequestType.SUnion;
import static command_request.CommandRequestOuterClass.RequestType.SUnionStore;
import static command_request.CommandRequestOuterClass.RequestType.Scan;
import static command_request.CommandRequestOuterClass.RequestType.ScriptShow;
import static command_request.CommandRequestOuterClass.RequestType.ScriptExists;
import static command_request.CommandRequestOuterClass.RequestType.ScriptFlush;
import static command_request.CommandRequestOuterClass.RequestType.ScriptKill;
import static command_request.CommandRequestOuterClass.RequestType.ScriptShow;
import static command_request.CommandRequestOuterClass.RequestType.Select;
import static command_request.CommandRequestOuterClass.RequestType.SetBit;
import static command_request.CommandRequestOuterClass.RequestType.SetRange;
Expand Down
117 changes: 1 addition & 116 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import glide.api.GlideClient;
import glide.api.GlideClusterClient;
import glide.api.models.GlideString;
import glide.api.models.Script;
import glide.api.models.commands.ConditionalChange;
import glide.api.models.commands.ExpireOptions;
import glide.api.models.commands.GetExOptions;
Expand Down Expand Up @@ -3130,122 +3131,6 @@ public void persist_on_existing_and_non_existing_key(BaseClient client) {
assertEquals(-1L, client.ttl(key).get());
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
public void invokeScript_test(BaseClient client) {
String key1 = UUID.randomUUID().toString();
String key2 = UUID.randomUUID().toString();

try (Script script = new Script("return 'Hello'", false)) {
Object response = client.invokeScript(script).get();
assertEquals("Hello", response);
}

try (Script script = new Script("return redis.call('SET', KEYS[1], ARGV[1])", false)) {
Object setResponse1 =
client
.invokeScript(script, ScriptOptions.builder().key(key1).arg("value1").build())
.get();
assertEquals(OK, setResponse1);

Object setResponse2 =
client
.invokeScript(script, ScriptOptions.builder().key(key2).arg("value2").build())
.get();
assertEquals(OK, setResponse2);
}

try (Script script = new Script("return redis.call('GET', KEYS[1])", false)) {
Object getResponse1 =
client.invokeScript(script, ScriptOptions.builder().key(key1).build()).get();
assertEquals("value1", getResponse1);

// Use GlideString in option but we still expect nonbinary output
Object getResponse2 =
client
.invokeScript(script, ScriptOptionsGlideString.builder().key(gs(key2)).build())
.get();
assertEquals("value2", getResponse2);
}
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
public void script_large_keys_and_or_args(BaseClient client) {
String str1 = "0".repeat(1 << 12); // 4k
String str2 = "0".repeat(1 << 12); // 4k

try (Script script = new Script("return KEYS[1]", false)) {
// 1 very big key
Object response =
client.invokeScript(script, ScriptOptions.builder().key(str1 + str2).build()).get();
assertEquals(str1 + str2, response);
}

try (Script script = new Script("return KEYS[1]", false)) {
// 2 big keys
Object response =
client.invokeScript(script, ScriptOptions.builder().key(str1).key(str2).build()).get();
assertEquals(str1, response);
}

try (Script script = new Script("return ARGV[1]", false)) {
// 1 very big arg
Object response =
client.invokeScript(script, ScriptOptions.builder().arg(str1 + str2).build()).get();
assertEquals(str1 + str2, response);
}

try (Script script = new Script("return ARGV[1]", false)) {
// 1 big arg + 1 big key
Object response =
client.invokeScript(script, ScriptOptions.builder().arg(str1).key(str2).build()).get();
assertEquals(str2, response);
}
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
public void invokeScript_gs_test(BaseClient client) {
GlideString key1 = gs(UUID.randomUUID().toString());
GlideString key2 = gs(UUID.randomUUID().toString());

try (Script script = new Script(gs("return 'Hello'"), true)) {
Object response = client.invokeScript(script).get();
assertEquals(gs("Hello"), response);
}

try (Script script = new Script(gs("return redis.call('SET', KEYS[1], ARGV[1])"), true)) {
Object setResponse1 =
client
.invokeScript(
script, ScriptOptionsGlideString.builder().key(key1).arg(gs("value1")).build())
.get();
assertEquals(OK, setResponse1);

Object setResponse2 =
client
.invokeScript(
script, ScriptOptionsGlideString.builder().key(key2).arg(gs("value2")).build())
.get();
assertEquals(OK, setResponse2);
}

try (Script script = new Script(gs("return redis.call('GET', KEYS[1])"), true)) {
Object getResponse1 =
client.invokeScript(script, ScriptOptionsGlideString.builder().key(key1).build()).get();
assertEquals(gs("value1"), getResponse1);

// Use String in option but we still expect binary output (GlideString)
Object getResponse2 =
client.invokeScript(script, ScriptOptions.builder().key(key2.toString()).build()).get();
assertEquals(gs("value2"), getResponse2);
}
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static glide.cluster.CommandTests.EVERYTHING_INFO_SECTIONS;
import static glide.utils.ArrayTransformUtils.concatenateArrays;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
Expand All @@ -51,8 +52,6 @@
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.scan.ScanOptions;
import glide.api.models.exceptions.RequestException;
import java.time.Instant;
Expand Down

0 comments on commit 3038c53

Please sign in to comment.