Skip to content

Commit

Permalink
Valkey-8: add BY/GET support for SORT/RO in cluster mode
Browse files Browse the repository at this point in the history
Signed-off-by: Shoham Elias <shohame@amazon.com>
  • Loading branch information
shohamazon committed Sep 12, 2024
1 parent 11da7d9 commit 4569e52
Show file tree
Hide file tree
Showing 32 changed files with 1,685 additions and 2,131 deletions.
66 changes: 66 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
import glide.api.models.commands.ScriptOptions;
import glide.api.models.commands.ScriptOptionsGlideString;
import glide.api.models.commands.SetOptions;
import glide.api.models.commands.SortOptions;
import glide.api.models.commands.SortOptionsBinary;
import glide.api.models.commands.WeightAggregateOptions.Aggregate;
import glide.api.models.commands.WeightAggregateOptions.KeyArray;
import glide.api.models.commands.WeightAggregateOptions.KeyArrayBinary;
Expand Down Expand Up @@ -4691,6 +4693,23 @@ public CompletableFuture<GlideString[]> sort(@NonNull GlideString key) {
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<String[]> sort(@NonNull String key, @NonNull SortOptions sortOptions) {
String[] arguments = ArrayUtils.addFirst(sortOptions.toArgs(), key);
return commandManager.submitNewCommand(
Sort, arguments, response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sort(
@NonNull GlideString key, @NonNull SortOptionsBinary sortOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortOptions.toArgs()).toArray();
return commandManager.submitNewCommand(
Sort,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<String[]> sortReadOnly(@NonNull String key) {
return commandManager.submitNewCommand(
Expand All @@ -4707,6 +4726,27 @@ public CompletableFuture<GlideString[]> sortReadOnly(@NonNull GlideString key) {
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<String[]> sortReadOnly(
@NonNull String key, @NonNull SortOptions sortOptions) {
String[] arguments = ArrayUtils.addFirst(sortOptions.toArgs(), key);
return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sortReadOnly(
@NonNull GlideString key, @NonNull SortOptionsBinary sortOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortOptions.toArgs()).toArray();

return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<Long> sortStore(@NonNull String key, @NonNull String destination) {
return commandManager.submitNewCommand(
Expand All @@ -4722,6 +4762,32 @@ public CompletableFuture<Long> sortStore(
this::handleLongResponse);
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull String key, @NonNull String destination, @NonNull SortOptions sortOptions) {
String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination};
String[] arguments =
concatenateArrays(new String[] {key}, sortOptions.toArgs(), storeArguments);
return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull GlideString key,
@NonNull GlideString destination,
@NonNull SortOptionsBinary sortOptions) {

GlideString[] arguments =
new ArgsBuilder()
.add(key)
.add(sortOptions.toArgs())
.add(STORE_COMMAND_STRING)
.add(destination)
.toArray();

return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<String[]> geosearch(
@NonNull String key,
Expand Down
69 changes: 0 additions & 69 deletions java/client/src/main/java/glide/api/GlideClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
import static command_request.CommandRequestOuterClass.RequestType.RandomKey;
import static command_request.CommandRequestOuterClass.RequestType.Scan;
import static command_request.CommandRequestOuterClass.RequestType.Select;
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.models.GlideString.gs;
import static glide.api.models.commands.SortBaseOptions.STORE_COMMAND_STRING;
import static glide.api.models.commands.function.FunctionListOptions.LIBRARY_NAME_VALKEY_API;
import static glide.api.models.commands.function.FunctionListOptions.WITH_CODE_VALKEY_API;
import static glide.api.models.commands.function.FunctionLoadOptions.REPLACE;
Expand All @@ -51,8 +48,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 Expand Up @@ -481,70 +476,6 @@ public CompletableFuture<GlideString> randomKeyBinary() {
RandomKey, new GlideString[0], this::handleGlideStringOrNullResponse);
}

@Override
public CompletableFuture<String[]> sort(@NonNull String key, @NonNull SortOptions sortOptions) {
String[] arguments = ArrayUtils.addFirst(sortOptions.toArgs(), key);
return commandManager.submitNewCommand(
Sort, arguments, response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sort(
@NonNull GlideString key, @NonNull SortOptionsBinary sortOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortOptions.toArgs()).toArray();
return commandManager.submitNewCommand(
Sort,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<String[]> sortReadOnly(
@NonNull String key, @NonNull SortOptions sortOptions) {
String[] arguments = ArrayUtils.addFirst(sortOptions.toArgs(), key);
return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sortReadOnly(
@NonNull GlideString key, @NonNull SortOptionsBinary sortOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortOptions.toArgs()).toArray();

return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull String key, @NonNull String destination, @NonNull SortOptions sortOptions) {
String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination};
String[] arguments =
concatenateArrays(new String[] {key}, sortOptions.toArgs(), storeArguments);
return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull GlideString key,
@NonNull GlideString destination,
@NonNull SortOptionsBinary sortOptions) {

GlideString[] arguments =
new ArgsBuilder()
.add(key)
.add(sortOptions.toArgs())
.add(STORE_COMMAND_STRING)
.add(destination)
.toArray();

return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<Object[]> scan(@NonNull String cursor) {
return commandManager.submitNewCommand(Scan, new String[] {cursor}, this::handleArrayResponse);
Expand Down
71 changes: 0 additions & 71 deletions java/client/src/main/java/glide/api/GlideClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
import static command_request.CommandRequestOuterClass.RequestType.PubSubSNumSub;
import static command_request.CommandRequestOuterClass.RequestType.RandomKey;
import static command_request.CommandRequestOuterClass.RequestType.SPublish;
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;
import static glide.api.models.GlideString.gs;
import static glide.api.models.commands.SortBaseOptions.STORE_COMMAND_STRING;
import static glide.api.models.commands.function.FunctionListOptions.LIBRARY_NAME_VALKEY_API;
import static glide.api.models.commands.function.FunctionListOptions.WITH_CODE_VALKEY_API;
import static glide.api.models.commands.function.FunctionLoadOptions.REPLACE;
Expand All @@ -57,7 +54,6 @@
import glide.api.models.GlideString;
import glide.api.models.commands.FlushMode;
import glide.api.models.commands.InfoOptions.Section;
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 All @@ -74,7 +70,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
import lombok.NonNull;
import org.apache.commons.lang3.ArrayUtils;
import response.ResponseOuterClass.Response;

/** Async (non-blocking) client for Cluster mode. Use {@link #createClient} to request a client. */
Expand Down Expand Up @@ -1130,72 +1125,6 @@ public CompletableFuture<Object[]> scanBinary(ClusterScanCursor cursor, ScanOpti
result -> new Object[] {new NativeClusterScanCursor(result[0].toString()), result[1]});
}

@Override
public CompletableFuture<String[]> sort(
@NonNull String key, @NonNull SortClusterOptions sortClusterOptions) {
String[] arguments = ArrayUtils.addFirst(sortClusterOptions.toArgs(), key);
return commandManager.submitNewCommand(
Sort, arguments, response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sort(
@NonNull GlideString key, @NonNull SortClusterOptions sortClusterOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortClusterOptions.toArgs()).toArray();

return commandManager.submitNewCommand(
Sort,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<String[]> sortReadOnly(
@NonNull String key, @NonNull SortClusterOptions sortClusterOptions) {
String[] arguments = ArrayUtils.addFirst(sortClusterOptions.toArgs(), key);
return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayResponse(response), String.class));
}

@Override
public CompletableFuture<GlideString[]> sortReadOnly(
@NonNull GlideString key, @NonNull SortClusterOptions sortClusterOptions) {
GlideString[] arguments = new ArgsBuilder().add(key).add(sortClusterOptions.toArgs()).toArray();
return commandManager.submitNewCommand(
SortReadOnly,
arguments,
response -> castArray(handleArrayOrNullResponseBinary(response), GlideString.class));
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull String key,
@NonNull String destination,
@NonNull SortClusterOptions sortClusterOptions) {
String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination};
String[] arguments =
concatenateArrays(new String[] {key}, sortClusterOptions.toArgs(), storeArguments);
return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

@Override
public CompletableFuture<Long> sortStore(
@NonNull GlideString key,
@NonNull GlideString destination,
@NonNull SortClusterOptions sortClusterOptions) {
GlideString[] arguments =
new ArgsBuilder()
.add(key)
.add(sortClusterOptions.toArgs())
.add(STORE_COMMAND_STRING)
.add(destination)
.toArray();

return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}

/** A {@link ClusterScanCursor} implementation for interacting with the Rust layer. */
private static final class NativeClusterScanCursor
implements CommandManager.ClusterScanCursorDetail {
Expand Down
Loading

0 comments on commit 4569e52

Please sign in to comment.