diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 28b59dedfb..5eeba1ef96 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -593,7 +593,7 @@ public CompletableFuture zcard(@NonNull String key) { } @Override - public CompletableFuture xadd(@NonNull String key, Map values) { + public CompletableFuture xadd(@NonNull String key, @NonNull Map values) { return xadd(key, values, StreamAddOptions.builder().build()); } @@ -603,7 +603,7 @@ public CompletableFuture xadd( String[] arguments = ArrayUtils.addAll( ArrayUtils.addFirst(options.toArgs(), key), - ArrayTransformUtils.convertMapToKeyValueStringArray(values)); + convertMapToKeyValueStringArray(values)); return commandManager.submitNewCommand(XAdd, arguments, this::handleStringOrNullResponse); } } diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 2dde99d820..fcc00dc75b 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -39,7 +39,7 @@ public interface StreamBaseCommands { * set to false and no stream with the matching key exists. * @example *
{@code
-     * // Stream options to not make the stream if "key" is not a stream, as use stream id of "sid"
+     * // Option to use the existing stream, or return null if the stream doesn't already exist at "key"
      * StreamAddOptions options = StreamAddOptions.builder().id("sid").makeStream(Boolean.FALSE).build();
      * String streamId = client.xadd("key", Map.of("name", "Sara", "surname", "OConnor"), options).get();
      * if (streamId != null) {
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 eea175265d..4494af36be 100644
--- a/java/client/src/main/java/glide/api/models/BaseTransaction.java
+++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java
@@ -1252,8 +1252,9 @@ public T zcard(@NonNull String key) {
      * @param values field-value pairs to be added to the entry.
      * @return Command Response - The id of the added entry.
      */
-    public T xadd(String key, Map values) {
-        return this.xadd(key, values, StreamAddOptions.builder().build());
+    public T xadd(@NonNull String key, @NonNull Map values) {
+        this.xadd(key, values, StreamAddOptions.builder().build());
+        return getThis();
     }
 
     /**
@@ -1267,11 +1268,11 @@ public T xadd(String key, Map values) {
      *     options.makeStream is set to false and no stream with the matching
      *     key exists.
      */
-    public T xadd(String key, Map values, StreamAddOptions options) {
+    public T xadd(@NonNull String key, @NonNull Map values, @NonNull StreamAddOptions options) {
         String[] arguments =
                 ArrayUtils.addAll(
                         ArrayUtils.addFirst(options.toArgs(), key),
-                        ArrayTransformUtils.convertMapToKeyValueStringArray(values));
+                        convertMapToKeyValueStringArray(values));
         ArgsArray commandArgs = buildArgs(arguments);
         protobufTransaction.addCommands(buildCommand(XAdd, commandArgs));
         return getThis();
diff --git a/java/client/src/main/java/glide/api/models/commands/StreamAddOptions.java b/java/client/src/main/java/glide/api/models/commands/StreamAddOptions.java
index e1f1b99153..fe682d5db9 100644
--- a/java/client/src/main/java/glide/api/models/commands/StreamAddOptions.java
+++ b/java/client/src/main/java/glide/api/models/commands/StreamAddOptions.java
@@ -5,6 +5,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import lombok.Builder;
+import lombok.NonNull;
 
 /**
  * Optional arguments to {@link StreamBaseCommands#xadd}
@@ -37,8 +38,8 @@ public final class StreamAddOptions {
 
     public abstract static class StreamTrimOptions {
         /**
-         * If `true`, the stream will be trimmed exactly. Equivalent to `=` in the Redis API. Otherwise
-         * the stream will be trimmed in a near-exact manner, which is more efficient, equivalent to `~`
+         * If true, the stream will be trimmed exactly. Equivalent to = in the Redis API. Otherwise,
+         * the stream will be trimmed in a near-exact manner, which is more efficient, equivalent to ~
          * in the Redis API.
          */
         protected Boolean exact;
@@ -70,12 +71,12 @@ public static class MinId extends StreamTrimOptions {
         /** Trim the stream according to entry ID. Equivalent to MINID in the Redis API. */
         private final String threshold;
 
-        public MinId(Boolean exact, String threshold) {
+        public MinId(boolean exact, @NonNull String threshold) {
             this.threshold = threshold;
             this.exact = exact;
         }
 
-        public MinId(Boolean exact, String threshold, Long limit) {
+        public MinId(boolean exact, @NonNull String threshold, long limit) {
             this.threshold = threshold;
             this.exact = exact;
             this.limit = limit;
@@ -97,12 +98,12 @@ public static class Maxlen extends StreamTrimOptions {
          */
         private final Long threshold;
 
-        public Maxlen(Boolean exact, Long threshold) {
+        public Maxlen(boolean exact, long threshold) {
             this.threshold = threshold;
             this.exact = exact;
         }
 
-        public Maxlen(Boolean exact, Long threshold, Long limit) {
+        public Maxlen(boolean exact, long threshold, long limit) {
             this.threshold = threshold;
             this.exact = exact;
             this.limit = limit;
diff --git a/java/client/src/test/java/glide/api/models/TransactionTests.java b/java/client/src/test/java/glide/api/models/TransactionTests.java
index d45acf112d..744b14b687 100644
--- a/java/client/src/test/java/glide/api/models/TransactionTests.java
+++ b/java/client/src/test/java/glide/api/models/TransactionTests.java
@@ -374,6 +374,17 @@ public void transaction_builds_protobuf_request(BaseTransaction transaction)
         transaction.zcard("key");
         results.add(Pair.of(Zcard, ArgsArray.newBuilder().addArgs("key").build()));
 
+        transaction.xadd("key", Map.of("field1", "foo1"));
+        results.add(
+            Pair.of(
+                XAdd,
+                ArgsArray.newBuilder()
+                    .addArgs("key")
+                    .addArgs("*")
+                    .addArgs("field1")
+                    .addArgs("foo1")
+                    .build()));
+
         transaction.xadd("key", Map.of("field1", "foo1"), StreamAddOptions.builder().id("id").build());
         results.add(
                 Pair.of(