Skip to content

Commit

Permalink
adding script exist doc and tests
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Zhang <tj.zhang@improving.com>
  • Loading branch information
TJ Zhang committed Sep 11, 2024
1 parent 9284772 commit 2719b0b
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 281 deletions.
58 changes: 58 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import static command_request.CommandRequestOuterClass.RequestType.SScan;
import static command_request.CommandRequestOuterClass.RequestType.SUnion;
import static command_request.CommandRequestOuterClass.RequestType.SUnionStore;
import static command_request.CommandRequestOuterClass.RequestType.ScriptExists;
import static command_request.CommandRequestOuterClass.RequestType.Set;
import static command_request.CommandRequestOuterClass.RequestType.SetBit;
import static command_request.CommandRequestOuterClass.RequestType.SetRange;
Expand Down Expand Up @@ -211,6 +212,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;
Expand All @@ -223,6 +225,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;
Expand Down Expand Up @@ -276,6 +280,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;
Expand Down Expand Up @@ -5018,4 +5023,57 @@ 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);
}
}

@Override
public CompletableFuture<Boolean[]> scriptExists(@NonNull String[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}

@Override
public CompletableFuture<Boolean[]> scriptExists(@NonNull GlideString[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}
}
59 changes: 0 additions & 59 deletions java/client/src/main/java/glide/api/GlideClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static command_request.CommandRequestOuterClass.RequestType.Ping;
import static command_request.CommandRequestOuterClass.RequestType.RandomKey;
import static command_request.CommandRequestOuterClass.RequestType.Scan;
import static command_request.CommandRequestOuterClass.RequestType.ScriptExists;
import static command_request.CommandRequestOuterClass.RequestType.Select;
import static command_request.CommandRequestOuterClass.RequestType.Sort;
import static command_request.CommandRequestOuterClass.RequestType.SortReadOnly;
Expand All @@ -49,23 +48,18 @@
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;
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;
import glide.api.models.commands.scan.ScanOptions;
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 lombok.NonNull;
import org.apache.commons.lang3.ArrayUtils;

Expand Down Expand Up @@ -570,57 +564,4 @@ public CompletableFuture<Object[]> scan(
GlideString[] arguments = new ArgsBuilder().add(cursor).add(options.toArgs()).toArray();
return commandManager.submitNewCommand(Scan, arguments, this::handleArrayResponseBinary);
}

@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);
}
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull String[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull GlideString[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}
}
59 changes: 2 additions & 57 deletions java/client/src/main/java/glide/api/GlideClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import glide.api.models.Script;
import glide.api.models.commands.FlushMode;
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.ScriptOptions;
import glide.api.models.commands.ScriptOptionsGlideString;
import glide.api.models.commands.SortClusterOptions;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.commands.scan.ClusterScanCursor;
Expand Down Expand Up @@ -952,47 +950,6 @@ public CompletableFuture<String> functionKill(@NonNull Route route) {
FunctionKill, new String[0], route, this::handleStringResponse);
}

@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);
}
}

@Override
public CompletableFuture<Object> invokeScript(@NonNull Script script, Route route) {
if (script.getBinaryOutput()) {
Expand Down Expand Up @@ -1034,19 +991,7 @@ public CompletableFuture<Object> invokeScriptBinary(
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull String[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull GlideString[] sha1s) {
return commandManager.submitNewCommand(
ScriptExists, sha1s, response -> castArray(handleArrayResponse(response), Boolean.class));
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull String[] sha1s, Route route) {
public CompletableFuture<Boolean[]> scriptExists(@NonNull String[] sha1s, Route route) {
return commandManager.submitNewCommand(
ScriptExists,
sha1s,
Expand All @@ -1055,7 +1000,7 @@ public CompletableFuture<Boolean[]> scriptExist(@NonNull String[] sha1s, Route r
}

@Override
public CompletableFuture<Boolean[]> scriptExist(@NonNull GlideString[] sha1s, Route route) {
public CompletableFuture<Boolean[]> scriptExists(@NonNull GlideString[] sha1s, Route route) {
return commandManager.submitNewCommand(
ScriptExists,
sha1s,
Expand Down
Loading

0 comments on commit 2719b0b

Please sign in to comment.