From 111de9f6f7b7bf4945b16a58ca5fa60cf3f65a84 Mon Sep 17 00:00:00 2001 From: eifrah-aws Date: Mon, 1 Jul 2024 12:44:14 +0300 Subject: [PATCH] Changed the API to support binary transaction (#1731) * Changed the API to support binary transaction In addition, the following commands are modified to support it: customCommand, echo, ping, del, get, getdel, getex, set, append, mget, mset, msetnx, incr, incrBy, incrByFloat, decr, decrBy, strlen, setrange , getrange, hget, hset, hsetnx, hdel, hlen, hvals, hmget, spopCount * Temporarily disable large-values tests * ArgsBuilder now collects all arguments and returns `GlideString[]` Restored large value tests --- .../src/main/java/glide/api/RedisClient.java | 7 +- .../java/glide/api/RedisClusterClient.java | 18 +- .../java/glide/api/models/ArgsBuilder.java | 40 + .../glide/api/models/BaseTransaction.java | 894 ++++++++++-------- .../glide/api/models/ClusterTransaction.java | 32 +- .../java/glide/api/models/GlideString.java | 16 + .../java/glide/api/models/Transaction.java | 32 +- .../java/glide/managers/CommandManager.java | 6 +- .../java/glide/utils/ArrayTransformUtils.java | 26 +- 9 files changed, 630 insertions(+), 441 deletions(-) create mode 100644 java/client/src/main/java/glide/api/models/ArgsBuilder.java diff --git a/java/client/src/main/java/glide/api/RedisClient.java b/java/client/src/main/java/glide/api/RedisClient.java index 096adfe0f2..1e9fb71893 100644 --- a/java/client/src/main/java/glide/api/RedisClient.java +++ b/java/client/src/main/java/glide/api/RedisClient.java @@ -96,7 +96,12 @@ public CompletableFuture customCommand(@NonNull String[] args) { @Override public CompletableFuture exec(@NonNull Transaction transaction) { - return commandManager.submitNewTransaction(transaction, this::handleArrayOrNullResponse); + if (transaction.isBinarySafeOutput()) { + return commandManager.submitNewTransaction( + transaction, this::handleArrayOrNullResponseBinary); + } else { + return commandManager.submitNewTransaction(transaction, this::handleArrayOrNullResponse); + } } @Override diff --git a/java/client/src/main/java/glide/api/RedisClusterClient.java b/java/client/src/main/java/glide/api/RedisClusterClient.java index 92c5d3bbdd..47edacf23f 100644 --- a/java/client/src/main/java/glide/api/RedisClusterClient.java +++ b/java/client/src/main/java/glide/api/RedisClusterClient.java @@ -122,15 +122,25 @@ protected ClusterValue handleCustomCommandResponse(Route route, Response @Override public CompletableFuture exec(@NonNull ClusterTransaction transaction) { - return commandManager.submitNewTransaction( - transaction, Optional.empty(), this::handleArrayOrNullResponse); + if (transaction.isBinarySafeOutput()) { + return commandManager.submitNewTransaction( + transaction, Optional.empty(), this::handleArrayOrNullResponseBinary); + } else { + return commandManager.submitNewTransaction( + transaction, Optional.empty(), this::handleArrayOrNullResponse); + } } @Override public CompletableFuture exec( @NonNull ClusterTransaction transaction, @NonNull SingleNodeRoute route) { - return commandManager.submitNewTransaction( - transaction, Optional.of(route), this::handleArrayOrNullResponse); + if (transaction.isBinarySafeOutput()) { + return commandManager.submitNewTransaction( + transaction, Optional.of(route), this::handleArrayOrNullResponseBinary); + } else { + return commandManager.submitNewTransaction( + transaction, Optional.of(route), this::handleArrayOrNullResponse); + } } @Override diff --git a/java/client/src/main/java/glide/api/models/ArgsBuilder.java b/java/client/src/main/java/glide/api/models/ArgsBuilder.java new file mode 100644 index 0000000000..06be541bf3 --- /dev/null +++ b/java/client/src/main/java/glide/api/models/ArgsBuilder.java @@ -0,0 +1,40 @@ +/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.api.models; + +import java.util.ArrayList; + +/** + * Helper class for collecting arbitrary type of arguments and stores them as an array of + * GlideString + */ +public class ArgsBuilder { + ArrayList argumentsList = null; + + public ArgsBuilder() { + argumentsList = new ArrayList<>(); + } + + public ArgsBuilder add(ArgType[] args) { + for (ArgType arg : args) { + argumentsList.add(GlideString.of(arg)); + } + + return this; + } + + public ArgsBuilder add(ArgType arg) { + argumentsList.add(GlideString.of(arg)); + return this; + } + + public ArgsBuilder add(String[] args) { + for (String arg : args) { + argumentsList.add(GlideString.of(arg)); + } + return this; + } + + public GlideString[] toArray() { + return argumentsList.toArray(new GlideString[0]); + } +} diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index 13659f4b4c..1a3ae30312 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -24,6 +24,7 @@ import static glide.utils.ArrayTransformUtils.concatenateArrays; import static glide.utils.ArrayTransformUtils.convertMapToKeyValueStringArray; import static glide.utils.ArrayTransformUtils.convertMapToValueKeyStringArray; +import static glide.utils.ArrayTransformUtils.flattenMapToGlideStringArray; import static glide.utils.ArrayTransformUtils.mapGeoDataToArray; import static redis_request.RedisRequestOuterClass.RequestType.Append; import static redis_request.RedisRequestOuterClass.RequestType.BLMPop; @@ -206,6 +207,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.ZUnion; import static redis_request.RedisRequestOuterClass.RequestType.ZUnionStore; +import com.google.protobuf.ByteString; import glide.api.models.commands.ExpireOptions; import glide.api.models.commands.FlushMode; import glide.api.models.commands.GetExOptions; @@ -276,6 +278,7 @@ import lombok.NonNull; import org.apache.commons.lang3.ArrayUtils; import redis_request.RedisRequestOuterClass.Command; +import redis_request.RedisRequestOuterClass.Command.ArgsArray; import redis_request.RedisRequestOuterClass.RequestType; import redis_request.RedisRequestOuterClass.Transaction; @@ -295,8 +298,28 @@ public abstract class BaseTransaction> { /** Command class to send a single request to Redis. */ protected final Transaction.Builder protobufTransaction = Transaction.newBuilder(); + protected static final GlideString GLIDE_STRING = GlideString.of("gs"); + + protected static final String STRING = "string"; + + protected boolean binarySafeOutput = false; + protected abstract T getThis(); + /** Enable binary output */ + public T withBinarySafeOutput() { + binarySafeOutput = true; + return getThis(); + } + + /** + * Return true if the output array from this transaction should handle strings as valid UTF-8 + * strings or use GlideString + */ + public boolean isBinarySafeOutput() { + return this.binarySafeOutput; + } + /** * Executes a single command, without checking inputs. Every part of the command, including * subcommands, should be added as a separate value in args. @@ -312,8 +335,8 @@ public abstract class BaseTransaction> { * Object result = client.customCommand(new String[]{ "CLIENT", "LIST", "TYPE", "PUBSUB" }).get(); * } */ - public T customCommand(String[] args) { - String[] commandArgs = buildArgs(args); + public T customCommand(ArgType[] args) { + ArgsArray commandArgs = buildArgs(args); protobufTransaction.addCommands(buildCommand(CustomCommand, commandArgs)); return getThis(); } @@ -325,8 +348,8 @@ public T customCommand(String[] args) { * @param message The message to be echoed back. * @return Command Response - The provided message. */ - public T echo(@NonNull String message) { - String[] commandArgs = buildArgs(message); + public T echo(@NonNull ArgType message) { + ArgsArray commandArgs = buildArgs(message); protobufTransaction.addCommands(buildCommand(Echo, commandArgs)); return getThis(); } @@ -349,8 +372,8 @@ public T ping() { * @param msg The ping argument that will be returned. * @return Command Response - A response from Redis with a String. */ - public T ping(@NonNull String msg) { - String[] commandArgs = buildArgs(msg); + public T ping(@NonNull ArgType msg) { + ArgsArray commandArgs = buildArgs(msg); protobufTransaction.addCommands(buildCommand(Ping, commandArgs)); return getThis(); } @@ -376,7 +399,7 @@ public T info() { * @return Command Response - A String containing the requested {@link Section}s. */ public T info(@NonNull InfoOptions options) { - String[] commandArgs = buildArgs(options.toArgs()); + ArgsArray commandArgs = buildArgs(options.toArgs()); protobufTransaction.addCommands(buildCommand(Info, commandArgs)); return getThis(); } @@ -389,8 +412,8 @@ public T info(@NonNull InfoOptions options) { * @param keys The keys we wanted to remove. * @return Command Response - The number of keys that were removed. */ - public T del(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + public T del(@NonNull ArgType[] keys) { + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(Del, commandArgs)); return getThis(); } @@ -403,9 +426,8 @@ public T del(@NonNull String[] keys) { * @return Command Response - If key exists, returns the value of * key as a String. Otherwise, return null. */ - public T get(@NonNull String key) { - String[] commandArgs = buildArgs(key); - protobufTransaction.addCommands(buildCommand(Get, commandArgs)); + public T get(@NonNull ArgType key) { + protobufTransaction.addCommands(buildCommand(Get, newArgsBuilder().add(key))); return getThis(); } @@ -417,8 +439,8 @@ public T get(@NonNull String key) { * @return Command Response - If key exists, returns the value of * key. Otherwise, return null. */ - public T getdel(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T getdel(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(GetDel, commandArgs)); return getThis(); } @@ -432,8 +454,8 @@ public T getdel(@NonNull String key) { * @return Command Response - If key exists, return the value of the * key. Otherwise, return null. */ - public T getex(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T getex(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(GetEx, commandArgs)); return getThis(); } @@ -448,8 +470,8 @@ public T getex(@NonNull String key) { * @return Command Response - If key exists, return the value of the * key. Otherwise, return null. */ - public T getex(@NonNull String key, @NonNull GetExOptions options) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(options.toArgs(), key)); + public T getex(@NonNull ArgType key, @NonNull GetExOptions options) { + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(options.toArgs(), key)); protobufTransaction.addCommands(buildCommand(GetEx, commandArgs)); return getThis(); } @@ -462,9 +484,8 @@ public T getex(@NonNull String key, @NonNull GetExOptions options) { * @param value The value to store with the given key. * @return Command Response - A response from Redis. */ - public T set(@NonNull String key, @NonNull String value) { - String[] commandArgs = buildArgs(key, value); - protobufTransaction.addCommands(buildCommand(Set, commandArgs)); + public T set(@NonNull ArgType key, @NonNull ArgType value) { + protobufTransaction.addCommands(buildCommand(Set, newArgsBuilder().add(key).add(value))); return getThis(); } @@ -481,11 +502,10 @@ public T set(@NonNull String key, @NonNull String value) { * {@link ConditionalSet#ONLY_IF_DOES_NOT_EXIST} conditions, return null. * Otherwise, return OK. */ - public T set(@NonNull String key, @NonNull String value, @NonNull SetOptions options) { - String[] commandArgs = - buildArgs(ArrayUtils.addAll(new String[] {key, value}, options.toArgs())); - - protobufTransaction.addCommands(buildCommand(Set, commandArgs)); + public T set( + @NonNull ArgType key, @NonNull ArgType value, @NonNull SetOptions options) { + protobufTransaction.addCommands( + buildCommand(Set, newArgsBuilder().add(key).add(value).add(options.toArgs()))); return getThis(); } @@ -499,8 +519,8 @@ public T set(@NonNull String key, @NonNull String value, @NonNull SetOptions opt * @param value The value to append. * @return Command Response - The length of the string after appending the value. */ - public T append(@NonNull String key, @NonNull String value) { - String[] commandArgs = buildArgs(key, value); + public T append(@NonNull ArgType key, @NonNull ArgType value) { + ArgsArray commandArgs = buildArgs(key, value); protobufTransaction.addCommands(buildCommand(Append, commandArgs)); return getThis(); } @@ -515,8 +535,8 @@ public T append(@NonNull String key, @NonNull String value) { * If a keyis not found, its corresponding value in the list will be null * . */ - public T mget(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + public T mget(@NonNull ArgType[] keys) { + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(MGet, commandArgs)); return getThis(); } @@ -528,9 +548,9 @@ public T mget(@NonNull String[] keys) { * @param keyValueMap A key-value map consisting of keys and their respective values to set. * @return Command Response - Always OK. */ - public T mset(@NonNull Map keyValueMap) { - String[] args = convertMapToKeyValueStringArray(keyValueMap); - String[] commandArgs = buildArgs(args); + public T mset(@NonNull Map keyValueMap) { + GlideString[] args = flattenMapToGlideStringArray(keyValueMap); + ArgsArray commandArgs = buildArgs(args); protobufTransaction.addCommands(buildCommand(MSet, commandArgs)); return getThis(); @@ -545,9 +565,9 @@ public T mset(@NonNull Map keyValueMap) { * @return Command Response - true if all keys were set, false if no key * was set. */ - public T msetnx(@NonNull Map keyValueMap) { - String[] args = convertMapToKeyValueStringArray(keyValueMap); - String[] commandArgs = buildArgs(args); + public T msetnx(@NonNull Map keyValueMap) { + GlideString[] args = flattenMapToGlideStringArray(keyValueMap); + ArgsArray commandArgs = buildArgs(args); protobufTransaction.addCommands(buildCommand(MSetNX, commandArgs)); return getThis(); @@ -561,8 +581,8 @@ public T msetnx(@NonNull Map keyValueMap) { * @param key The key to increment its value. * @return Command Response - The value of key after the increment. */ - public T incr(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T incr(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Incr, commandArgs)); return getThis(); } @@ -576,8 +596,8 @@ public T incr(@NonNull String key) { * @param amount The amount to increment. * @return Command Response - The value of key after the increment. */ - public T incrBy(@NonNull String key, long amount) { - String[] commandArgs = buildArgs(key, Long.toString(amount)); + public T incrBy(@NonNull ArgType key, long amount) { + ArgsArray commandArgs = buildArgs(key, this.convertTo(key.getClass(), amount)); protobufTransaction.addCommands(buildCommand(IncrBy, commandArgs)); return getThis(); } @@ -593,8 +613,8 @@ public T incrBy(@NonNull String key, long amount) { * @param amount The amount to increment. * @return Command Response - The value of key after the increment. */ - public T incrByFloat(@NonNull String key, double amount) { - String[] commandArgs = buildArgs(key, Double.toString(amount)); + public T incrByFloat(@NonNull ArgType key, double amount) { + ArgsArray commandArgs = buildArgs(key, this.convertTo(key.getClass(), amount)); protobufTransaction.addCommands(buildCommand(IncrByFloat, commandArgs)); return getThis(); } @@ -607,8 +627,8 @@ public T incrByFloat(@NonNull String key, double amount) { * @param key The key to decrement its value. * @return Command Response - The value of key after the decrement. */ - public T decr(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T decr(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Decr, commandArgs)); return getThis(); } @@ -622,8 +642,8 @@ public T decr(@NonNull String key) { * @param amount The amount to decrement. * @return Command Response - The value of key after the decrement. */ - public T decrBy(@NonNull String key, long amount) { - String[] commandArgs = buildArgs(key, Long.toString(amount)); + public T decrBy(@NonNull ArgType key, long amount) { + ArgsArray commandArgs = buildArgs(key, this.convertTo(key.getClass(), amount)); protobufTransaction.addCommands(buildCommand(DecrBy, commandArgs)); return getThis(); } @@ -637,8 +657,8 @@ public T decrBy(@NonNull String key, long amount) { * If key does not exist, it is treated as an empty string, and the command * returns 0. */ - public T strlen(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T strlen(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Strlen, commandArgs)); return getThis(); } @@ -657,8 +677,8 @@ public T strlen(@NonNull String key) { * @return Command Response - The length of the string stored at key after it was * modified. */ - public T setrange(@NonNull String key, int offset, @NonNull String value) { - String[] commandArgs = buildArgs(key, Integer.toString(offset), value); + public T setrange(@NonNull ArgType key, int offset, @NonNull ArgType value) { + ArgsArray commandArgs = buildArgs(key, this.convertTo(key.getClass(), offset), value); protobufTransaction.addCommands(buildCommand(SetRange, commandArgs)); return getThis(); } @@ -675,8 +695,9 @@ public T setrange(@NonNull String key, int offset, @NonNull String value) { * @param end The ending offset. * @return Command Response - A substring extracted from the value stored at key. */ - public T getrange(@NonNull String key, int start, int end) { - String[] commandArgs = buildArgs(key, Integer.toString(start), Integer.toString(end)); + public T getrange(@NonNull ArgType key, int start, int end) { + ArgsArray commandArgs = + buildArgs(key, this.convertTo(key.getClass(), start), this.convertTo(key.getClass(), end)); protobufTransaction.addCommands(buildCommand(GetRange, commandArgs)); return getThis(); } @@ -690,8 +711,8 @@ public T getrange(@NonNull String key, int start, int end) { * @return Command Response - The value associated with field, or null * when field is not present in the hash or key does not exist. */ - public T hget(@NonNull String key, @NonNull String field) { - String[] commandArgs = buildArgs(key, field); + public T hget(@NonNull ArgType key, @NonNull ArgType field) { + ArgsArray commandArgs = buildArgs(key, field); protobufTransaction.addCommands(buildCommand(HGet, commandArgs)); return getThis(); } @@ -705,9 +726,12 @@ public T hget(@NonNull String key, @NonNull String field) { * be set in the hash stored at the specified key. * @return Command Response - The number of fields that were added. */ - public T hset(@NonNull String key, @NonNull Map fieldValueMap) { - String[] commandArgs = - buildArgs(ArrayUtils.addFirst(convertMapToKeyValueStringArray(fieldValueMap), key)); + public T hset(@NonNull ArgType key, @NonNull Map fieldValueMap) { + ArgsArray commandArgs = + buildArgs( + ArrayUtils.addFirst( + flattenMapToGlideStringArray(fieldValueMap), + this.convertTo(GlideString.class, key))); protobufTransaction.addCommands(buildCommand(HSet, commandArgs)); return getThis(); @@ -726,8 +750,8 @@ public T hset(@NonNull String key, @NonNull Map fieldValueMap) { * @return Command Response - true if the field was set, false if the * field already existed and was not set. */ - public T hsetnx(@NonNull String key, @NonNull String field, @NonNull String value) { - String[] commandArgs = buildArgs(key, field, value); + public T hsetnx(@NonNull ArgType key, @NonNull ArgType field, @NonNull ArgType value) { + ArgsArray commandArgs = buildArgs(key, field, value); protobufTransaction.addCommands(buildCommand(HSetNX, commandArgs)); return getThis(); } @@ -743,8 +767,8 @@ public T hsetnx(@NonNull String key, @NonNull String field, @NonNull String valu * specified but non-existing fields.
* If key does not exist, it is treated as an empty hash and it returns 0.
*/ - public T hdel(@NonNull String key, @NonNull String[] fields) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(fields, key)); + public T hdel(@NonNull ArgType key, @NonNull ArgType[] fields) { + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(fields, key)); protobufTransaction.addCommands(buildCommand(HDel, commandArgs)); return getThis(); } @@ -758,8 +782,8 @@ public T hdel(@NonNull String key, @NonNull String[] fields) { * does not exist.
* If key holds a value that is not a hash, an error is returned. */ - public T hlen(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T hlen(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(HLen, commandArgs)); return getThis(); } @@ -772,8 +796,8 @@ public T hlen(@NonNull String key) { * @return Command Response - An array of values in the hash, or an empty array * when the key does not exist. */ - public T hvals(@NonNull String key) { - String[] commandArgs = buildArgs(key); + public T hvals(@NonNull ArgType key) { + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(HVals, commandArgs)); return getThis(); } @@ -790,8 +814,8 @@ public T hvals(@NonNull String key) { * If key does not exist, it is treated as an empty hash, and it returns an array * of null values.
*/ - public T hmget(@NonNull String key, @NonNull String[] fields) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(fields, key)); + public T hmget(@NonNull ArgType key, @NonNull ArgType[] fields) { + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(fields, key)); protobufTransaction.addCommands(buildCommand(HMGet, commandArgs)); return getThis(); } @@ -807,7 +831,7 @@ public T hmget(@NonNull String key, @NonNull String[] fields) { * . */ public T hexists(@NonNull String key, @NonNull String field) { - String[] commandArgs = buildArgs(key, field); + ArgsArray commandArgs = buildArgs(key, field); protobufTransaction.addCommands(buildCommand(HExists, commandArgs)); return getThis(); } @@ -822,7 +846,7 @@ public T hexists(@NonNull String key, @NonNull String field) { * If key does not exist, it returns an empty map. */ public T hgetall(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(HGetAll, commandArgs)); return getThis(); } @@ -843,7 +867,7 @@ public T hgetall(@NonNull String key) { * after the increment or decrement. */ public T hincrBy(@NonNull String key, @NonNull String field, long amount) { - String[] commandArgs = buildArgs(key, field, Long.toString(amount)); + ArgsArray commandArgs = buildArgs(key, field, Long.toString(amount)); protobufTransaction.addCommands(buildCommand(HIncrBy, commandArgs)); return getThis(); } @@ -865,7 +889,7 @@ public T hincrBy(@NonNull String key, @NonNull String field, long amount) { * after the increment or decrement. */ public T hincrByFloat(@NonNull String key, @NonNull String field, double amount) { - String[] commandArgs = buildArgs(key, field, Double.toString(amount)); + ArgsArray commandArgs = buildArgs(key, field, Double.toString(amount)); protobufTransaction.addCommands(buildCommand(HIncrByFloat, commandArgs)); return getThis(); } @@ -946,7 +970,7 @@ public T hrandfieldWithCount(@NonNull String key, long count) { * If the hash does not exist or is empty, the response will be an empty array. */ public T hrandfieldWithCountWithValues(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count), WITH_VALUES_REDIS_API); + ArgsArray commandArgs = buildArgs(key, Long.toString(count), WITH_VALUES_REDIS_API); protobufTransaction.addCommands(buildCommand(HRandField, commandArgs)); return getThis(); } @@ -963,7 +987,7 @@ public T hrandfieldWithCountWithValues(@NonNull String key, long count) { * @return Command Response - The length of the list after the push operations. */ public T lpush(@NonNull String key, @NonNull String[] elements) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); protobufTransaction.addCommands(buildCommand(LPush, commandArgs)); return getThis(); } @@ -978,7 +1002,7 @@ public T lpush(@NonNull String key, @NonNull String[] elements) { * If key does not exist, null will be returned. */ public T lpop(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(LPop, commandArgs)); return getThis(); } @@ -995,7 +1019,7 @@ public T lpop(@NonNull String key) { * null if element is not in the list. */ public T lpos(@NonNull String key, @NonNull String element) { - String[] commandArgs = buildArgs(key, element); + ArgsArray commandArgs = buildArgs(key, element); protobufTransaction.addCommands(buildCommand(LPos, commandArgs)); return getThis(); } @@ -1013,7 +1037,7 @@ public T lpos(@NonNull String key, @NonNull String element) { * element is not in the list. */ public T lpos(@NonNull String key, @NonNull String element, @NonNull LPosOptions options) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(ArrayUtils.addAll(new String[] {key, element}, options.toArgs())); protobufTransaction.addCommands(buildCommand(LPos, commandArgs)); return getThis(); @@ -1031,7 +1055,7 @@ public T lpos(@NonNull String key, @NonNull String element, @NonNull LPosOptions * elements within the list. */ public T lposCount(@NonNull String key, @NonNull String element, long count) { - String[] commandArgs = buildArgs(key, element, COUNT_REDIS_API, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, element, COUNT_REDIS_API, Long.toString(count)); protobufTransaction.addCommands(buildCommand(LPos, commandArgs)); return getThis(); } @@ -1051,7 +1075,7 @@ public T lposCount(@NonNull String key, @NonNull String element, long count) { */ public T lposCount( @NonNull String key, @NonNull String element, long count, @NonNull LPosOptions options) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( ArrayUtils.addAll( new String[] {key, element, COUNT_REDIS_API, Long.toString(count)}, @@ -1072,7 +1096,7 @@ public T lposCount( * If key does not exist, null will be returned. */ public T lpopCount(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(LPop, commandArgs)); return getThis(); } @@ -1097,7 +1121,7 @@ public T lpopCount(@NonNull String key, long count) { * If key does not exist an empty array will be returned. */ public T lrange(@NonNull String key, long start, long end) { - String[] commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); + ArgsArray commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); protobufTransaction.addCommands(buildCommand(LRange, commandArgs)); return getThis(); } @@ -1118,7 +1142,7 @@ public T lrange(@NonNull String key, long start, long end) { * is returned. */ public T lindex(@NonNull String key, long index) { - String[] commandArgs = buildArgs(key, Long.toString(index)); + ArgsArray commandArgs = buildArgs(key, Long.toString(index)); protobufTransaction.addCommands(buildCommand(LIndex, commandArgs)); return getThis(); @@ -1145,7 +1169,7 @@ public T lindex(@NonNull String key, long index) { * If key does not exist, OK will be returned without changes to the database. */ public T ltrim(@NonNull String key, long start, long end) { - String[] commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); + ArgsArray commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); protobufTransaction.addCommands(buildCommand(LTrim, commandArgs)); return getThis(); } @@ -1160,7 +1184,7 @@ public T ltrim(@NonNull String key, long start, long end) { * is returned. */ public T llen(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(LLen, commandArgs)); return getThis(); @@ -1184,7 +1208,7 @@ public T llen(@NonNull String key) { * If key does not exist, 0 is returned. */ public T lrem(@NonNull String key, long count, @NonNull String element) { - String[] commandArgs = buildArgs(key, Long.toString(count), element); + ArgsArray commandArgs = buildArgs(key, Long.toString(count), element); protobufTransaction.addCommands(buildCommand(LRem, commandArgs)); return getThis(); } @@ -1201,7 +1225,7 @@ public T lrem(@NonNull String key, long count, @NonNull String element) { * @return Command Response - The length of the list after the push operations. */ public T rpush(@NonNull String key, @NonNull String[] elements) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); protobufTransaction.addCommands(buildCommand(RPush, commandArgs)); return getThis(); } @@ -1216,7 +1240,7 @@ public T rpush(@NonNull String key, @NonNull String[] elements) { * If key does not exist, null will be returned. */ public T rpop(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(RPop, commandArgs)); return getThis(); } @@ -1232,7 +1256,7 @@ public T rpop(@NonNull String key) { * If key does not exist, null will be returned. */ public T rpopCount(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(RPop, commandArgs)); return getThis(); } @@ -1250,7 +1274,7 @@ public T rpopCount(@NonNull String key, long count) { * . */ public T sadd(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(SAdd, commandArgs)); return getThis(); } @@ -1266,7 +1290,7 @@ public T sadd(@NonNull String key, @NonNull String[] members) { * and the command returns false. */ public T sismember(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member); + ArgsArray commandArgs = buildArgs(key, member); protobufTransaction.addCommands(buildCommand(SIsMember, commandArgs)); return getThis(); } @@ -1284,7 +1308,7 @@ public T sismember(@NonNull String key, @NonNull String member) { * returns 0. */ public T srem(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(SRem, commandArgs)); return getThis(); } @@ -1298,7 +1322,7 @@ public T srem(@NonNull String key, @NonNull String[] members) { * @remarks If key does not exist an empty set will be returned. */ public T smembers(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(SMembers, commandArgs)); return getThis(); } @@ -1312,7 +1336,7 @@ public T smembers(@NonNull String key) { * does not exist. */ public T scard(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(SCard, commandArgs)); return getThis(); } @@ -1327,7 +1351,7 @@ public T scard(@NonNull String key) { * If the a key does not exist, it is treated as an empty set. */ public T sdiff(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(SDiff, commandArgs)); return getThis(); } @@ -1342,7 +1366,7 @@ public T sdiff(@NonNull String[] keys) { * indicating if the respective member exists in the set. */ public T smismember(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(SMIsMember, commandArgs)); return getThis(); } @@ -1357,7 +1381,7 @@ public T smismember(@NonNull String key, @NonNull String[] members) { * @return Command Response - The number of elements in the resulting set. */ public T sdiffstore(@NonNull String destination, @NonNull String[] keys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); protobufTransaction.addCommands(buildCommand(SDiffStore, commandArgs)); return getThis(); } @@ -1375,7 +1399,7 @@ public T sdiffstore(@NonNull String destination, @NonNull String[] keys) { * source set does not exist or the element is not a member of the source set. */ public T smove(@NonNull String source, @NonNull String destination, @NonNull String member) { - String[] commandArgs = buildArgs(source, destination, member); + ArgsArray commandArgs = buildArgs(source, destination, member); protobufTransaction.addCommands(buildCommand(SMove, commandArgs)); return getThis(); } @@ -1390,7 +1414,7 @@ public T smove(@NonNull String source, @NonNull String destination, @NonNull Str * Missing or empty input sets cause an empty response. */ public T sinter(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(SInter, commandArgs)); return getThis(); } @@ -1405,7 +1429,7 @@ public T sinter(@NonNull String[] keys) { * @return Command Response - The number of elements in the resulting set. */ public T sinterstore(@NonNull String destination, @NonNull String[] keys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); protobufTransaction.addCommands(buildCommand(SInterStore, commandArgs)); return getThis(); } @@ -1420,7 +1444,7 @@ public T sinterstore(@NonNull String destination, @NonNull String[] keys) { * not exist, 0 is returned. */ public T sintercard(@NonNull String[] keys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(concatenateArrays(new String[] {Long.toString(keys.length)}, keys)); protobufTransaction.addCommands(buildCommand(SInterCard, commandArgs)); return getThis(); @@ -1438,7 +1462,7 @@ public T sintercard(@NonNull String[] keys) { * partway through the computation, returns limit as the cardinality. */ public T sintercard(@NonNull String[] keys, long limit) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Long.toString(keys.length)}, @@ -1458,7 +1482,7 @@ public T sintercard(@NonNull String[] keys, long limit) { * @return Command Response - The number of elements in the resulting set. */ public T sunionstore(@NonNull String destination, @NonNull String[] keys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(keys, destination)); protobufTransaction.addCommands(buildCommand(SUnionStore, commandArgs)); return getThis(); } @@ -1473,7 +1497,7 @@ public T sunionstore(@NonNull String destination, @NonNull String[] keys) { * parameters. */ public T configGet(@NonNull String[] parameters) { - String[] commandArgs = buildArgs(parameters); + ArgsArray commandArgs = buildArgs(parameters); protobufTransaction.addCommands(buildCommand(ConfigGet, commandArgs)); return getThis(); } @@ -1488,7 +1512,7 @@ public T configGet(@NonNull String[] parameters) { * Otherwise, the transaction fails with an error. */ public T configSet(@NonNull Map parameters) { - String[] commandArgs = buildArgs(convertMapToKeyValueStringArray(parameters)); + ArgsArray commandArgs = buildArgs(convertMapToKeyValueStringArray(parameters)); protobufTransaction.addCommands(buildCommand(ConfigSet, commandArgs)); return getThis(); } @@ -1502,7 +1526,7 @@ public T configSet(@NonNull Map parameters) { * in keys multiple times, it will be counted multiple times. */ public T exists(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(Exists, commandArgs)); return getThis(); } @@ -1518,7 +1542,7 @@ public T exists(@NonNull String[] keys) { * @return Command Response - The number of keys that were unlinked. */ public T unlink(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(Unlink, commandArgs)); return getThis(); } @@ -1540,7 +1564,7 @@ public T unlink(@NonNull String[] keys) { * timeout was not set. e.g. key doesn't exist. */ public T expire(@NonNull String key, long seconds) { - String[] commandArgs = buildArgs(key, Long.toString(seconds)); + ArgsArray commandArgs = buildArgs(key, Long.toString(seconds)); protobufTransaction.addCommands(buildCommand(Expire, commandArgs)); return getThis(); } @@ -1564,7 +1588,7 @@ public T expire(@NonNull String key, long seconds) { * provided arguments. */ public T expire(@NonNull String key, long seconds, @NonNull ExpireOptions expireOptions) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( ArrayUtils.addAll(new String[] {key, Long.toString(seconds)}, expireOptions.toArgs())); @@ -1589,7 +1613,7 @@ public T expire(@NonNull String key, long seconds, @NonNull ExpireOptions expire * timeout was not set. e.g. key doesn't exist. */ public T expireAt(@NonNull String key, long unixSeconds) { - String[] commandArgs = buildArgs(key, Long.toString(unixSeconds)); + ArgsArray commandArgs = buildArgs(key, Long.toString(unixSeconds)); protobufTransaction.addCommands(buildCommand(ExpireAt, commandArgs)); return getThis(); } @@ -1613,7 +1637,7 @@ public T expireAt(@NonNull String key, long unixSeconds) { * provided arguments. */ public T expireAt(@NonNull String key, long unixSeconds, @NonNull ExpireOptions expireOptions) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( ArrayUtils.addAll( new String[] {key, Long.toString(unixSeconds)}, expireOptions.toArgs())); @@ -1639,7 +1663,7 @@ public T expireAt(@NonNull String key, long unixSeconds, @NonNull ExpireOptions * timeout was not set. e.g. key doesn't exist. */ public T pexpire(@NonNull String key, long milliseconds) { - String[] commandArgs = buildArgs(key, Long.toString(milliseconds)); + ArgsArray commandArgs = buildArgs(key, Long.toString(milliseconds)); protobufTransaction.addCommands(buildCommand(PExpire, commandArgs)); return getThis(); } @@ -1663,7 +1687,7 @@ public T pexpire(@NonNull String key, long milliseconds) { * provided arguments. */ public T pexpire(@NonNull String key, long milliseconds, @NonNull ExpireOptions expireOptions) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( ArrayUtils.addAll( new String[] {key, Long.toString(milliseconds)}, expireOptions.toArgs())); @@ -1689,7 +1713,7 @@ public T pexpire(@NonNull String key, long milliseconds, @NonNull ExpireOptions * timeout was not set. e.g. key doesn't exist. */ public T pexpireAt(@NonNull String key, long unixMilliseconds) { - String[] commandArgs = buildArgs(key, Long.toString(unixMilliseconds)); + ArgsArray commandArgs = buildArgs(key, Long.toString(unixMilliseconds)); protobufTransaction.addCommands(buildCommand(PExpireAt, commandArgs)); return getThis(); @@ -1715,7 +1739,7 @@ public T pexpireAt(@NonNull String key, long unixMilliseconds) { */ public T pexpireAt( @NonNull String key, long unixMilliseconds, @NonNull ExpireOptions expireOptions) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( ArrayUtils.addAll( new String[] {key, Long.toString(unixMilliseconds)}, expireOptions.toArgs())); @@ -1733,7 +1757,7 @@ public T pexpireAt( * or -1 if key exists but has no associated expire. */ public T ttl(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(TTL, commandArgs)); return getThis(); @@ -1845,7 +1869,7 @@ public T zadd( String[] arguments = concatenateArrays(new String[] {key}, options.toArgs(), changedArg, membersScores); - String[] commandArgs = buildArgs(arguments); + ArgsArray commandArgs = buildArgs(arguments); protobufTransaction.addCommands(buildCommand(ZAdd, commandArgs)); return getThis(); @@ -1918,7 +1942,7 @@ public T zadd(@NonNull String key, @NonNull Map membersScoresMap */ public T zaddIncr( @NonNull String key, @NonNull String member, double increment, @NonNull ZAddOptions options) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {key}, @@ -1960,7 +1984,7 @@ public T zaddIncr(@NonNull String key, @NonNull String member, double increment) * returns 0. */ public T zrem(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(ZRem, commandArgs)); return getThis(); } @@ -1975,7 +1999,7 @@ public T zrem(@NonNull String key, @NonNull String[] members) { * return 0. */ public T zcard(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ZCard, commandArgs)); return getThis(); } @@ -1995,7 +2019,7 @@ public T zcard(@NonNull String key) { * command returns an empty Map. */ public T zpopmin(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(ZPopMin, commandArgs)); return getThis(); } @@ -2011,7 +2035,7 @@ public T zpopmin(@NonNull String key, long count) { * command returns an empty Map. */ public T zpopmin(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ZPopMin, commandArgs)); return getThis(); } @@ -2026,7 +2050,7 @@ public T zpopmin(@NonNull String key) { * If the sorted set does not exist or is empty, the response will be null. */ public T zrandmember(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ZRandMember, commandArgs)); return getThis(); } @@ -2044,7 +2068,7 @@ public T zrandmember(@NonNull String key) { * . */ public T zrandmemberWithCount(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(ZRandMember, commandArgs)); return getThis(); } @@ -2066,7 +2090,7 @@ public T zrandmemberWithCount(@NonNull String key, long count) { public T zrandmemberWithCountWithScores(String key, long count) { String[] arguments = new String[] {key, Long.toString(count), WITH_SCORES_REDIS_API}; - String[] commandArgs = buildArgs(arguments); + ArgsArray commandArgs = buildArgs(arguments); protobufTransaction.addCommands(buildCommand(ZRandMember, commandArgs)); return getThis(); } @@ -2085,7 +2109,7 @@ public T zrandmemberWithCountWithScores(String key, long count) { * @return Command Response - The new score of member. */ public T zincrby(@NonNull String key, double increment, @NonNull String member) { - String[] commandArgs = buildArgs(key, Double.toString(increment), member); + ArgsArray commandArgs = buildArgs(key, Double.toString(increment), member); protobufTransaction.addCommands(buildCommand(ZIncrBy, commandArgs)); return getThis(); } @@ -2109,7 +2133,7 @@ public T zincrby(@NonNull String key, double increment, @NonNull String member) * . */ public T bzpopmin(@NonNull String[] keys, double timeout) { - String[] commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); + ArgsArray commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); protobufTransaction.addCommands(buildCommand(BZPopMin, commandArgs)); return getThis(); } @@ -2129,7 +2153,7 @@ public T bzpopmin(@NonNull String[] keys, double timeout) { * command returns an empty Map. */ public T zpopmax(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(ZPopMax, commandArgs)); return getThis(); } @@ -2145,7 +2169,7 @@ public T zpopmax(@NonNull String key, long count) { * command returns an empty Map. */ public T zpopmax(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ZPopMax, commandArgs)); return getThis(); } @@ -2169,7 +2193,7 @@ public T zpopmax(@NonNull String key) { * . */ public T bzpopmax(@NonNull String[] keys, double timeout) { - String[] commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); + ArgsArray commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); protobufTransaction.addCommands(buildCommand(BZPopMax, commandArgs)); return getThis(); } @@ -2185,7 +2209,7 @@ public T bzpopmax(@NonNull String[] keys, double timeout) { * If key does not exist, null is returned. */ public T zscore(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member); + ArgsArray commandArgs = buildArgs(key, member); protobufTransaction.addCommands(buildCommand(ZScore, commandArgs)); return getThis(); } @@ -2203,7 +2227,7 @@ public T zscore(@NonNull String key, @NonNull String member) { * null will be returned. */ public T zrank(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member); + ArgsArray commandArgs = buildArgs(key, member); protobufTransaction.addCommands(buildCommand(ZRank, commandArgs)); return getThis(); } @@ -2221,7 +2245,7 @@ public T zrank(@NonNull String key, @NonNull String member) { * null will be returned. */ public T zrankWithScore(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member, WITH_SCORE_REDIS_API); + ArgsArray commandArgs = buildArgs(key, member, WITH_SCORE_REDIS_API); protobufTransaction.addCommands(buildCommand(ZRank, commandArgs)); return getThis(); } @@ -2240,7 +2264,7 @@ public T zrankWithScore(@NonNull String key, @NonNull String member) { * null will be returned. */ public T zrevrank(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member); + ArgsArray commandArgs = buildArgs(key, member); protobufTransaction.addCommands(buildCommand(ZRevRank, commandArgs)); return getThis(); } @@ -2259,7 +2283,7 @@ public T zrevrank(@NonNull String key, @NonNull String member) { * null will be returned. */ public T zrevrankWithScore(@NonNull String key, @NonNull String member) { - String[] commandArgs = buildArgs(key, member, WITH_SCORE_REDIS_API); + ArgsArray commandArgs = buildArgs(key, member, WITH_SCORE_REDIS_API); protobufTransaction.addCommands(buildCommand(ZRevRank, commandArgs)); return getThis(); } @@ -2276,7 +2300,7 @@ public T zrevrankWithScore(@NonNull String key, @NonNull String member) { * will be null. */ public T zmscore(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(ZMScore, commandArgs)); return getThis(); } @@ -2294,7 +2318,7 @@ public T zmscore(@NonNull String key, @NonNull String[] members) { * command returns an empty array. */ public T zdiff(@NonNull String[] keys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(keys, Long.toString(keys.length))); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(keys, Long.toString(keys.length))); protobufTransaction.addCommands(buildCommand(ZDiff, commandArgs)); return getThis(); } @@ -2313,7 +2337,7 @@ public T zdiff(@NonNull String[] keys) { public T zdiffWithScores(@NonNull String[] keys) { String[] arguments = ArrayUtils.addFirst(keys, Long.toString(keys.length)); arguments = ArrayUtils.add(arguments, WITH_SCORES_REDIS_API); - String[] commandArgs = buildArgs(arguments); + ArgsArray commandArgs = buildArgs(arguments); protobufTransaction.addCommands(buildCommand(ZDiff, commandArgs)); return getThis(); } @@ -2331,7 +2355,7 @@ public T zdiffWithScores(@NonNull String[] keys) { * destination. */ public T zdiffstore(@NonNull String destination, @NonNull String[] keys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(ArrayUtils.addAll(new String[] {destination, Long.toString(keys.length)}, keys)); protobufTransaction.addCommands(buildCommand(ZDiffStore, commandArgs)); return getThis(); @@ -2355,7 +2379,7 @@ public T zdiffstore(@NonNull String destination, @NonNull String[] keys) { * If maxScore < minScore, 0 is returned. */ public T zcount(@NonNull String key, @NonNull ScoreRange minScore, @NonNull ScoreRange maxScore) { - String[] commandArgs = buildArgs(key, minScore.toArgs(), maxScore.toArgs()); + ArgsArray commandArgs = buildArgs(key, minScore.toArgs(), maxScore.toArgs()); protobufTransaction.addCommands(buildCommand(ZCount, commandArgs)); return getThis(); } @@ -2378,7 +2402,7 @@ public T zcount(@NonNull String key, @NonNull ScoreRange minScore, @NonNull Scor * If key does not exist 0 will be returned. */ public T zremrangebyrank(@NonNull String key, long start, long end) { - String[] commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); + ArgsArray commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); protobufTransaction.addCommands(buildCommand(ZRemRangeByRank, commandArgs)); return getThis(); } @@ -2407,7 +2431,7 @@ public T zrangestore( @NonNull String source, @NonNull RangeQuery rangeQuery, boolean reverse) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(RangeOptions.createZRangeStoreArgs(destination, source, rangeQuery, reverse)); protobufTransaction.addCommands(buildCommand(ZRangeStore, commandArgs)); return getThis(); @@ -2453,7 +2477,7 @@ public T zrangestore( * If minLex is greater than maxLex, 0 is returned. */ public T zremrangebylex(@NonNull String key, @NonNull LexRange minLex, @NonNull LexRange maxLex) { - String[] commandArgs = buildArgs(key, minLex.toArgs(), maxLex.toArgs()); + ArgsArray commandArgs = buildArgs(key, minLex.toArgs(), maxLex.toArgs()); protobufTransaction.addCommands(buildCommand(ZRemRangeByLex, commandArgs)); return getThis(); } @@ -2477,7 +2501,7 @@ public T zremrangebylex(@NonNull String key, @NonNull LexRange minLex, @NonNull */ public T zremrangebyscore( @NonNull String key, @NonNull ScoreRange minScore, @NonNull ScoreRange maxScore) { - String[] commandArgs = buildArgs(key, minScore.toArgs(), maxScore.toArgs()); + ArgsArray commandArgs = buildArgs(key, minScore.toArgs(), maxScore.toArgs()); protobufTransaction.addCommands(buildCommand(ZRemRangeByScore, commandArgs)); return getThis(); } @@ -2500,7 +2524,7 @@ public T zremrangebyscore( * If maxLex < minLex, 0 is returned. */ public T zlexcount(@NonNull String key, @NonNull LexRange minLex, @NonNull LexRange maxLex) { - String[] commandArgs = buildArgs(key, minLex.toArgs(), maxLex.toArgs()); + ArgsArray commandArgs = buildArgs(key, minLex.toArgs(), maxLex.toArgs()); protobufTransaction.addCommands(buildCommand(ZLexCount, commandArgs)); return getThis(); } @@ -2528,7 +2552,7 @@ public T zunionstore( @NonNull String destination, @NonNull KeysOrWeightedKeys keysOrWeightedKeys, @NonNull Aggregate aggregate) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {destination}, keysOrWeightedKeys.toArgs(), aggregate.toArgs())); @@ -2554,7 +2578,7 @@ public T zunionstore( */ public T zunionstore( @NonNull String destination, @NonNull KeysOrWeightedKeys keysOrWeightedKeys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(concatenateArrays(new String[] {destination}, keysOrWeightedKeys.toArgs())); protobufTransaction.addCommands(buildCommand(ZUnionStore, commandArgs)); return getThis(); @@ -2583,7 +2607,7 @@ public T zinterstore( @NonNull String destination, @NonNull KeysOrWeightedKeys keysOrWeightedKeys, @NonNull Aggregate aggregate) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {destination}, keysOrWeightedKeys.toArgs(), aggregate.toArgs())); @@ -2600,7 +2624,7 @@ public T zinterstore( * @return Command Response - The cardinality of the intersection of the given sorted sets. */ public T zintercard(@NonNull String[] keys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(keys, Integer.toString(keys.length))); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(keys, Integer.toString(keys.length))); protobufTransaction.addCommands(buildCommand(ZInterCard, commandArgs)); return getThis(); } @@ -2619,7 +2643,7 @@ public T zintercard(@NonNull String[] keys) { * limit if reached. */ public T zintercard(@NonNull String[] keys, long limit) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Integer.toString(keys.length)}, @@ -2649,7 +2673,7 @@ public T zintercard(@NonNull String[] keys, long limit) { */ public T zinterstore( @NonNull String destination, @NonNull KeysOrWeightedKeys keysOrWeightedKeys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(concatenateArrays(new String[] {destination}, keysOrWeightedKeys.toArgs())); protobufTransaction.addCommands(buildCommand(ZInterStore, commandArgs)); return getThis(); @@ -2665,7 +2689,7 @@ public T zinterstore( * @return Command Response - The resulting sorted set from the union. */ public T zunion(@NonNull KeyArray keys) { - String[] commandArgs = buildArgs(keys.toArgs()); + ArgsArray commandArgs = buildArgs(keys.toArgs()); protobufTransaction.addCommands(buildCommand(ZUnion, commandArgs)); return getThis(); } @@ -2688,7 +2712,7 @@ public T zunion(@NonNull KeyArray keys) { */ public T zunionWithScores( @NonNull KeysOrWeightedKeys keysOrWeightedKeys, @NonNull Aggregate aggregate) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( keysOrWeightedKeys.toArgs(), @@ -2715,7 +2739,7 @@ public T zunionWithScores( * @return Command Response - The resulting sorted set from the union. */ public T zunionWithScores(@NonNull KeysOrWeightedKeys keysOrWeightedKeys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays(keysOrWeightedKeys.toArgs(), new String[] {WITH_SCORES_REDIS_API})); protobufTransaction.addCommands(buildCommand(ZUnion, commandArgs)); @@ -2733,7 +2757,7 @@ public T zunionWithScores(@NonNull KeysOrWeightedKeys keysOrWeightedKeys) { * @return Command Response - The resulting sorted set from the intersection. */ public T zinter(@NonNull KeyArray keys) { - String[] commandArgs = buildArgs(keys.toArgs()); + ArgsArray commandArgs = buildArgs(keys.toArgs()); protobufTransaction.addCommands(buildCommand(ZInter, commandArgs)); return getThis(); } @@ -2754,7 +2778,7 @@ public T zinter(@NonNull KeyArray keys) { * @return Command Response - The resulting sorted set from the intersection. */ public T zinterWithScores(@NonNull KeysOrWeightedKeys keysOrWeightedKeys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays(keysOrWeightedKeys.toArgs(), new String[] {WITH_SCORES_REDIS_API})); protobufTransaction.addCommands(buildCommand(ZInter, commandArgs)); @@ -2779,7 +2803,7 @@ public T zinterWithScores(@NonNull KeysOrWeightedKeys keysOrWeightedKeys) { */ public T zinterWithScores( @NonNull KeysOrWeightedKeys keysOrWeightedKeys, @NonNull Aggregate aggregate) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( keysOrWeightedKeys.toArgs(), @@ -2819,7 +2843,7 @@ public T xadd( String[] arguments = ArrayUtils.addAll( ArrayUtils.addFirst(options.toArgs(), key), convertMapToKeyValueStringArray(values)); - String[] commandArgs = buildArgs(arguments); + ArgsArray commandArgs = buildArgs(arguments); protobufTransaction.addCommands(buildCommand(XAdd, commandArgs)); return getThis(); } @@ -2863,7 +2887,7 @@ public T xread(@NonNull Map keysAndIds, @NonNull StreamReadOptio * @return Command Response - The number of entries deleted from the stream. */ public T xtrim(@NonNull String key, @NonNull StreamTrimOptions options) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(options.toArgs(), key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(options.toArgs(), key)); protobufTransaction.addCommands(buildCommand(XTrim, commandArgs)); return getThis(); } @@ -2892,7 +2916,7 @@ public T xlen(@NonNull String key) { * don't exist in the stream. */ public T xdel(@NonNull String key, @NonNull String[] ids) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(ids, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(ids, key)); protobufTransaction.addCommands(buildCommand(XDel, commandArgs)); return getThis(); } @@ -2904,24 +2928,24 @@ public T xdel(@NonNull String key, @NonNull String[] ids) { * @param key The key of the stream. * @param start Starting stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MIN} to start with the minimum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MIN} to start with the minimum available ID. *
* * @param end Ending stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MAX} to end with the maximum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MAX} to end with the maximum available ID. *
* * @return Command Response - A Map of key to stream entry data, where entry data is an array of pairings with format [[field, entry], [field, entry], ...]. */ public T xrange(@NonNull String key, @NonNull StreamRange start, @NonNull StreamRange end) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(start, end), key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(start, end), key)); protobufTransaction.addCommands(buildCommand(XRange, commandArgs)); return getThis(); } @@ -2933,18 +2957,18 @@ public T xrange(@NonNull String key, @NonNull StreamRange start, @NonNull Stream * @param key The key of the stream. * @param start Starting stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MIN} to start with the minimum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MIN} to start with the minimum available ID. *
* * @param end Ending stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MAX} to end with the maximum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MAX} to end with the maximum available ID. *
* * @param count Maximum count of stream entries to return. @@ -2952,7 +2976,7 @@ public T xrange(@NonNull String key, @NonNull StreamRange start, @NonNull Stream */ public T xrange( @NonNull String key, @NonNull StreamRange start, @NonNull StreamRange end, long count) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(start, end, count), key)); protobufTransaction.addCommands(buildCommand(XRange, commandArgs)); return getThis(); @@ -2967,24 +2991,24 @@ public T xrange( * @param key The key of the stream. * @param end Ending stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MAX} to end with the maximum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MAX} to end with the maximum available ID. *
* * @param start Starting stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MIN} to start with the minimum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MIN} to start with the minimum available ID. *
* * @return Command Response - A Map of key to stream entry data, where entry data is an array of pairings with format [[field, entry], [field, entry], ...]. */ public T xrevrange(@NonNull String key, @NonNull StreamRange end, @NonNull StreamRange start) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(end, start), key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(end, start), key)); protobufTransaction.addCommands(buildCommand(XRevRange, commandArgs)); return getThis(); } @@ -2998,18 +3022,18 @@ public T xrevrange(@NonNull String key, @NonNull StreamRange end, @NonNull Strea * @param key The key of the stream. * @param start Starting stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MIN} to start with the minimum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MIN} to start with the minimum available ID. *
* * @param end Ending stream ID bound for range. *
    - *
  • Use {@link IdBound#of} to specify a stream ID. - *
  • Use {@link IdBound#ofExclusive} to specify an exclusive bounded stream + *
  • Use {@link StreamRange.IdBound#of} to specify a stream ID. + *
  • Use {@link StreamRange.IdBound#ofExclusive} to specify an exclusive bounded stream * ID. - *
  • Use {@link InfRangeBound#MAX} to end with the maximum available ID. + *
  • Use {@link StreamRange.InfRangeBound#MAX} to end with the maximum available ID. *
* * @param count Maximum count of stream entries to return. @@ -3017,7 +3041,7 @@ public T xrevrange(@NonNull String key, @NonNull StreamRange end, @NonNull Strea */ public T xrevrange( @NonNull String key, @NonNull StreamRange end, @NonNull StreamRange start, long count) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(StreamRange.toArgs(end, start, count), key)); protobufTransaction.addCommands(buildCommand(XRevRange, commandArgs)); return getThis(); @@ -3053,14 +3077,14 @@ public T xgroupCreate(@NonNull String key, @NonNull String groupName, @NonNull S * @param options The group options {@link StreamGroupOptions}. * @return Command Response - OK. */ - public T xgroupCreate( - @NonNull String key, - @NonNull String groupName, - @NonNull String id, + public T xgroupCreate( + @NonNull ArgType key, + @NonNull ArgType groupName, + @NonNull ArgType id, @NonNull StreamGroupOptions options) { - String[] commandArgs = - buildArgs(concatenateArrays(new String[] {key, groupName, id}, options.toArgs())); - protobufTransaction.addCommands(buildCommand(XGroupCreate, commandArgs)); + protobufTransaction.addCommands( + buildCommand( + XGroupCreate, newArgsBuilder().add(key).add(groupName).add(id).add(options.toArgs()))); return getThis(); } @@ -3069,7 +3093,7 @@ public T xgroupCreate( * * @see valkey.io for details. * @param key The key of the stream. - * @param groupname The consumer group name to delete. + * @param groupname The newly created consumer group name. * @return Command Response - true if the consumer group is destroyed. Otherwise, * false. */ @@ -3102,7 +3126,7 @@ public T xgroupCreateConsumer( * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name. - * @param consumer The consumer to delete. + * @param consumer The newly created consumer. * @return Command Response - The number of pending messages the consumer had before * it was deleted. */ @@ -3141,13 +3165,20 @@ public T xgroupSetId(@NonNull String key, @NonNull String groupName, @NonNull St * it) and the stream's last entry. * @return Command Response - OK. */ - public T xgroupSetId( - @NonNull String key, - @NonNull String groupName, - @NonNull String id, - @NonNull String entriesReadId) { - String[] commandArgs = buildArgs(key, groupName, id, "ENTRIESREAD", entriesReadId); - protobufTransaction.addCommands(buildCommand(XGroupSetId, commandArgs)); + public T xgroupSetId( + @NonNull ArgType key, + @NonNull ArgType groupName, + @NonNull ArgType id, + @NonNull ArgType entriesReadId) { + protobufTransaction.addCommands( + buildCommand( + XGroupSetId, + newArgsBuilder() + .add(key) + .add(groupName) + .add(id) + .add("ENTRIESREAD") + .add(entriesReadId))); return getThis(); } @@ -3162,11 +3193,12 @@ public T xgroupSetId( * will be read. Use the special id of {@literal Map>} * to receive only new messages. * @param group The consumer group name. - * @param consumer The consumer name. + * @param consumer The newly created consumer. * @return Command Response - A {@literal Map>} with * stream keys, to Map of stream-ids, to an array of pairings with format * [[field, entry], [field, entry], ...]. - * Returns null if there is no stream that can be served. + * Returns null if the consumer group does not exist. Returns a Map + * with a value of code>null if the stream is empty. */ public T xreadgroup( @NonNull Map keysAndIds, @NonNull String group, @NonNull String consumer) { @@ -3184,12 +3216,13 @@ public T xreadgroup( * will be read. Use the special id of {@literal Map>} * to receive only new messages. * @param group The consumer group name. - * @param consumer The consumer name. + * @param consumer The newly created consumer. * @param options Options detailing how to read the stream {@link StreamReadGroupOptions}. * @return Command Response - A {@literal Map>} with * stream keys, to Map of stream-ids, to an array of pairings with format * [[field, entry], [field, entry], ...]. - * Returns null if the {@link StreamReadGroupOptions#block} option is given and a timeout occurs, or if there is no stream that can be served. + * Returns null if the consumer group does not exist. Returns a Map + * with a value of code>null if the stream is empty. */ public T xreadgroup( @NonNull Map keysAndIds, @@ -3206,7 +3239,6 @@ public T xreadgroup( * of a stream. This command should be called on a pending message so that such message does not * get processed again. * - * @see valkey.io for details. * @param key The key of the stream. * @param group The consumer group name. * @param ids Stream entry ID to acknowledge and purge messages. @@ -3450,7 +3482,7 @@ public T xclaimJustId( * exist, -1 if key exists but has no associated expire. */ public T pttl(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(PTTL, commandArgs)); return getThis(); } @@ -3466,7 +3498,7 @@ public T pttl(@NonNull String key) { * have an associated timeout, true if the timeout has been removed. */ public T persist(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Persist, commandArgs)); return getThis(); } @@ -3589,7 +3621,7 @@ public T lolwut(int @NonNull [] parameters) { * version. */ public T lolwut(int version) { - String[] commandArgs = buildArgs(VERSION_REDIS_API, Integer.toString(version)); + ArgsArray commandArgs = buildArgs(VERSION_REDIS_API, Integer.toString(version)); protobufTransaction.addCommands(buildCommand(Lolwut, commandArgs)); return getThis(); } @@ -3639,7 +3671,7 @@ public T dbsize() { * returned. Otherwise, a "none" string is returned. */ public T type(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Type, commandArgs)); return getThis(); } @@ -3666,7 +3698,7 @@ public T randomKey() { * . If key does not exist, the transaction fails with an error. */ public T rename(@NonNull String key, @NonNull String newKey) { - String[] commandArgs = buildArgs(key, newKey); + ArgsArray commandArgs = buildArgs(key, newKey); protobufTransaction.addCommands(buildCommand(Rename, commandArgs)); return getThis(); } @@ -3681,7 +3713,7 @@ public T rename(@NonNull String key, @NonNull String newKey) { * , false if newKey already exists. */ public T renamenx(@NonNull String key, @NonNull String newKey) { - String[] commandArgs = buildArgs(key, newKey); + ArgsArray commandArgs = buildArgs(key, newKey); protobufTransaction.addCommands(buildCommand(RenameNX, commandArgs)); return getThis(); } @@ -3705,7 +3737,7 @@ public T linsert( @NonNull InsertPosition position, @NonNull String pivot, @NonNull String element) { - String[] commandArgs = buildArgs(key, position.toString(), pivot, element); + ArgsArray commandArgs = buildArgs(key, position.toString(), pivot, element); protobufTransaction.addCommands(buildCommand(LInsert, commandArgs)); return getThis(); } @@ -3729,7 +3761,7 @@ public T linsert( * null. */ public T brpop(@NonNull String[] keys, double timeout) { - String[] commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); + ArgsArray commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); protobufTransaction.addCommands(buildCommand(BRPop, commandArgs)); return getThis(); } @@ -3745,7 +3777,7 @@ public T brpop(@NonNull String[] keys, double timeout) { * @return Command Response - The length of the list after the push operation. */ public T lpushx(@NonNull String key, @NonNull String[] elements) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); protobufTransaction.addCommands(buildCommand(LPushX, commandArgs)); return getThis(); } @@ -3761,7 +3793,7 @@ public T lpushx(@NonNull String key, @NonNull String[] elements) { * @return Command Response - The length of the list after the push operation. */ public T rpushx(@NonNull String key, @NonNull String[] elements) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); protobufTransaction.addCommands(buildCommand(RPushX, commandArgs)); return getThis(); } @@ -3785,7 +3817,7 @@ public T rpushx(@NonNull String key, @NonNull String[] elements) { * null. */ public T blpop(@NonNull String[] keys, double timeout) { - String[] commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); + ArgsArray commandArgs = buildArgs(ArrayUtils.add(keys, Double.toString(timeout))); protobufTransaction.addCommands(buildCommand(BLPop, commandArgs)); return getThis(); } @@ -3812,7 +3844,7 @@ public T blpop(@NonNull String[] keys, double timeout) { * array. */ public T zrange(@NonNull String key, @NonNull RangeQuery rangeQuery, boolean reverse) { - String[] commandArgs = buildArgs(createZRangeArgs(key, rangeQuery, reverse, false)); + ArgsArray commandArgs = buildArgs(createZRangeArgs(key, rangeQuery, reverse, false)); protobufTransaction.addCommands(buildCommand(ZRange, commandArgs)); return getThis(); } @@ -3860,7 +3892,7 @@ public T zrange(@NonNull String key, @NonNull RangeQuery rangeQuery) { */ public T zrangeWithScores( @NonNull String key, @NonNull ScoredRangeQuery rangeQuery, boolean reverse) { - String[] commandArgs = buildArgs(createZRangeArgs(key, rangeQuery, reverse, true)); + ArgsArray commandArgs = buildArgs(createZRangeArgs(key, rangeQuery, reverse, true)); protobufTransaction.addCommands(buildCommand(ZRange, commandArgs)); return getThis(); } @@ -3900,7 +3932,7 @@ public T zrangeWithScores(@NonNull String key, @NonNull ScoredRangeQuery rangeQu * If no member could be popped, returns null. */ public T zmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Integer.toString(keys.length)}, @@ -3926,7 +3958,7 @@ public T zmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier) { * If no member could be popped, returns null. */ public T zmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier, long count) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Integer.toString(keys.length)}, @@ -3957,7 +3989,7 @@ public T zmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier, long count * If no member could be popped and the timeout expired, returns null. */ public T bzmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier, double timeout) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Double.toString(timeout), Integer.toString(keys.length)}, @@ -3991,7 +4023,7 @@ public T bzmpop(@NonNull String[] keys, @NonNull ScoreFilter modifier, double ti */ public T bzmpop( @NonNull String[] keys, @NonNull ScoreFilter modifier, double timeout, long count) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Double.toString(timeout), Integer.toString(keys.length)}, @@ -4018,7 +4050,7 @@ public T bzmpop( * 0. */ public T pfadd(@NonNull String key, @NonNull String[] elements) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(elements, key)); protobufTransaction.addCommands(buildCommand(PfAdd, commandArgs)); return getThis(); } @@ -4034,7 +4066,7 @@ public T pfadd(@NonNull String key, @NonNull String[] elements) { * The cardinality of a key that does not exist is 0. */ public T pfcount(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(PfCount, commandArgs)); return getThis(); } @@ -4051,7 +4083,7 @@ public T pfcount(@NonNull String[] keys) { * @return Command Response - OK. */ public T pfmerge(@NonNull String destination, @NonNull String[] sourceKeys) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(sourceKeys, destination)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(sourceKeys, destination)); protobufTransaction.addCommands(buildCommand(PfMerge, commandArgs)); return getThis(); } @@ -4066,7 +4098,7 @@ public T pfmerge(@NonNull String destination, @NonNull String[] sourceKeys) { * . */ public T objectEncoding(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ObjectEncoding, commandArgs)); return getThis(); } @@ -4082,7 +4114,7 @@ public T objectEncoding(@NonNull String key) { * null. */ public T objectFreq(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ObjectFreq, commandArgs)); return getThis(); } @@ -4096,7 +4128,7 @@ public T objectFreq(@NonNull String key) { * Otherwise, returns null. */ public T objectIdletime(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ObjectIdleTime, commandArgs)); return getThis(); } @@ -4111,7 +4143,7 @@ public T objectIdletime(@NonNull String key) { * . */ public T objectRefcount(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(ObjectRefCount, commandArgs)); return getThis(); } @@ -4124,7 +4156,7 @@ public T objectRefcount(@NonNull String key) { * @return Command Response - The number of keys that were updated. */ public T touch(@NonNull String[] keys) { - String[] commandArgs = buildArgs(keys); + ArgsArray commandArgs = buildArgs(keys); protobufTransaction.addCommands(buildCommand(Touch, commandArgs)); return getThis(); } @@ -4147,7 +4179,7 @@ public T copy(@NonNull String source, @NonNull String destination, boolean repla if (replace) { args = ArrayUtils.add(args, REPLACE_REDIS_API); } - String[] commandArgs = buildArgs(args); + ArgsArray commandArgs = buildArgs(args); protobufTransaction.addCommands(buildCommand(Copy, commandArgs)); return getThis(); } @@ -4176,7 +4208,7 @@ public T copy(@NonNull String source, @NonNull String destination) { * missing as it is treated as an empty string. */ public T bitcount(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(BitCount, commandArgs)); return getThis(); } @@ -4198,7 +4230,7 @@ public T bitcount(@NonNull String key) { * treated as an empty string. */ public T bitcount(@NonNull String key, long start, long end) { - String[] commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); + ArgsArray commandArgs = buildArgs(key, Long.toString(start), Long.toString(end)); protobufTransaction.addCommands(buildCommand(BitCount, commandArgs)); return getThis(); @@ -4224,7 +4256,7 @@ public T bitcount(@NonNull String key, long start, long end) { * missing as it is treated as an empty string. */ public T bitcount(@NonNull String key, long start, long end, @NonNull BitmapIndexType options) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(key, Long.toString(start), Long.toString(end), options.toString()); protobufTransaction.addCommands(buildCommand(BitCount, commandArgs)); @@ -4250,7 +4282,7 @@ public T geoadd( @NonNull String key, @NonNull Map membersToGeospatialData, @NonNull GeoAddOptions options) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {key}, options.toArgs(), mapGeoDataToArray(membersToGeospatialData))); @@ -4289,7 +4321,7 @@ public T geoadd( * be null. */ public T geopos(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(GeoPos, commandArgs)); return getThis(); } @@ -4306,12 +4338,13 @@ public T geopos(@NonNull String key, @NonNull String[] members) { * @return Command Response - The distance between member1 and member2. * If one or both members do not exist or if the key does not exist returns null. */ - public T geodist( - @NonNull String key, - @NonNull String member1, - @NonNull String member2, + public T geodist( + @NonNull ArgType key, + @NonNull ArgType member1, + @NonNull ArgType member2, @NonNull GeoUnit geoUnit) { - String[] commandArgs = buildArgs(key, member1, member2, geoUnit.getValkeyAPI()); + ArgsArray commandArgs = + buildArgs(key, member1, member2, this.convertTo(key.getClass(), geoUnit.getValkeyAPI())); protobufTransaction.addCommands(buildCommand(GeoDist, commandArgs)); return getThis(); } @@ -4329,7 +4362,7 @@ public T geodist( * The default unit is {@see GeoUnit#METERS}. */ public T geodist(@NonNull String key, @NonNull String member1, @NonNull String member2) { - String[] commandArgs = buildArgs(key, member1, member2); + ArgsArray commandArgs = buildArgs(key, member1, member2); protobufTransaction.addCommands(buildCommand(GeoDist, commandArgs)); return getThis(); } @@ -4346,7 +4379,7 @@ public T geodist(@NonNull String key, @NonNull String member1, @NonNull String m * sorted set, a null value is returned for that member. */ public T geohash(@NonNull String key, @NonNull String[] members) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(members, key)); protobufTransaction.addCommands(buildCommand(GeoHash, commandArgs)); return getThis(); } @@ -4362,7 +4395,7 @@ public T geohash(@NonNull String key, @NonNull String[] members) { * @return Command Response - The library name that was loaded. */ public T functionLoad(@NonNull String libraryCode, boolean replace) { - String[] commandArgs = + ArgsArray commandArgs = replace ? buildArgs(REPLACE.toString(), libraryCode) : buildArgs(libraryCode); protobufTransaction.addCommands(buildCommand(FunctionLoad, commandArgs)); return getThis(); @@ -4377,7 +4410,7 @@ public T functionLoad(@NonNull String libraryCode, boolean replace) { * @return Command Response - Info about all libraries and their functions. */ public T functionList(boolean withCode) { - String[] commandArgs = withCode ? buildArgs(WITH_CODE_REDIS_API) : buildArgs(); + ArgsArray commandArgs = withCode ? buildArgs(WITH_CODE_REDIS_API) : emptyArgs(); protobufTransaction.addCommands(buildCommand(FunctionList, commandArgs)); return getThis(); } @@ -4392,7 +4425,7 @@ public T functionList(boolean withCode) { * @return Command Response - Info about queried libraries and their functions. */ public T functionList(@NonNull String libNamePattern, boolean withCode) { - String[] commandArgs = + ArgsArray commandArgs = withCode ? buildArgs(LIBRARY_NAME_REDIS_API, libNamePattern, WITH_CODE_REDIS_API) : buildArgs(LIBRARY_NAME_REDIS_API, libNamePattern); @@ -4414,7 +4447,7 @@ public T functionList(@NonNull String libNamePattern, boolean withCode) { * @return Command Response - The invoked function's return value. */ public T fcall(@NonNull String function, @NonNull String[] keys, @NonNull String[] arguments) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {function, Long.toString(keys.length)}, keys, arguments)); @@ -4451,7 +4484,7 @@ public T fcall(@NonNull String function, @NonNull String[] arguments) { */ public T fcallReadOnly( @NonNull String function, @NonNull String[] keys, @NonNull String[] arguments) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {function, Long.toString(keys.length)}, keys, arguments)); @@ -4506,7 +4539,7 @@ public T functionStats() { * @return Command Response - The bit value that was previously stored at offset. */ public T setbit(@NonNull String key, long offset, long value) { - String[] commandArgs = buildArgs(key, Long.toString(offset), Long.toString(value)); + ArgsArray commandArgs = buildArgs(key, Long.toString(offset), Long.toString(value)); protobufTransaction.addCommands(buildCommand(SetBit, commandArgs)); return getThis(); } @@ -4522,7 +4555,7 @@ public T setbit(@NonNull String key, long offset, long value) { * if the positive offset exceeds the length of the string. */ public T getbit(@NonNull String key, long offset) { - String[] commandArgs = buildArgs(key, Long.toString(offset)); + ArgsArray commandArgs = buildArgs(key, Long.toString(offset)); protobufTransaction.addCommands(buildCommand(GetBit, commandArgs)); return getThis(); } @@ -4552,7 +4585,7 @@ public T blmpop( @NonNull ListDirection direction, @NonNull Long count, double timeout) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Double.toString(timeout), Long.toString(keys.length)}, @@ -4584,7 +4617,7 @@ public T blmpop( * If no member could be popped and the timeout expired, returns null. */ public T blmpop(@NonNull String[] keys, @NonNull ListDirection direction, double timeout) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Double.toString(timeout), Long.toString(keys.length)}, @@ -4605,7 +4638,7 @@ public T blmpop(@NonNull String[] keys, @NonNull ListDirection direction, double * a -1 is returned. */ public T bitpos(@NonNull String key, long bit) { - String[] commandArgs = buildArgs(key, Long.toString(bit)); + ArgsArray commandArgs = buildArgs(key, Long.toString(bit)); protobufTransaction.addCommands(buildCommand(BitPos, commandArgs)); return getThis(); } @@ -4626,7 +4659,7 @@ public T bitpos(@NonNull String key, long bit) { * . If bit is not found, a -1 is returned. */ public T bitpos(@NonNull String key, long bit, long start) { - String[] commandArgs = buildArgs(key, Long.toString(bit), Long.toString(start)); + ArgsArray commandArgs = buildArgs(key, Long.toString(bit), Long.toString(start)); protobufTransaction.addCommands(buildCommand(BitPos, commandArgs)); return getThis(); } @@ -4648,7 +4681,7 @@ public T bitpos(@NonNull String key, long bit, long start) { * at key. If bit is not found, a -1 is returned. */ public T bitpos(@NonNull String key, long bit, long start, long end) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(key, Long.toString(bit), Long.toString(start), Long.toString(end)); protobufTransaction.addCommands(buildCommand(BitPos, commandArgs)); return getThis(); @@ -4678,7 +4711,7 @@ public T bitpos(@NonNull String key, long bit, long start, long end) { */ public T bitpos( @NonNull String key, long bit, long start, long end, @NonNull BitmapIndexType offsetType) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( key, Long.toString(bit), @@ -4704,7 +4737,7 @@ public T bitop( @NonNull BitwiseOperation bitwiseOperation, @NonNull String destination, @NonNull String[] keys) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs(concatenateArrays(new String[] {bitwiseOperation.toString(), destination}, keys)); protobufTransaction.addCommands(buildCommand(BitOp, commandArgs)); @@ -4725,7 +4758,7 @@ public T bitop( * elements. */ public T lmpop(@NonNull String[] keys, @NonNull ListDirection direction, @NonNull Long count) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Long.toString(keys.length)}, @@ -4749,7 +4782,7 @@ public T lmpop(@NonNull String[] keys, @NonNull ListDirection direction, @NonNul * popped element. */ public T lmpop(@NonNull String[] keys, @NonNull ListDirection direction) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( concatenateArrays( new String[] {Long.toString(keys.length)}, @@ -4772,7 +4805,7 @@ public T lmpop(@NonNull String[] keys, @NonNull ListDirection direction) { * @return Command Response - OK. */ public T lset(@NonNull String key, long index, @NonNull String element) { - String[] commandArgs = buildArgs(key, Long.toString(index), element); + ArgsArray commandArgs = buildArgs(key, Long.toString(index), element); protobufTransaction.addCommands(buildCommand(LSet, commandArgs)); return getThis(); } @@ -4796,7 +4829,8 @@ public T lmove( @NonNull String destination, @NonNull ListDirection wherefrom, @NonNull ListDirection whereto) { - String[] commandArgs = buildArgs(source, destination, wherefrom.toString(), whereto.toString()); + ArgsArray commandArgs = + buildArgs(source, destination, wherefrom.toString(), whereto.toString()); protobufTransaction.addCommands(buildCommand(LMove, commandArgs)); return getThis(); } @@ -4829,7 +4863,7 @@ public T blmove( @NonNull ListDirection wherefrom, @NonNull ListDirection whereto, double timeout) { - String[] commandArgs = + ArgsArray commandArgs = buildArgs( source, destination, @@ -4849,7 +4883,7 @@ public T blmove( * does not exist. */ public T srandmember(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(SRandMember, commandArgs)); return getThis(); } @@ -4866,7 +4900,7 @@ public T srandmember(@NonNull String key) { * array if key does not exist. */ public T srandmember(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + ArgsArray commandArgs = buildArgs(key, Long.toString(count)); protobufTransaction.addCommands(buildCommand(SRandMember, commandArgs)); return getThis(); } @@ -4880,7 +4914,7 @@ public T srandmember(@NonNull String key, long count) { * If key does not exist, null will be returned. */ public T spop(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(SPop, commandArgs)); return getThis(); } @@ -4896,8 +4930,8 @@ public T spop(@NonNull String key) { * length.
* If key does not exist, an empty Set will be returned. */ - public T spopCount(@NonNull String key, long count) { - String[] commandArgs = buildArgs(key, Long.toString(count)); + public T spopCount(@NonNull ArgType key, long count) { + ArgsArray commandArgs = buildArgs(key, this.convertTo(key.getClass(), count)); protobufTransaction.addCommands(buildCommand(SPop, commandArgs)); return getThis(); } @@ -4930,7 +4964,7 @@ public T spopCount(@NonNull String key, long count) { * */ public T bitfield(@NonNull String key, @NonNull BitFieldSubCommands[] subCommands) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(createBitFieldArgs(subCommands), key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(createBitFieldArgs(subCommands), key)); protobufTransaction.addCommands(buildCommand(BitField, commandArgs)); return getThis(); } @@ -4948,7 +4982,7 @@ public T bitfield(@NonNull String key, @NonNull BitFieldSubCommands[] subCommand */ public T bitfieldReadOnly( @NonNull String key, @NonNull BitFieldReadOnlySubCommands[] subCommands) { - String[] commandArgs = buildArgs(ArrayUtils.addFirst(createBitFieldArgs(subCommands), key)); + ArgsArray commandArgs = buildArgs(ArrayUtils.addFirst(createBitFieldArgs(subCommands), key)); protobufTransaction.addCommands(buildCommand(BitFieldReadOnly, commandArgs)); return getThis(); } @@ -5022,7 +5056,7 @@ public T lcs(@NonNull String key1, @NonNull String key2) { * @return Command Response - The length of the longest common subsequence between the 2 strings. */ public T lcsLen(@NonNull String key1, @NonNull String key2) { - String[] args = buildArgs(key1, key2, LEN_REDIS_API); + ArgsArray args = buildArgs(key1, key2, LEN_REDIS_API); protobufTransaction.addCommands(buildCommand(LCS, args)); return getThis(); } @@ -5092,9 +5126,9 @@ public T sunion(@NonNull String[] keys) { * "bcd" in key1 at index 1 to 3 which matches * the substring in key2 at index 0 to 2. */ - public T lcsIdx(@NonNull String key1, @NonNull String key2) { - String[] args = buildArgs(key1, key2, IDX_COMMAND_STRING); - protobufTransaction.addCommands(buildCommand(LCS, args)); + public T lcsIdx(@NonNull ArgType key1, @NonNull ArgType key2) { + protobufTransaction.addCommands( + buildCommand(LCS, newArgsBuilder().add(key1).add(key2).add(IDX_COMMAND_STRING))); return getThis(); } @@ -5138,15 +5172,16 @@ public T lcsIdx(@NonNull String key1, @NonNull String key2) { * "bcd" in key1 at index 1 to 3 which matches * the substring in key2 at index 0 to 2. */ - public T lcsIdx(@NonNull String key1, @NonNull String key2, long minMatchLen) { - String[] args = - buildArgs( - key1, - key2, - IDX_COMMAND_STRING, - MINMATCHLEN_COMMAND_STRING, - String.valueOf(minMatchLen)); - protobufTransaction.addCommands(buildCommand(LCS, args)); + public T lcsIdx(@NonNull ArgType key1, @NonNull ArgType key2, long minMatchLen) { + protobufTransaction.addCommands( + buildCommand( + LCS, + newArgsBuilder() + .add(key1) + .add(key2) + .add(IDX_COMMAND_STRING) + .add(MINMATCHLEN_COMMAND_STRING) + .add(minMatchLen))); return getThis(); } @@ -5191,9 +5226,15 @@ public T lcsIdx(@NonNull String key1, @NonNull String key2, long minMatchLen) { * matches the substring in key2 at index 0 to 2 and * the last element in the array is the length of the substring match which is 3. */ - public T lcsIdxWithMatchLen(@NonNull String key1, @NonNull String key2) { - String[] args = buildArgs(key1, key2, IDX_COMMAND_STRING, WITHMATCHLEN_COMMAND_STRING); - protobufTransaction.addCommands(buildCommand(LCS, args)); + public T lcsIdxWithMatchLen(@NonNull ArgType key1, @NonNull ArgType key2) { + protobufTransaction.addCommands( + buildCommand( + LCS, + newArgsBuilder() + .add(key1) + .add(key2) + .add(IDX_COMMAND_STRING) + .add(WITHMATCHLEN_COMMAND_STRING))); return getThis(); } @@ -5239,16 +5280,18 @@ public T lcsIdxWithMatchLen(@NonNull String key1, @NonNull String key2) { * matches the substring in key2 at index 0 to 2 and * the last element in the array is the length of the substring match which is 3. */ - public T lcsIdxWithMatchLen(@NonNull String key1, @NonNull String key2, long minMatchLen) { - String[] args = - buildArgs( - key1, - key2, - IDX_COMMAND_STRING, - MINMATCHLEN_COMMAND_STRING, - String.valueOf(minMatchLen), - WITHMATCHLEN_COMMAND_STRING); - protobufTransaction.addCommands(buildCommand(LCS, args)); + public T lcsIdxWithMatchLen( + @NonNull ArgType key1, @NonNull ArgType key2, long minMatchLen) { + protobufTransaction.addCommands( + buildCommand( + LCS, + newArgsBuilder() + .add(key1) + .add(key2) + .add(IDX_COMMAND_STRING) + .add(MINMATCHLEN_COMMAND_STRING) + .add(minMatchLen) + .add(WITHMATCHLEN_COMMAND_STRING))); return getThis(); } @@ -5263,7 +5306,7 @@ public T lcsIdxWithMatchLen(@NonNull String key1, @NonNull String key2, long min * @return Command Response - An Array of sorted elements. */ public T sort(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(Sort, commandArgs)); return getThis(); } @@ -5279,7 +5322,7 @@ public T sort(@NonNull String key) { * @return Command Response - An Array of sorted elements. */ public T sortReadOnly(@NonNull String key) { - String[] commandArgs = buildArgs(key); + ArgsArray commandArgs = buildArgs(key); protobufTransaction.addCommands(buildCommand(SortReadOnly, commandArgs)); return getThis(); } @@ -5297,9 +5340,9 @@ public T sortReadOnly(@NonNull String key) { * @return Command Response - The number of elements in the sorted key stored at destination * . */ - public T sortStore(@NonNull String key, @NonNull String destination) { - String[] commandArgs = buildArgs(new String[] {key, STORE_COMMAND_STRING, destination}); - protobufTransaction.addCommands(buildCommand(Sort, commandArgs)); + public T sortStore(@NonNull ArgType key, @NonNull ArgType destination) { + protobufTransaction.addCommands( + buildCommand(Sort, newArgsBuilder().add(key).add(STORE_COMMAND_STRING).add(destination))); return getThis(); } @@ -5328,13 +5371,13 @@ public T sortStore(@NonNull String key, @NonNull String destination) { * * @return Command Response - An array of matched member names. */ - public T geosearch( - @NonNull String key, + public T geosearch( + @NonNull ArgType key, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy) { - String[] args = - buildArgs(concatenateArrays(new String[] {key}, searchFrom.toArgs(), searchBy.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearch, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearch, newArgsBuilder().add(key).add(searchFrom.toArgs()).add(searchBy.toArgs()))); return getThis(); } @@ -5365,19 +5408,19 @@ public T geosearch( * GeoSearchResultOptions} * @return Command Response - An array of matched member names. */ - public T geosearch( - @NonNull String key, + public T geosearch( + @NonNull ArgType key, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchResultOptions resultOptions) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {key}, - searchFrom.toArgs(), - searchBy.toArgs(), - resultOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearch, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearch, + newArgsBuilder() + .add(key) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(resultOptions.toArgs()))); return getThis(); } @@ -5415,16 +5458,19 @@ public T geosearch( *
  • The coordinates as a two item array of Double. * */ - public T geosearch( - @NonNull String key, + public T geosearch( + @NonNull ArgType key, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchOptions options) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {key}, searchFrom.toArgs(), searchBy.toArgs(), options.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearch, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearch, + newArgsBuilder() + .add(key) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(options.toArgs()))); return getThis(); } @@ -5464,21 +5510,21 @@ public T geosearch( *
  • The coordinates as a two item array of Double. * */ - public T geosearch( - @NonNull String key, + public T geosearch( + @NonNull ArgType key, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchOptions options, @NonNull GeoSearchResultOptions resultOptions) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {key}, - searchFrom.toArgs(), - searchBy.toArgs(), - options.toArgs(), - resultOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearch, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearch, + newArgsBuilder() + .add(key) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(options.toArgs()) + .add(resultOptions.toArgs()))); return getThis(); } @@ -5511,16 +5557,19 @@ public T geosearch( * * @return Command Response - The number of elements in the resulting set. */ - public T geosearchstore( - @NonNull String destination, - @NonNull String source, + public T geosearchstore( + @NonNull ArgType destination, + @NonNull ArgType source, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {destination, source}, searchFrom.toArgs(), searchBy.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearchStore, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearchStore, + newArgsBuilder() + .add(destination) + .add(source) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()))); return getThis(); } @@ -5555,20 +5604,21 @@ public T geosearchstore( * GeoSearchResultOptions} * @return Command Response - The number of elements in the resulting set. */ - public T geosearchstore( - @NonNull String destination, - @NonNull String source, + public T geosearchstore( + @NonNull ArgType destination, + @NonNull ArgType source, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchResultOptions resultOptions) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {destination, source}, - searchFrom.toArgs(), - searchBy.toArgs(), - resultOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearchStore, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearchStore, + newArgsBuilder() + .add(destination) + .add(source) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(resultOptions.toArgs()))); return getThis(); } @@ -5602,20 +5652,21 @@ public T geosearchstore( * @param options The optional inputs to request additional information. * @return Command Response - The number of elements in the resulting set. */ - public T geosearchstore( - @NonNull String destination, - @NonNull String source, + public T geosearchstore( + @NonNull ArgType destination, + @NonNull ArgType source, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchStoreOptions options) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {destination, source}, - searchFrom.toArgs(), - searchBy.toArgs(), - options.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearchStore, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearchStore, + newArgsBuilder() + .add(destination) + .add(source) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(options.toArgs()))); return getThis(); } @@ -5651,22 +5702,23 @@ public T geosearchstore( * GeoSearchResultOptions} * @return Command Response - The number of elements in the resulting set. */ - public T geosearchstore( - @NonNull String destination, - @NonNull String source, + public T geosearchstore( + @NonNull ArgType destination, + @NonNull ArgType source, @NonNull GeoSearchOrigin.SearchOrigin searchFrom, @NonNull GeoSearchShape searchBy, @NonNull GeoSearchStoreOptions options, @NonNull GeoSearchResultOptions resultOptions) { - String[] args = - buildArgs( - concatenateArrays( - new String[] {destination, source}, - searchFrom.toArgs(), - searchBy.toArgs(), - options.toArgs(), - resultOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(GeoSearchStore, args)); + protobufTransaction.addCommands( + buildCommand( + GeoSearchStore, + newArgsBuilder() + .add(destination) + .add(source) + .add(searchFrom.toArgs()) + .add(searchBy.toArgs()) + .add(options.toArgs()) + .add(resultOptions.toArgs()))); return getThis(); } @@ -5682,7 +5734,7 @@ public T geosearchstore( * the cursor returned on the last iteration of the set. The second element is * always an Array of the subset of the set held in key. */ - public T sscan(@NonNull String key, @NonNull String cursor) { + public T sscan(@NonNull ArgType key, @NonNull ArgType cursor) { protobufTransaction.addCommands(buildCommand(SScan, buildArgs(key, cursor))); return getThis(); } @@ -5700,10 +5752,10 @@ public T sscan(@NonNull String key, @NonNull String cursor) { * the cursor returned on the last iteration of the set. The second element is * always an Array of the subset of the set held in key. */ - public T sscan(@NonNull String key, @NonNull String cursor, @NonNull SScanOptions sScanOptions) { - String[] commandArgs = - buildArgs(concatenateArrays(new String[] {key, cursor}, sScanOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(SScan, commandArgs)); + public T sscan( + @NonNull ArgType key, @NonNull ArgType cursor, @NonNull SScanOptions sScanOptions) { + protobufTransaction.addCommands( + buildCommand(SScan, newArgsBuilder().add(key).add(cursor).add(sScanOptions.toArgs()))); return getThis(); } @@ -5721,7 +5773,7 @@ public T sscan(@NonNull String key, @NonNull String cursor, @NonNull SScanOption * . The array in the second element is always a flattened series of String * pairs, where the value is at even indices and the score is at odd indices. */ - public T zscan(@NonNull String key, @NonNull String cursor) { + public T zscan(@NonNull ArgType key, @NonNull ArgType cursor) { protobufTransaction.addCommands(buildCommand(ZScan, buildArgs(key, cursor))); return getThis(); } @@ -5741,10 +5793,10 @@ public T zscan(@NonNull String key, @NonNull String cursor) { * . The array in the second element is always a flattened series of String * pairs, where the value is at even indices and the score is at odd indices. */ - public T zscan(@NonNull String key, @NonNull String cursor, @NonNull ZScanOptions zScanOptions) { - String[] commandArgs = - buildArgs(concatenateArrays(new String[] {key, cursor}, zScanOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(ZScan, commandArgs)); + public T zscan( + @NonNull ArgType key, @NonNull ArgType cursor, @NonNull ZScanOptions zScanOptions) { + protobufTransaction.addCommands( + buildCommand(ZScan, newArgsBuilder().add(key).add(cursor).add(zScanOptions.toArgs()))); return getThis(); } @@ -5762,7 +5814,7 @@ public T zscan(@NonNull String key, @NonNull String cursor, @NonNull ZScanOption * in the second element is always a flattened series of String pairs, where the * key is at even indices and the value is at odd indices. */ - public T hscan(@NonNull String key, @NonNull String cursor) { + public T hscan(@NonNull ArgType key, @NonNull ArgType cursor) { protobufTransaction.addCommands(buildCommand(HScan, buildArgs(key, cursor))); return getThis(); } @@ -5782,10 +5834,10 @@ public T hscan(@NonNull String key, @NonNull String cursor) { * in the second element is always a flattened series of String pairs, where the * key is at even indices and the value is at odd indices. */ - public T hscan(@NonNull String key, @NonNull String cursor, @NonNull HScanOptions hScanOptions) { - final String[] commandArgs = - buildArgs(concatenateArrays(new String[] {key, cursor}, hScanOptions.toArgs())); - protobufTransaction.addCommands(buildCommand(HScan, commandArgs)); + public T hscan( + @NonNull ArgType key, @NonNull ArgType cursor, @NonNull HScanOptions hScanOptions) { + protobufTransaction.addCommands( + buildCommand(HScan, newArgsBuilder().add(key).add(cursor).add(hScanOptions.toArgs()))); return getThis(); } @@ -5800,30 +5852,66 @@ public T hscan(@NonNull String key, @NonNull String cursor, @NonNull HScanOption * context of the current connection. */ public T wait(long numreplicas, long timeout) { - String[] args = buildArgs(Long.toString(numreplicas), Long.toString(timeout)); - protobufTransaction.addCommands(buildCommand(Wait, args)); + protobufTransaction.addCommands(buildCommand(Wait, buildArgs(numreplicas, timeout))); return getThis(); } /** Build protobuf {@link Command} object for given command and arguments. */ protected Command buildCommand(RequestType requestType) { - // An empty args array is still needed for parameter-less commands. - return Command.newBuilder() - .setRequestType(requestType) - .setArgsArray(Command.ArgsArray.newBuilder().build()) - .build(); + return buildCommand(requestType, emptyArgs()); } /** Build protobuf {@link Command} object for given command and arguments. */ - protected Command buildCommand(RequestType requestType, String... args) { + protected Command buildCommand(RequestType requestType, ArgsArray args) { + return Command.newBuilder().setRequestType(requestType).setArgsArray(args).build(); + } + + /** Build protobuf {@link Command} object for given command and arguments. */ + protected Command buildCommand(RequestType requestType, ArgsBuilder argsBuilder) { final Command.Builder builder = Command.newBuilder(); builder.setRequestType(requestType); - CommandManager.populateCommandWithArgs(args, builder); + CommandManager.populateCommandWithArgs(argsBuilder.toArray(), builder); return builder.build(); } - /** Dummy function for taking a series of String parameters and returning an String array */ - private static String[] buildArgs(String... args) { + /** Build protobuf {@link ArgsArray} object for empty arguments. */ + protected ArgsArray emptyArgs() { + ArgsArray.Builder commandArgs = ArgsArray.newBuilder(); + return commandArgs.build(); + } + + protected ArgsArray.Builder newArgsArrayBuilder(ArgType... args) { + ArgsArray.Builder builder = ArgsArray.newBuilder(); + for (ArgType arg : args) { + builder.addArgs(ByteString.copyFrom(GlideString.of(arg).getBytes())); + } + return builder; + } + + /** Build protobuf {@link ArgsArray} object for given arguments. */ + protected ArgsArray buildArgs(ArgType... args) { + return this.newArgsArrayBuilder(args).build(); + } + + /** Convert value to either String or GlideString. If cls is neither, throw an exception */ + protected StringType convertTo(Class cls, ValueType value) { + if (cls.isInstance(this.GLIDE_STRING)) { + return (StringType) GlideString.of(value.toString()); + } else if (cls.isInstance(this.STRING)) { + return (StringType) value.toString(); + } else { + // arguments can be of type String or GlideString + throw new IllegalArgumentException( + "Arguments can only be of type String or GlideString. Got: " + + cls.getClass().getSimpleName()); + } + } + + protected ArgsBuilder newArgsBuilder() { + return new ArgsBuilder(); + } + + protected ArgType[] intoArray(ArgType... args) { return args; } } diff --git a/java/client/src/main/java/glide/api/models/ClusterTransaction.java b/java/client/src/main/java/glide/api/models/ClusterTransaction.java index 42354669f1..4bbebf40d6 100644 --- a/java/client/src/main/java/glide/api/models/ClusterTransaction.java +++ b/java/client/src/main/java/glide/api/models/ClusterTransaction.java @@ -2,14 +2,12 @@ package glide.api.models; import static glide.api.models.commands.SortBaseOptions.STORE_COMMAND_STRING; -import static glide.utils.ArrayTransformUtils.concatenateArrays; import static redis_request.RedisRequestOuterClass.RequestType.SPublish; import static redis_request.RedisRequestOuterClass.RequestType.Sort; import static redis_request.RedisRequestOuterClass.RequestType.SortReadOnly; import glide.api.models.commands.SortClusterOptions; import lombok.NonNull; -import org.apache.commons.lang3.ArrayUtils; /** * Extends BaseTransaction class for cluster mode commands. Transactions allow the execution of a @@ -44,8 +42,9 @@ protected ClusterTransaction getThis() { * @param message The message to publish. * @return Command response - The number of clients that received the message. */ - public ClusterTransaction spublish(@NonNull String channel, @NonNull String message) { - protobufTransaction.addCommands(buildCommand(SPublish, channel, message)); + public ClusterTransaction spublish(@NonNull ArgType channel, @NonNull ArgType message) { + protobufTransaction.addCommands( + buildCommand(SPublish, newArgsBuilder().add(channel).add(message))); return getThis(); } @@ -60,10 +59,10 @@ public ClusterTransaction spublish(@NonNull String channel, @NonNull String mess * @param sortClusterOptions The {@link SortClusterOptions}. * @return Command Response - An Array of sorted elements. */ - public ClusterTransaction sort( - @NonNull String key, @NonNull SortClusterOptions sortClusterOptions) { + public ClusterTransaction sort( + @NonNull ArgType key, @NonNull SortClusterOptions sortClusterOptions) { protobufTransaction.addCommands( - buildCommand(Sort, ArrayUtils.addFirst(sortClusterOptions.toArgs(), key))); + buildCommand(Sort, newArgsBuilder().add(key).add(sortClusterOptions.toArgs()))); return this; } @@ -78,10 +77,10 @@ public ClusterTransaction sort( * @param sortClusterOptions The {@link SortClusterOptions}. * @return Command Response - An Array of sorted elements. */ - public ClusterTransaction sortReadOnly( - @NonNull String key, @NonNull SortClusterOptions sortClusterOptions) { + public ClusterTransaction sortReadOnly( + @NonNull ArgType key, @NonNull SortClusterOptions sortClusterOptions) { protobufTransaction.addCommands( - buildCommand(SortReadOnly, ArrayUtils.addFirst(sortClusterOptions.toArgs(), key))); + buildCommand(SortReadOnly, newArgsBuilder().add(key).add(sortClusterOptions.toArgs()))); return this; } @@ -99,15 +98,18 @@ public ClusterTransaction sortReadOnly( * @return Command Response - The number of elements in the sorted key stored at destination * . */ - public ClusterTransaction sortStore( - @NonNull String key, - @NonNull String destination, + public ClusterTransaction sortStore( + @NonNull ArgType key, + @NonNull ArgType destination, @NonNull SortClusterOptions sortClusterOptions) { - String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination}; protobufTransaction.addCommands( buildCommand( Sort, - concatenateArrays(new String[] {key}, sortClusterOptions.toArgs(), storeArguments))); + newArgsBuilder() + .add(key) + .add(sortClusterOptions.toArgs()) + .add(STORE_COMMAND_STRING) + .add(destination))); return this; } } diff --git a/java/client/src/main/java/glide/api/models/GlideString.java b/java/client/src/main/java/glide/api/models/GlideString.java index f02927ba4b..0b6189b252 100644 --- a/java/client/src/main/java/glide/api/models/GlideString.java +++ b/java/client/src/main/java/glide/api/models/GlideString.java @@ -30,6 +30,22 @@ public static GlideString of(byte[] bytes) { return res; } + /** Allow converting any type to GlideString */ + public static GlideString of(ArgType o) { + if (o instanceof GlideString) { + return (GlideString) o; + } else if (o instanceof byte[]) { + return GlideString.of((byte[]) o); + } else if (o instanceof String) { + return GlideString.of((String) o); + } else { + var res = new GlideString(); + res.string = o.toString(); + res.bytes = res.string.getBytes(StandardCharsets.UTF_8); + return res; + } + } + public static GlideString gs(String string) { return GlideString.of(string); } diff --git a/java/client/src/main/java/glide/api/models/Transaction.java b/java/client/src/main/java/glide/api/models/Transaction.java index 588dd7d641..18669e6958 100644 --- a/java/client/src/main/java/glide/api/models/Transaction.java +++ b/java/client/src/main/java/glide/api/models/Transaction.java @@ -4,8 +4,6 @@ import static glide.api.commands.GenericBaseCommands.REPLACE_REDIS_API; import static glide.api.commands.GenericCommands.DB_REDIS_API; import static glide.api.models.commands.SortBaseOptions.STORE_COMMAND_STRING; -import static glide.api.models.commands.SortOptions.STORE_COMMAND_STRING; -import static glide.utils.ArrayTransformUtils.concatenateArrays; import static redis_request.RedisRequestOuterClass.RequestType.Copy; import static redis_request.RedisRequestOuterClass.RequestType.Move; import static redis_request.RedisRequestOuterClass.RequestType.Select; @@ -52,7 +50,7 @@ protected Transaction getThis() { * @return Command Response - A simple OK response. */ public Transaction select(long index) { - protobufTransaction.addCommands(buildCommand(Select, Long.toString(index))); + protobufTransaction.addCommands(buildCommand(Select, this.buildArgs(Long.toString(index)))); return this; } @@ -67,8 +65,9 @@ public Transaction select(long index) { * if the key already exists in the destination database or does not * exist in the source database. */ - public Transaction move(String key, long dbIndex) { - protobufTransaction.addCommands(buildCommand(Move, key, Long.toString(dbIndex))); + public Transaction move(ArgType key, long dbIndex) { + protobufTransaction.addCommands( + buildCommand(Move, this.buildArgs(key, this.convertTo(key.getClass(), dbIndex)))); return this; } @@ -109,7 +108,7 @@ public Transaction copy( if (replace) { args = ArrayUtils.add(args, REPLACE_REDIS_API); } - protobufTransaction.addCommands(buildCommand(Copy, args)); + protobufTransaction.addCommands(buildCommand(Copy, this.buildArgs(args))); return this; } @@ -123,9 +122,9 @@ public Transaction copy( * @param sortOptions The {@link SortOptions}. * @return Command Response - An Array of sorted elements. */ - public Transaction sort(@NonNull String key, @NonNull SortOptions sortOptions) { + public Transaction sort(@NonNull ArgType key, @NonNull SortOptions sortOptions) { protobufTransaction.addCommands( - buildCommand(Sort, ArrayUtils.addFirst(sortOptions.toArgs(), key))); + buildCommand(Sort, newArgsBuilder().add(key).add(sortOptions.toArgs()))); return this; } @@ -139,9 +138,10 @@ public Transaction sort(@NonNull String key, @NonNull SortOptions sortOptions) { * @param sortOptions The {@link SortOptions}. * @return Command Response - An Array of sorted elements. */ - public Transaction sortReadOnly(@NonNull String key, @NonNull SortOptions sortOptions) { + public Transaction sortReadOnly( + @NonNull ArgType key, @NonNull SortOptions sortOptions) { protobufTransaction.addCommands( - buildCommand(SortReadOnly, ArrayUtils.addFirst(sortOptions.toArgs(), key))); + buildCommand(SortReadOnly, newArgsBuilder().add(key).add(sortOptions.toArgs()))); return this; } @@ -158,12 +158,16 @@ public Transaction sortReadOnly(@NonNull String key, @NonNull SortOptions sortOp * @return Command Response - The number of elements in the sorted key stored at destination * . */ - public Transaction sortStore( - @NonNull String key, @NonNull String destination, @NonNull SortOptions sortOptions) { - String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination}; + public Transaction sortStore( + @NonNull ArgType key, @NonNull ArgType destination, @NonNull SortOptions sortOptions) { protobufTransaction.addCommands( buildCommand( - Sort, concatenateArrays(new String[] {key}, sortOptions.toArgs(), storeArguments))); + Sort, + newArgsBuilder() + .add(key) + .add(sortOptions.toArgs()) + .add(STORE_COMMAND_STRING) + .add(destination))); return this; } } diff --git a/java/client/src/main/java/glide/managers/CommandManager.java b/java/client/src/main/java/glide/managers/CommandManager.java index 481b377a35..353c970b56 100644 --- a/java/client/src/main/java/glide/managers/CommandManager.java +++ b/java/client/src/main/java/glide/managers/CommandManager.java @@ -17,7 +17,6 @@ import glide.connectors.handlers.CallbackDispatcher; import glide.connectors.handlers.ChannelHandler; import glide.ffi.resolvers.RedisValueResolver; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -379,10 +378,11 @@ private Response exceptionHandler(Throwable e) { * @param arguments The arguments to add to the builder. * @param outputBuilder The builder to populate with arguments. */ - public static void populateCommandWithArgs(String[] arguments, Command.Builder outputBuilder) { + public static void populateCommandWithArgs( + ArgType[] arguments, Command.Builder outputBuilder) { populateCommandWithArgs( Arrays.stream(arguments) - .map(value -> value.getBytes(StandardCharsets.UTF_8)) + .map(value -> GlideString.of(value).getBytes()) .collect(Collectors.toList()), outputBuilder); } diff --git a/java/client/src/main/java/glide/utils/ArrayTransformUtils.java b/java/client/src/main/java/glide/utils/ArrayTransformUtils.java index 9e1ffc6d53..f568516817 100644 --- a/java/client/src/main/java/glide/utils/ArrayTransformUtils.java +++ b/java/client/src/main/java/glide/utils/ArrayTransformUtils.java @@ -23,7 +23,7 @@ public class ArrayTransformUtils { */ public static String[] convertMapToKeyValueStringArray(Map args) { return args.entrySet().stream() - .flatMap(entry -> Stream.of(entry.getKey(), entry.getValue().toString())) + .flatMap(entry -> Stream.of(entry.getKey(), entry.getValue())) .toArray(String[]::new); } @@ -181,4 +181,28 @@ public static Map castMapOf2DArray( public static T[] concatenateArrays(T[]... arrays) { return Stream.of(arrays).flatMap(Stream::of).toArray(size -> Arrays.copyOf(arrays[0], size)); } + + /** + * Converts a map of any type of keys and values in to an array of GlideString with alternating + * keys and values. + * + * @param args Map of keys to values of any type to convert. + * @return Array of strings [key1, value1, key2, value2, ...]. + */ + public static GlideString[] flattenMapToGlideStringArray(Map args) { + return args.entrySet().stream() + .flatMap( + entry -> Stream.of(GlideString.of(entry.getKey()), GlideString.of(entry.getValue()))) + .toArray(GlideString[]::new); + } + + /** + * Converts any array into GlideString array keys and values. + * + * @param args Map of keys to values of any type to convert. + * @return Array of strings [key1, value1, key2, value2, ...]. + */ + public static GlideString[] toGlideStringArray(ArgType[] args) { + return Arrays.stream(args).map(GlideString::of).toArray(GlideString[]::new); + } }