From f4735dd7373a61258011378f04fb6d811b91029e Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Mon, 25 Mar 2024 16:39:09 -0700 Subject: [PATCH] Update StreamAddOptions for comments Signed-off-by: Andrew Carbonetto --- .../api/commands/StreamBaseCommands.java | 8 +- .../glide/api/models/BaseTransaction.java | 8 +- .../api/models/commands/StreamAddOptions.java | 48 +++++-- .../test/java/glide/api/RedisClientTest.java | 130 +++++++++--------- .../test/java/glide/SharedCommandTests.java | 16 +-- 5 files changed, 120 insertions(+), 90 deletions(-) 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 fcc00dc75b..5577655ab8 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -18,7 +18,7 @@ public interface StreamBaseCommands { * * @see redis.io for details. * @param key The key of the stream. - * @param values field-value pairs to be added to the entry. + * @param values Field-value pairs to be added to the entry. * @return The id of the added entry. * @example *
{@code
@@ -33,10 +33,10 @@ public interface StreamBaseCommands {
      *
      * @see redis.io for details.
      * @param key The key of the stream.
-     * @param values field-value pairs to be added to the entry.
+     * @param values Field-value pairs to be added to the entry.
      * @param options Stream add options.
-     * @return The id of the added entry, or null if options.makeStream is
-     *     set to false and no stream with the matching key exists.
+     * @return The id of the added entry, or null if {@link StreamAddOptions#makeStream}
+     *     is set to false and no stream with the matching key exists.
      * @example
      *     
{@code
      * // Option to use the existing stream, or return null if the stream doesn't already exist at "key"
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 54a31fa061..9f145ebcb8 100644
--- a/java/client/src/main/java/glide/api/models/BaseTransaction.java
+++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java
@@ -1299,7 +1299,7 @@ public T zscore(@NonNull String key, @NonNull String member) {
      *
      * @see redis.io for details.
      * @param key The key of the stream.
-     * @param values field-value pairs to be added to the entry.
+     * @param values Field-value pairs to be added to the entry.
      * @return Command Response - The id of the added entry.
      */
     public T xadd(@NonNull String key, @NonNull Map values) {
@@ -1312,10 +1312,10 @@ public T xadd(@NonNull String key, @NonNull Map values) {
      *
      * @see redis.io for details.
      * @param key The key of the stream.
-     * @param values field-value pairs to be added to the entry.
+     * @param values Field-value pairs to be added to the entry.
      * @param options Stream add options.
-     * @return Command Response - The id of the added entry, or null if 
-     *     options.makeStream is set to false and no stream with the matching
+     * @return Command Response - The id of the added entry, or null if {@link
+     *     StreamAddOptions#makeStream} is set to false and no stream with the matching
      *     key exists.
      */
     public T xadd(
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 3e13441fc9..f86dd18c68 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
@@ -42,7 +42,7 @@ public abstract static class StreamTrimOptions {
          * 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;
+        protected boolean exact;
 
         /** If set, sets the maximal amount of entries that will be deleted. */
         protected Long limit;
@@ -71,49 +71,79 @@ public static class MinId extends StreamTrimOptions {
         /** Trim the stream according to entry ID. Equivalent to MINID in the Redis API. */
         private final String threshold;
 
+        /**
+         * Create a trim option to trim stream based on stream ID.
+         *
+         * @param exact whether to match exactly on the threshold.
+         * @param threshold comparison id.
+         */
         public MinId(boolean exact, @NonNull String threshold) {
             this.threshold = threshold;
             this.exact = exact;
         }
 
+        /**
+         * Create a trim option to trim stream based on stream ID.
+         *
+         * @param exact whether to match exactly on the threshold.
+         * @param threshold comparison id.
+         * @param limit max number of stream entries to be trimmed.
+         */
         public MinId(boolean exact, @NonNull String threshold, long limit) {
             this.threshold = threshold;
             this.exact = exact;
             this.limit = limit;
         }
 
-        public String getMethod() {
+        @Override
+        protected String getMethod() {
             return TRIM_MINID_REDIS_API;
         }
 
-        public String getThreshold() {
+        @Override
+        protected String getThreshold() {
             return threshold;
         }
     }
 
-    public static class Maxlen extends StreamTrimOptions {
+    public static class MaxLen extends StreamTrimOptions {
         /**
-         * Trim the stream according to length. 
+ * Trim the stream according to length.
* Equivalent to MAXLEN in the Redis API. */ private final Long threshold; - public Maxlen(boolean exact, long threshold) { + /** + * Create a Max Length trim option to trim stream based on length. + * + * @param exact whether to match exactly on the threshold. + * @param threshold comparison count. + */ + public MaxLen(boolean exact, long threshold) { this.threshold = threshold; this.exact = exact; } - public Maxlen(boolean exact, long threshold, long limit) { + /** + * Create a Max Length trim option to trim stream entries exceeds the threshold. + * + * @param exact whether to match exactly on the threshold. + * @param threshold comparison count. + * @param limit max number of stream entries to be trimmed. + */ + public MaxLen(boolean exact, long threshold, long limit) { this.threshold = threshold; this.exact = exact; this.limit = limit; } - public String getMethod() { + @Override + protected String getMethod() { return TRIM_MAXLEN_REDIS_API; } - public String getThreshold() { + @Override + protected String getThreshold() { return threshold.toString(); } } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 17a11a3580..3820604e0e 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -1903,71 +1903,71 @@ public void xadd_with_nomakestream_maxlen_options_returns_success() { private static List getStreamAddOptions() { return List.of( - Arguments.of( - Pair.of( - // no TRIM option - StreamAddOptions.builder().id("id").makeStream(Boolean.FALSE).build(), - new String[] {"testKey", NO_MAKE_STREAM_REDIS_API, "id"}), - Pair.of( - // MAXLEN with LIMIT - StreamAddOptions.builder() - .id("id") - .makeStream(Boolean.TRUE) - .trim(new StreamAddOptions.Maxlen(Boolean.TRUE, 5L, 10L)) - .build(), - new String[] { - "testKey", - TRIM_MAXLEN_REDIS_API, - TRIM_EXACT_REDIS_API, - Long.toString(5L), - TRIM_LIMIT_REDIS_API, - Long.toString(10L), - "id" - }), - Pair.of( - // MAXLEN with non exact match - StreamAddOptions.builder() - .makeStream(Boolean.FALSE) - .trim(new StreamAddOptions.Maxlen(Boolean.FALSE, 2L)) - .build(), - new String[] { - "testKey", - NO_MAKE_STREAM_REDIS_API, - TRIM_MAXLEN_REDIS_API, - TRIM_NOT_EXACT_REDIS_API, - Long.toString(2L), - "*" - }), - Pair.of( - // MIN ID with LIMIT - StreamAddOptions.builder() - .id("id") - .makeStream(Boolean.TRUE) - .trim(new StreamAddOptions.MinId(Boolean.TRUE, "testKey", 10L)) - .build(), - new String[] { - "testKey", - TRIM_MINID_REDIS_API, - TRIM_EXACT_REDIS_API, - Long.toString(5L), - TRIM_LIMIT_REDIS_API, - Long.toString(10L), - "id" - }), - Pair.of( - // MIN ID with non exact match - StreamAddOptions.builder() - .makeStream(Boolean.FALSE) - .trim(new StreamAddOptions.MinId(Boolean.FALSE, "testKey")) - .build(), - new String[] { - "testKey", - NO_MAKE_STREAM_REDIS_API, - TRIM_MINID_REDIS_API, - TRIM_NOT_EXACT_REDIS_API, - Long.toString(5L), - "*" - }))); + Arguments.of( + Pair.of( + // no TRIM option + StreamAddOptions.builder().id("id").makeStream(Boolean.FALSE).build(), + new String[] {"testKey", NO_MAKE_STREAM_REDIS_API, "id"}), + Pair.of( + // MAXLEN with LIMIT + StreamAddOptions.builder() + .id("id") + .makeStream(Boolean.TRUE) + .trim(new StreamAddOptions.MaxLen(Boolean.TRUE, 5L, 10L)) + .build(), + new String[] { + "testKey", + TRIM_MAXLEN_REDIS_API, + TRIM_EXACT_REDIS_API, + Long.toString(5L), + TRIM_LIMIT_REDIS_API, + Long.toString(10L), + "id" + }), + Pair.of( + // MAXLEN with non exact match + StreamAddOptions.builder() + .makeStream(Boolean.FALSE) + .trim(new StreamAddOptions.MaxLen(Boolean.FALSE, 2L)) + .build(), + new String[] { + "testKey", + NO_MAKE_STREAM_REDIS_API, + TRIM_MAXLEN_REDIS_API, + TRIM_NOT_EXACT_REDIS_API, + Long.toString(2L), + "*" + }), + Pair.of( + // MIN ID with LIMIT + StreamAddOptions.builder() + .id("id") + .makeStream(Boolean.TRUE) + .trim(new StreamAddOptions.MinId(Boolean.TRUE, "testKey", 10L)) + .build(), + new String[] { + "testKey", + TRIM_MINID_REDIS_API, + TRIM_EXACT_REDIS_API, + Long.toString(5L), + TRIM_LIMIT_REDIS_API, + Long.toString(10L), + "id" + }), + Pair.of( + // MIN ID with non exact match + StreamAddOptions.builder() + .makeStream(Boolean.FALSE) + .trim(new StreamAddOptions.MinId(Boolean.FALSE, "testKey")) + .build(), + new String[] { + "testKey", + NO_MAKE_STREAM_REDIS_API, + TRIM_MINID_REDIS_API, + TRIM_NOT_EXACT_REDIS_API, + Long.toString(5L), + "*" + }))); } @SneakyThrows diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index b450fb69bc..7d279682c6 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -1174,14 +1174,14 @@ public void xadd(BaseClient client) { // this will trim the first entry. String id = - client - .xadd( - key, - Map.of(field1, "foo3", field2, "bar3"), - StreamAddOptions.builder() - .trim(new StreamAddOptions.Maxlen(Boolean.TRUE, 2L)) - .build()) - .get(); + client + .xadd( + key, + Map.of(field1, "foo3", field2, "bar3"), + StreamAddOptions.builder() + .trim(new StreamAddOptions.MaxLen(Boolean.TRUE, 2L)) + .build()) + .get(); assertNotNull(id); if (client instanceof RedisClient) { assertEquals(2L, ((RedisClient) client).customCommand(new String[] {"XLEN", key}).get());