Skip to content

Commit

Permalink
Java: Added examples to documentation for StringCommands. (#120) (val…
Browse files Browse the repository at this point in the history
…key-io#1068)

* Java: Added examples to documentation for StringCommands. (#120)

* Minor Documentation changes.

* Minor documentation changes.
  • Loading branch information
SanHalacogluImproving authored and cyip10 committed Jun 24, 2024
1 parent ffe5393 commit 43d9610
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions java/client/src/main/java/glide/api/commands/StringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public interface StringCommands {
* @param key The <code>key</code> to retrieve from the database.
* @return Response from Redis. If <code>key</code> exists, returns the <code>value</code> of
* <code>key</code> as a <code>String</code>. Otherwise, return <code>null</code>.
* @example
* <pre>{@code
* String payload = client.get("key").get();
* assert payload.equals("value");
*
* String payload = client.get("non_existing_key").get();
* assert payload.equals(null);
* }</pre>
*/
CompletableFuture<String> get(String key);

Expand All @@ -32,6 +40,11 @@ public interface StringCommands {
* @param key The <code>key</code> to store.
* @param value The value to store with the given <code>key</code>.
* @return Response from Redis containing <code>"OK"</code>.
* @example
* <pre>{@code
* String payload = client.set("key", "value").get();
* assert payload.equals("OK");
* }</pre>
*/
CompletableFuture<String> set(String key, String value);

Expand All @@ -47,6 +60,16 @@ public interface StringCommands {
* {@link ConditionalSet#ONLY_IF_EXISTS} or {@link ConditionalSet#ONLY_IF_DOES_NOT_EXIST}
* conditions, return <code>null</code>. If {@link SetOptionsBuilder#returnOldValue(boolean)}
* is set, return the old value as a <code>String</code>.
* @example
* <pre>{@code
* String payload =
* client.set("key", "value", SetOptions.builder()
* .conditionalSet(ONLY_IF_EXISTS)
* .expiry(SetOptions.Expiry.Seconds(5L))
* .build())
* .get();
* assert payload.equals("OK");
* }</pre>
*/
CompletableFuture<String> set(String key, String value, SetOptions options);

Expand All @@ -58,6 +81,11 @@ public interface StringCommands {
* @return An array of values corresponding to the provided <code>keys</code>.<br>
* If a <code>key</code>is not found, its corresponding value in the list will be <code>null
* </code>.
* @example
* <pre>{@code
* String payload = client.mget(new String[] {"key1", "key2"}).get();
* assert payload.equals(new String[] {"value1", "value2"});
* }</pre>
*/
CompletableFuture<String[]> mget(String[] keys);

Expand All @@ -67,6 +95,11 @@ public interface StringCommands {
* @see <a href="https://redis.io/commands/mset/">redis.io</a> for details.
* @param keyValueMap A key-value map consisting of keys and their respective values to set.
* @return Always <code>OK</code>.
* @example
* <pre>{@code
* String payload = client.mset(Map.of("key1", "value1", "key2", "value2"}).get();
* assert payload.equals("OK"));
* }</pre>
*/
CompletableFuture<String> mset(Map<String, String> keyValueMap);

Expand All @@ -77,6 +110,11 @@ public interface StringCommands {
* @see <a href="https://redis.io/commands/incr/">redis.io</a> for details.
* @param key The key to increment its value.
* @return The value of <code>key</code> after the increment.
* @example
* <pre>{@code
* Long num = client.incr("key").get();
* assert num == 5L;
* }</pre>
*/
CompletableFuture<Long> incr(String key);

Expand All @@ -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 <code>key</code> after the increment.
* @example
* <pre>{@code
* Long num = client.incrBy("key", 2).get();
* assert num == 7L;
* }</pre>
*/
CompletableFuture<Long> incrBy(String key, long amount);

Expand All @@ -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 <code>key</code> after the increment.
* @example
* <pre>{@code
* Long num = client.incrByFloat("key", 0.5).get();
* assert num == 7.5;
* }</pre>
*/
CompletableFuture<Double> incrByFloat(String key, double amount);

Expand All @@ -111,6 +159,11 @@ public interface StringCommands {
* @see <a href="https://redis.io/commands/decr/">redis.io</a> for details.
* @param key The key to decrement its value.
* @return The value of <code>key</code> after the decrement.
* @example
* <pre>{@code
* Long num = client.decr("key").get();
* assert num == 4L;
* }</pre>
*/
CompletableFuture<Long> decr(String key);

Expand All @@ -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 <code>key</code> after the decrement.
* @example
* <pre>{@code
* Long num = client.decrBy("key", 2).get();
* assert num == 2L;
* }</pre>
*/
CompletableFuture<Long> decrBy(String key, long amount);
}

0 comments on commit 43d9610

Please sign in to comment.