From f1d5e6755ecde76b1411c60f9a00437c76ec1f82 Mon Sep 17 00:00:00 2001 From: SanHalacogluImproving <144171266+SanHalacogluImproving@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:10:21 -0800 Subject: [PATCH] Java: Added examples to documentation for StringCommands. (#120) (#1068) * Java: Added examples to documentation for StringCommands. (#120) * Minor Documentation changes. * Minor documentation changes. --- .../glide/api/commands/StringCommands.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/java/client/src/main/java/glide/api/commands/StringCommands.java b/java/client/src/main/java/glide/api/commands/StringCommands.java index 97bb98fa31..7431927947 100644 --- a/java/client/src/main/java/glide/api/commands/StringCommands.java +++ b/java/client/src/main/java/glide/api/commands/StringCommands.java @@ -22,6 +22,14 @@ public interface StringCommands { * @param key The key to retrieve from the database. * @return Response from Redis. If key exists, returns the value of * key as a String. Otherwise, return null. + * @example + *
{@code
+     * String payload = client.get("key").get();
+     * assert payload.equals("value");
+     *
+     * String payload = client.get("non_existing_key").get();
+     * assert payload.equals(null);
+     * }
*/ CompletableFuture get(String key); @@ -32,6 +40,11 @@ public interface StringCommands { * @param key The key to store. * @param value The value to store with the given key. * @return Response from Redis containing "OK". + * @example + *
{@code
+     * String payload = client.set("key", "value").get();
+     * assert payload.equals("OK");
+     * }
*/ CompletableFuture set(String key, String value); @@ -47,6 +60,16 @@ public interface StringCommands { * {@link ConditionalSet#ONLY_IF_EXISTS} or {@link ConditionalSet#ONLY_IF_DOES_NOT_EXIST} * conditions, return null. If {@link SetOptionsBuilder#returnOldValue(boolean)} * is set, return the old value as a String. + * @example + *
{@code
+     * String payload =
+     *         client.set("key", "value", SetOptions.builder()
+     *                 .conditionalSet(ONLY_IF_EXISTS)
+     *                 .expiry(SetOptions.Expiry.Seconds(5L))
+     *                 .build())
+     *                 .get();
+     * assert payload.equals("OK");
+     * }
*/ CompletableFuture set(String key, String value, SetOptions options); @@ -58,6 +81,11 @@ public interface StringCommands { * @return An array of values corresponding to the provided keys.
* If a keyis not found, its corresponding value in the list will be null * . + * @example + *
{@code
+     * String payload = client.mget(new String[] {"key1", "key2"}).get();
+     * assert payload.equals(new String[] {"value1", "value2"});
+     * }
*/ CompletableFuture mget(String[] keys); @@ -67,6 +95,11 @@ public interface StringCommands { * @see redis.io for details. * @param keyValueMap A key-value map consisting of keys and their respective values to set. * @return Always OK. + * @example + *
{@code
+     * String payload = client.mset(Map.of("key1", "value1", "key2", "value2"}).get();
+     * assert payload.equals("OK"));
+     * }
*/ CompletableFuture mset(Map keyValueMap); @@ -77,6 +110,11 @@ public interface StringCommands { * @see redis.io for details. * @param key The key to increment its value. * @return The value of key after the increment. + * @example + *
{@code
+     * Long num = client.incr("key").get();
+     * assert num == 5L;
+     * }
*/ CompletableFuture incr(String key); @@ -88,6 +126,11 @@ public interface StringCommands { * @param key The key to increment its value. * @param amount The amount to increment. * @return The value of key after the increment. + * @example + *
{@code
+     * Long num = client.incrBy("key", 2).get();
+     * assert num == 7L;
+     * }
*/ CompletableFuture incrBy(String key, long amount); @@ -101,6 +144,11 @@ public interface StringCommands { * @param key The key to increment its value. * @param amount The amount to increment. * @return The value of key after the increment. + * @example + *
{@code
+     * Long num = client.incrByFloat("key", 0.5).get();
+     * assert num == 7.5;
+     * }
*/ CompletableFuture incrByFloat(String key, double amount); @@ -111,6 +159,11 @@ public interface StringCommands { * @see redis.io for details. * @param key The key to decrement its value. * @return The value of key after the decrement. + * @example + *
{@code
+     * Long num = client.decr("key").get();
+     * assert num == 4L;
+     * }
*/ CompletableFuture decr(String key); @@ -122,6 +175,11 @@ public interface StringCommands { * @param key The key to decrement its value. * @param amount The amount to decrement. * @return The value of key after the decrement. + * @example + *
{@code
+     * Long num = client.decrBy("key", 2).get();
+     * assert num == 2L;
+     * }
*/ CompletableFuture decrBy(String key, long amount); }