From aca69eeb8a52179d712a5455dc0289ff224a768f Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 27 Jan 2025 16:06:57 +0000 Subject: [PATCH 1/9] DOC-4757 examples up to brpop --- .../io/redis/examples/async/ListExample.java | 415 ++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 src/test/java/io/redis/examples/async/ListExample.java diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java new file mode 100644 index 000000000..39bc4a09c --- /dev/null +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -0,0 +1,415 @@ +// EXAMPLE: list_tutorial +package io.redis.examples.async; + +import io.lettuce.core.*; +import io.lettuce.core.api.async.RedisAsyncCommands; +import io.lettuce.core.protocol.ProtocolKeyword; +import io.lettuce.core.api.StatefulRedisConnection; + +// REMOVE_START +import org.junit.jupiter.api.Test; +// REMOVE_END + +import java.util.*; +import java.util.concurrent.CompletableFuture; + +// REMOVE_START +import static org.assertj.core.api.Assertions.assertThat; +// REMOVE_END + +public class ListExample { + + // REMOVE_START + @Test + // REMOVE_END + public void run() { + RedisClient redisClient = RedisClient.create("redis://localhost:6379"); + + try (StatefulRedisConnection connection = redisClient.connect()) { + RedisAsyncCommands asyncCommands = connection.async(); + // REMOVE_START + CompletableFuture delResult = asyncCommands + .del("bikes:repairs", "bikes:finished").toCompletableFuture(); + // REMOVE_END + + // STEP_START queue + CompletableFuture queue = asyncCommands.lpush("bikes:repairs", "bike:1") + .thenCompose(res1 -> { + System.out.println(res1); // >>> 1 + // REMOVE_START + assertThat(res1).isEqualTo(1); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:2"); + }).thenCompose(res2 -> { + System.out.println(res2); // >>> 2 + // REMOVE_START + assertThat(res2).isEqualTo(2); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }).thenCompose(res3 -> { + System.out.println(res3); // >>> bike:1 + // REMOVE_START + assertThat(res3).isEqualTo("bike:1"); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo("bike:2"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> bike:2 + .toCompletableFuture(); + // STEP_END + + // STEP_START stack + CompletableFuture stack = queue.thenCompose(r -> { + return asyncCommands.lpush("bikes:repairs", "bike:1"); + + }).thenCompose(res4 -> { + System.out.println(res4); // >>> 1 + // REMOVE_START + assertThat(res4).isEqualTo(1); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:2"); + }).thenCompose(res5 -> { + System.out.println(res5); // >>> 2 + // REMOVE_START + assertThat(res5).isEqualTo(2); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res6 -> { + System.out.println(res6); // >>> bike:2 + // REMOVE_START + assertThat(res6).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo("bike:1"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> bike:1 + .toCompletableFuture(); + // STEP_END + + // STEP_START llen + CompletableFuture llen = stack.thenCompose(r -> { + return asyncCommands.llen("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isZero(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 0 + .toCompletableFuture(); + // STEP_END + + // STEP_START lmove_lrange + CompletableFuture lmovelrange = llen.thenCompose(r -> { + return asyncCommands.lpush("bikes:repairs", "bike:1"); + }).thenCompose(res7 -> { + System.out.println(res7); // >>> 1 + // REMOVE_START + assertThat(res7).isEqualTo(1); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:2"); + }).thenCompose(res8 -> { + System.out.println(res8); // >>> 2 + // REMOVE_START + assertThat(res8).isEqualTo(2); + // REMOVE_END + + return asyncCommands.lmove( + "bikes:repairs", + "bikes:finished", + LMoveArgs.Builder.leftLeft() + ); + }).thenCompose(res9 -> { + System.out.println(res9); // >>> bike:2 + // REMOVE_START + assertThat(res9).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }).thenCompose(res10 -> { + System.out.println(res10); // >>> [bike:1] + // REMOVE_START + assertThat(res10.toString()).isEqualTo("[bike:1]"); + // REMOVE_END + + return asyncCommands.lrange("bikes:finished", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:2]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> [bike:2] + .toCompletableFuture(); + // STEP_END + + // STEP_START lpush_rpush + CompletableFuture lpushrpush = lmovelrange + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1"); + }).thenCompose(res11 -> { + System.out.println(res11); // >>> 1 + // REMOVE_START + assertThat(res11).isEqualTo(1); + // REMOVE_END + + return asyncCommands.rpush("bikes:repairs", "bike:2"); + }).thenCompose(res12 -> { + System.out.println(res12); // >>> 2 + // REMOVE_START + assertThat(res12).isEqualTo(2); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:important_bike"); + }).thenCompose(res13 -> { + System.out.println(res13); // >>> 3 + // REMOVE_START + assertThat(res13).isEqualTo(3); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:important_bike, bike:1, bike:2]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:important_bike, bike:1, bike:2] + .toCompletableFuture(); + // STEP_END + + // STEP_START variadic + CompletableFuture variadic = lpushrpush + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); + }).thenCompose(res14 -> { + System.out.println(res14); // >>> 3 + // REMOVE_START + assertThat(res14).isEqualTo(3); + // REMOVE_END + + return asyncCommands.lpush( + "bikes:repairs", "bike:important_bike", "bike:very_important_bike" + ); + }).thenCompose(res15 -> { + System.out.println(res15); // >>> 5 + // REMOVE_START + assertThat(res15).isEqualTo(5); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3] + .toCompletableFuture(); + // STEP_END + + // STEP_START lpop_rpop + CompletableFuture lpoprpop = variadic + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); + }).thenCompose(res16 -> { + System.out.println(res16); // >>> 3 + // REMOVE_START + assertThat(res16).isEqualTo(3); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }).thenCompose(res17 -> { + System.out.println(res17); // >>> bike:3 + // REMOVE_START + assertThat(res17).isEqualTo("bike:3"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res18 -> { + System.out.println(res18); // >>> bike:1 + // REMOVE_START + assertThat(res18).isEqualTo("bike:1"); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }).thenCompose(res19 -> { + System.out.println(res19); // >>> bike:2 + // REMOVE_START + assertThat(res19).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.rpop(res19); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); + // STEP_END + + // STEP_START ltrim + CompletableFuture ltrim = lpoprpop.thenCompose(r -> { + return asyncCommands.lpush( + "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" + ); + }).thenCompose(res20 -> { + System.out.println(res20); // >>> 5 + // REMOVE_START + assertThat(res20).isEqualTo(5); + // REMOVE_END + + return asyncCommands.ltrim("bikes:repairs", 0, 2); + }).thenCompose(res21 -> { + System.out.println(res21); // >>> OK + // REMOVE_START + assertThat(res21).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:5, bike:4, bike:3] + .toCompletableFuture(); + // STEP_END + + // STEP_START ltrim_end_of_list + CompletableFuture ltrimendoflist = ltrim + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush( + "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" + ); + }).thenCompose(res22 -> { + System.out.println(res22); // >>> 5 + // REMOVE_START + assertThat(res22).isEqualTo(5); + // REMOVE_END + + return asyncCommands.ltrim("bikes:repairs", -3, -1); + }).thenCompose(res23 -> { + System.out.println(res23); // >>> OK + // REMOVE_START + assertThat(res23).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:3, bike:4, bike:5]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:3, bike:4, bike:5] + .toCompletableFuture(); + // STEP_END + + // STEP_START brpop + CompletableFuture brpop = ltrimendoflist + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2"); + }).thenCompose(res24 -> { + System.out.println(res24); // >>> 2 + // REMOVE_START + assertThat(res24).isEqualTo(2); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }).thenCompose(res25 -> { + System.out.println(res25); + // >>> KeyValue[bikes:repairs, bike:2] + // REMOVE_START + assertThat(res25.toString()).isEqualTo("KeyValue[bikes:repairs, bike:2]"); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }).thenCompose(res26 -> { + System.out.println(res26); + // >>> KeyValue[bikes:repairs, bike:1] + // REMOVE_START + assertThat(res26.toString()).isEqualTo("KeyValue[bikes:repairs, bike:1]"); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); + // STEP_END + + // HIDE_START + CompletableFuture.allOf( + // REMOVE_START + delResult, + // REMOVE_END, + brpop + ).join(); + } finally { + redisClient.shutdown(); + } + } +} +// HIDE_END From af14ea1068a0fd618817d78b1d2cc2a6e9364e61 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 14:19:08 +0000 Subject: [PATCH 2/9] DOC-4757 added remaining list examples --- .../io/redis/examples/async/ListExample.java | 172 +++++++++++++++++- 1 file changed, 170 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index 39bc4a09c..bd9c18c0c 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -3,7 +3,6 @@ import io.lettuce.core.*; import io.lettuce.core.api.async.RedisAsyncCommands; -import io.lettuce.core.protocol.ProtocolKeyword; import io.lettuce.core.api.StatefulRedisConnection; // REMOVE_START @@ -400,12 +399,181 @@ public void run() { .toCompletableFuture(); // STEP_END + // STEP_START rule_1 + CompletableFuture rule1 = asyncCommands.del("new_bikes") + .thenCompose(res27 -> { + System.out.println(res27); // >>> 0 + + return asyncCommands.lpush( + "new_bikes", "bike:1", "bike:2", "bike:3" + ); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo(3); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 3 + .toCompletableFuture(); + // STEP_END + + // STEP_START rule_1.1 + CompletableFuture rule11 = rule1.thenCompose(r -> { + return asyncCommands.set("new_bikes", "bike:1"); + }).thenCompose(res28 -> { + System.out.println(res28); // >>> OK + // REMOVE_START + assertThat(res28).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.type("new_bikes"); + }).thenCompose(res29 -> { + System.out.println(res29); // >>> string + // REMOVE_START + assertThat(res29).isEqualTo("string"); + // REMOVE_END + + return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); + }).exceptionally(ex -> { + System.out.println(ex); + // >>> java.util.concurrent.CompletionException: + // >>> io.lettuce.core.RedisCommandExecutionException: + // >>> WRONGTYPE Operation against a key holding the wrong kind of value + // REMOVE_START + assertThat(ex.toString()).isEqualTo("java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value"); + // REMOVE_END + + return -1L; + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo(-1L); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + .toCompletableFuture(); + // STEP_END + + // STEP_START rule_2 + CompletableFuture rule2 = brpop + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.lpush( + "bikes:repairs", "bike:1", "bike:2", "bike:3" + ); + }).thenCompose(res30 -> { + System.out.println(res30); // >>> 3 + // REMOVE_START + assertThat(res30).isEqualTo(3); + // REMOVE_END + + return asyncCommands.exists("bikes:repairs"); + }).thenCompose(res31 -> { + System.out.println(res31); // >>> 1 + // REMOVE_START + assertThat(res31).isEqualTo(1); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res32 -> { + System.out.println(res32); // >>> bike:3 + // REMOVE_START + assertThat(res32).isEqualTo("bike:3"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res33 -> { + System.out.println(res33); // >>> bike:2 + // REMOVE_START + assertThat(res33).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res34 -> { + System.out.println(res34); // >>> bike:1 + // REMOVE_START + assertThat(res34).isEqualTo("bike:1"); + // REMOVE_END + + return asyncCommands.exists("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isZero(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 0 + .toCompletableFuture(); + // STEP_END + + // STEP_START rule_3 + CompletableFuture rule3 = rule2.thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }).thenCompose(res35 -> { + System.out.println(res35); // >>> 0 + + return asyncCommands.llen("bikes:repairs"); + }).thenCompose(res36 -> { + System.out.println(res36); // >>> 0 + // REMOVE_START + assertThat(res36).isZero(); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); + // STEP_END + + // STEP_START ltrim.1 + CompletableFuture ltrim1 = rule3.thenCompose(r -> { + return asyncCommands.lpush( + "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" + ); + }).thenCompose(res37 -> { + System.out.println(res37); // >>> 5 + // REMOVE_START + assertThat(res37).isEqualTo(5); + // REMOVE_END + + return asyncCommands.ltrim("bikes:repairs", 0, 2); + }).thenCompose(res38 -> { + System.out.println(res38); // >>> OK + // REMOVE_START + assertThat(res38).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> [bike:5, bike:4, bike:3] + .toCompletableFuture(); + // STEP_END + // HIDE_START CompletableFuture.allOf( // REMOVE_START delResult, // REMOVE_END, - brpop + rule11, ltrim1 ).join(); } finally { redisClient.shutdown(); From 35d2efe432d8d7a68868aeec4e52bd0c59c5425d Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 14:20:34 +0000 Subject: [PATCH 3/9] DOC-4757 formatted the source --- .../io/redis/examples/async/ListExample.java | 682 +++++++++--------- 1 file changed, 332 insertions(+), 350 deletions(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index bd9c18c0c..c70d47aeb 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -27,13 +27,11 @@ public void run() { try (StatefulRedisConnection connection = redisClient.connect()) { RedisAsyncCommands asyncCommands = connection.async(); // REMOVE_START - CompletableFuture delResult = asyncCommands - .del("bikes:repairs", "bikes:finished").toCompletableFuture(); + CompletableFuture delResult = asyncCommands.del("bikes:repairs", "bikes:finished").toCompletableFuture(); // REMOVE_END // STEP_START queue - CompletableFuture queue = asyncCommands.lpush("bikes:repairs", "bike:1") - .thenCompose(res1 -> { + CompletableFuture queue = asyncCommands.lpush("bikes:repairs", "bike:1").thenCompose(res1 -> { System.out.println(res1); // >>> 1 // REMOVE_START assertThat(res1).isEqualTo(1); @@ -55,16 +53,16 @@ public void run() { return asyncCommands.rpop("bikes:repairs"); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isEqualTo("bike:2"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> bike:2 - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo("bike:2"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> bike:2 + .toCompletableFuture(); // STEP_END - + // STEP_START stack CompletableFuture stack = queue.thenCompose(r -> { return asyncCommands.lpush("bikes:repairs", "bike:1"); @@ -91,28 +89,28 @@ public void run() { return asyncCommands.lpop("bikes:repairs"); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isEqualTo("bike:1"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> bike:1 - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo("bike:1"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> bike:1 + .toCompletableFuture(); // STEP_END // STEP_START llen CompletableFuture llen = stack.thenCompose(r -> { return asyncCommands.llen("bikes:repairs"); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isZero(); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> 0 - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isZero(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 0 + .toCompletableFuture(); // STEP_END // STEP_START lmove_lrange @@ -131,11 +129,7 @@ public void run() { assertThat(res8).isEqualTo(2); // REMOVE_END - return asyncCommands.lmove( - "bikes:repairs", - "bikes:finished", - LMoveArgs.Builder.leftLeft() - ); + return asyncCommands.lmove("bikes:repairs", "bikes:finished", LMoveArgs.Builder.leftLeft()); }).thenCompose(res9 -> { System.out.println(res9); // >>> bike:2 // REMOVE_START @@ -151,148 +145,145 @@ public void run() { return asyncCommands.lrange("bikes:finished", 0, -1); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:2]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> [bike:2] - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:2]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> [bike:2] + .toCompletableFuture(); // STEP_END - + // STEP_START lpush_rpush CompletableFuture lpushrpush = lmovelrange - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.rpush("bikes:repairs", "bike:1"); - }).thenCompose(res11 -> { - System.out.println(res11); // >>> 1 - // REMOVE_START - assertThat(res11).isEqualTo(1); - // REMOVE_END - - return asyncCommands.rpush("bikes:repairs", "bike:2"); - }).thenCompose(res12 -> { - System.out.println(res12); // >>> 2 - // REMOVE_START - assertThat(res12).isEqualTo(2); - // REMOVE_END - - return asyncCommands.lpush("bikes:repairs", "bike:important_bike"); - }).thenCompose(res13 -> { - System.out.println(res13); // >>> 3 - // REMOVE_START - assertThat(res13).isEqualTo(3); - // REMOVE_END - - return asyncCommands.lrange("bikes:repairs", 0, -1); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:important_bike, bike:1, bike:2]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) - // >>> [bike:important_bike, bike:1, bike:2] - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1"); + }).thenCompose(res11 -> { + System.out.println(res11); // >>> 1 + // REMOVE_START + assertThat(res11).isEqualTo(1); + // REMOVE_END + + return asyncCommands.rpush("bikes:repairs", "bike:2"); + }).thenCompose(res12 -> { + System.out.println(res12); // >>> 2 + // REMOVE_START + assertThat(res12).isEqualTo(2); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:important_bike"); + }).thenCompose(res13 -> { + System.out.println(res13); // >>> 3 + // REMOVE_START + assertThat(res13).isEqualTo(3); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:important_bike, bike:1, bike:2]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:important_bike, bike:1, bike:2] + .toCompletableFuture(); // STEP_END - + // STEP_START variadic CompletableFuture variadic = lpushrpush - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); - }).thenCompose(res14 -> { - System.out.println(res14); // >>> 3 - // REMOVE_START - assertThat(res14).isEqualTo(3); - // REMOVE_END - - return asyncCommands.lpush( - "bikes:repairs", "bike:important_bike", "bike:very_important_bike" - ); - }).thenCompose(res15 -> { - System.out.println(res15); // >>> 5 - // REMOVE_START - assertThat(res15).isEqualTo(5); - // REMOVE_END - - return asyncCommands.lrange("bikes:repairs", 0, -1); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) - // >>> [bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3] - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); + }).thenCompose(res14 -> { + System.out.println(res14); // >>> 3 + // REMOVE_START + assertThat(res14).isEqualTo(3); + // REMOVE_END + + return asyncCommands.lpush("bikes:repairs", "bike:important_bike", "bike:very_important_bike"); + }).thenCompose(res15 -> { + System.out.println(res15); // >>> 5 + // REMOVE_START + assertThat(res15).isEqualTo(5); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()) + .isEqualTo("[bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3] + .toCompletableFuture(); // STEP_END - + // STEP_START lpop_rpop CompletableFuture lpoprpop = variadic - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); - }).thenCompose(res16 -> { - System.out.println(res16); // >>> 3 - // REMOVE_START - assertThat(res16).isEqualTo(3); - // REMOVE_END - - return asyncCommands.rpop("bikes:repairs"); - }).thenCompose(res17 -> { - System.out.println(res17); // >>> bike:3 - // REMOVE_START - assertThat(res17).isEqualTo("bike:3"); - // REMOVE_END - - return asyncCommands.lpop("bikes:repairs"); - }).thenCompose(res18 -> { - System.out.println(res18); // >>> bike:1 - // REMOVE_START - assertThat(res18).isEqualTo("bike:1"); - // REMOVE_END - - return asyncCommands.rpop("bikes:repairs"); - }).thenCompose(res19 -> { - System.out.println(res19); // >>> bike:2 - // REMOVE_START - assertThat(res19).isEqualTo("bike:2"); - // REMOVE_END - - return asyncCommands.rpop(res19); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isNull(); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> null - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); + }).thenCompose(res16 -> { + System.out.println(res16); // >>> 3 + // REMOVE_START + assertThat(res16).isEqualTo(3); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }).thenCompose(res17 -> { + System.out.println(res17); // >>> bike:3 + // REMOVE_START + assertThat(res17).isEqualTo("bike:3"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res18 -> { + System.out.println(res18); // >>> bike:1 + // REMOVE_START + assertThat(res18).isEqualTo("bike:1"); + // REMOVE_END + + return asyncCommands.rpop("bikes:repairs"); + }).thenCompose(res19 -> { + System.out.println(res19); // >>> bike:2 + // REMOVE_START + assertThat(res19).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.rpop(res19); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); // STEP_END - + // STEP_START ltrim CompletableFuture ltrim = lpoprpop.thenCompose(r -> { - return asyncCommands.lpush( - "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" - ); + return asyncCommands.lpush("bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5"); }).thenCompose(res20 -> { System.out.println(res20); // >>> 5 // REMOVE_START @@ -308,116 +299,111 @@ public void run() { return asyncCommands.lrange("bikes:repairs", 0, -1); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) - // >>> [bike:5, bike:4, bike:3] - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:5, bike:4, bike:3] + .toCompletableFuture(); // STEP_END - + // STEP_START ltrim_end_of_list CompletableFuture ltrimendoflist = ltrim - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.rpush( - "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" - ); - }).thenCompose(res22 -> { - System.out.println(res22); // >>> 5 - // REMOVE_START - assertThat(res22).isEqualTo(5); - // REMOVE_END - - return asyncCommands.ltrim("bikes:repairs", -3, -1); - }).thenCompose(res23 -> { - System.out.println(res23); // >>> OK - // REMOVE_START - assertThat(res23).isEqualTo("OK"); - // REMOVE_END - - return asyncCommands.lrange("bikes:repairs", 0, -1); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:3, bike:4, bike:5]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) - // >>> [bike:3, bike:4, bike:5] - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5"); + }).thenCompose(res22 -> { + System.out.println(res22); // >>> 5 + // REMOVE_START + assertThat(res22).isEqualTo(5); + // REMOVE_END + + return asyncCommands.ltrim("bikes:repairs", -3, -1); + }).thenCompose(res23 -> { + System.out.println(res23); // >>> OK + // REMOVE_START + assertThat(res23).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.lrange("bikes:repairs", 0, -1); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:3, bike:4, bike:5]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) + // >>> [bike:3, bike:4, bike:5] + .toCompletableFuture(); // STEP_END - + // STEP_START brpop CompletableFuture brpop = ltrimendoflist - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2"); - }).thenCompose(res24 -> { - System.out.println(res24); // >>> 2 - // REMOVE_START - assertThat(res24).isEqualTo(2); - // REMOVE_END - - return asyncCommands.brpop(1, "bikes:repairs"); - }).thenCompose(res25 -> { - System.out.println(res25); - // >>> KeyValue[bikes:repairs, bike:2] - // REMOVE_START - assertThat(res25.toString()).isEqualTo("KeyValue[bikes:repairs, bike:2]"); - // REMOVE_END - - return asyncCommands.brpop(1, "bikes:repairs"); - }).thenCompose(res26 -> { - System.out.println(res26); - // >>> KeyValue[bikes:repairs, bike:1] - // REMOVE_START - assertThat(res26.toString()).isEqualTo("KeyValue[bikes:repairs, bike:1]"); - // REMOVE_END - - return asyncCommands.brpop(1, "bikes:repairs"); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isNull(); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> null - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.rpush("bikes:repairs", "bike:1", "bike:2"); + }).thenCompose(res24 -> { + System.out.println(res24); // >>> 2 + // REMOVE_START + assertThat(res24).isEqualTo(2); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }).thenCompose(res25 -> { + System.out.println(res25); + // >>> KeyValue[bikes:repairs, bike:2] + // REMOVE_START + assertThat(res25.toString()).isEqualTo("KeyValue[bikes:repairs, bike:2]"); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }).thenCompose(res26 -> { + System.out.println(res26); + // >>> KeyValue[bikes:repairs, bike:1] + // REMOVE_START + assertThat(res26.toString()).isEqualTo("KeyValue[bikes:repairs, bike:1]"); + // REMOVE_END + + return asyncCommands.brpop(1, "bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); // STEP_END - + // STEP_START rule_1 - CompletableFuture rule1 = asyncCommands.del("new_bikes") - .thenCompose(res27 -> { + CompletableFuture rule1 = asyncCommands.del("new_bikes").thenCompose(res27 -> { System.out.println(res27); // >>> 0 - return asyncCommands.lpush( - "new_bikes", "bike:1", "bike:2", "bike:3" - ); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isEqualTo(3); - return res; + return asyncCommands.lpush("new_bikes", "bike:1", "bike:2", "bike:3"); }) - // REMOVE_END - .thenAccept(System.out::println) // >>> 3 - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo(3); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 3 + .toCompletableFuture(); // STEP_END - + // STEP_START rule_1.1 CompletableFuture rule11 = rule1.thenCompose(r -> { return asyncCommands.set("new_bikes", "bike:1"); @@ -433,7 +419,7 @@ public void run() { // REMOVE_START assertThat(res29).isEqualTo("string"); // REMOVE_END - + return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); }).exceptionally(ex -> { System.out.println(ex); @@ -441,76 +427,74 @@ public void run() { // >>> io.lettuce.core.RedisCommandExecutionException: // >>> WRONGTYPE Operation against a key holding the wrong kind of value // REMOVE_START - assertThat(ex.toString()).isEqualTo("java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value"); + assertThat(ex.toString()).isEqualTo( + "java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value"); // REMOVE_END return -1L; }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isEqualTo(-1L); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isEqualTo(-1L); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println).toCompletableFuture(); // STEP_END - + // STEP_START rule_2 CompletableFuture rule2 = brpop - // REMOVE_START - .thenCompose(r -> { - return asyncCommands.del("bikes:repairs"); - }) - // REMOVE_END - .thenCompose(r -> { - return asyncCommands.lpush( - "bikes:repairs", "bike:1", "bike:2", "bike:3" - ); - }).thenCompose(res30 -> { - System.out.println(res30); // >>> 3 - // REMOVE_START - assertThat(res30).isEqualTo(3); - // REMOVE_END - - return asyncCommands.exists("bikes:repairs"); - }).thenCompose(res31 -> { - System.out.println(res31); // >>> 1 - // REMOVE_START - assertThat(res31).isEqualTo(1); - // REMOVE_END - - return asyncCommands.lpop("bikes:repairs"); - }).thenCompose(res32 -> { - System.out.println(res32); // >>> bike:3 - // REMOVE_START - assertThat(res32).isEqualTo("bike:3"); - // REMOVE_END - - return asyncCommands.lpop("bikes:repairs"); - }).thenCompose(res33 -> { - System.out.println(res33); // >>> bike:2 - // REMOVE_START - assertThat(res33).isEqualTo("bike:2"); - // REMOVE_END - - return asyncCommands.lpop("bikes:repairs"); - }).thenCompose(res34 -> { - System.out.println(res34); // >>> bike:1 - // REMOVE_START - assertThat(res34).isEqualTo("bike:1"); - // REMOVE_END - - return asyncCommands.exists("bikes:repairs"); - }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isZero(); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> 0 - .toCompletableFuture(); + // REMOVE_START + .thenCompose(r -> { + return asyncCommands.del("bikes:repairs"); + }) + // REMOVE_END + .thenCompose(r -> { + return asyncCommands.lpush("bikes:repairs", "bike:1", "bike:2", "bike:3"); + }).thenCompose(res30 -> { + System.out.println(res30); // >>> 3 + // REMOVE_START + assertThat(res30).isEqualTo(3); + // REMOVE_END + + return asyncCommands.exists("bikes:repairs"); + }).thenCompose(res31 -> { + System.out.println(res31); // >>> 1 + // REMOVE_START + assertThat(res31).isEqualTo(1); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res32 -> { + System.out.println(res32); // >>> bike:3 + // REMOVE_START + assertThat(res32).isEqualTo("bike:3"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res33 -> { + System.out.println(res33); // >>> bike:2 + // REMOVE_START + assertThat(res33).isEqualTo("bike:2"); + // REMOVE_END + + return asyncCommands.lpop("bikes:repairs"); + }).thenCompose(res34 -> { + System.out.println(res34); // >>> bike:1 + // REMOVE_START + assertThat(res34).isEqualTo("bike:1"); + // REMOVE_END + + return asyncCommands.exists("bikes:repairs"); + }) + // REMOVE_START + .thenApply(res -> { + assertThat(res).isZero(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> 0 + .toCompletableFuture(); // STEP_END // STEP_START rule_3 @@ -518,7 +502,7 @@ public void run() { return asyncCommands.del("bikes:repairs"); }).thenCompose(res35 -> { System.out.println(res35); // >>> 0 - + return asyncCommands.llen("bikes:repairs"); }).thenCompose(res36 -> { System.out.println(res36); // >>> 0 @@ -528,21 +512,19 @@ public void run() { return asyncCommands.lpop("bikes:repairs"); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res).isNull(); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> null - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res).isNull(); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> null + .toCompletableFuture(); // STEP_END - + // STEP_START ltrim.1 CompletableFuture ltrim1 = rule3.thenCompose(r -> { - return asyncCommands.lpush( - "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" - ); + return asyncCommands.lpush("bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5"); }).thenCompose(res37 -> { System.out.println(res37); // >>> 5 // REMOVE_START @@ -558,26 +540,26 @@ public void run() { return asyncCommands.lrange("bikes:repairs", 0, -1); }) - // REMOVE_START - .thenApply(res -> { - assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); - return res; - }) - // REMOVE_END - .thenAccept(System.out::println) // >>> [bike:5, bike:4, bike:3] - .toCompletableFuture(); + // REMOVE_START + .thenApply(res -> { + assertThat(res.toString()).isEqualTo("[bike:5, bike:4, bike:3]"); + return res; + }) + // REMOVE_END + .thenAccept(System.out::println) // >>> [bike:5, bike:4, bike:3] + .toCompletableFuture(); // STEP_END - + // HIDE_START CompletableFuture.allOf( // REMOVE_START delResult, // REMOVE_END, - rule11, ltrim1 - ).join(); + rule11, ltrim1).join(); } finally { redisClient.shutdown(); } } + } // HIDE_END From d44d03d6745a37157c3f482948db5ba9dba21cd6 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 15:09:31 +0000 Subject: [PATCH 4/9] DOC-4757 tried using handle() to handle exception instead of exceptionally() --- .../io/redis/examples/async/ListExample.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index c70d47aeb..c248287c1 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -421,17 +421,22 @@ public void run() { // REMOVE_END return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); - }).exceptionally(ex -> { - System.out.println(ex); - // >>> java.util.concurrent.CompletionException: - // >>> io.lettuce.core.RedisCommandExecutionException: - // >>> WRONGTYPE Operation against a key holding the wrong kind of value - // REMOVE_START - assertThat(ex.toString()).isEqualTo( - "java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value"); - // REMOVE_END + }).handle((res, ex) -> { + if (ex == null) { + return res; + } else { + System.out.println(ex); + // >>> java.util.concurrent.CompletionException: + // >>> io.lettuce.core.RedisCommandExecutionException: + // >>> WRONGTYPE Operation against a key holding the wrong + // >>> kind of value + // REMOVE_START + assertThat(ex.toString()).isEqualTo( + "java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value"); + // REMOVE_END - return -1L; + return -1L; + } }) // REMOVE_START .thenApply(res -> { From d001b3a28341057748259173f256c6f63874eee0 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 15:26:13 +0000 Subject: [PATCH 5/9] DOC-4757 formatting changes --- src/test/java/io/redis/examples/async/ListExample.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index c248287c1..d0a1a2f5a 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -5,14 +5,9 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.StatefulRedisConnection; -// REMOVE_START -import org.junit.jupiter.api.Test; -// REMOVE_END - -import java.util.*; import java.util.concurrent.CompletableFuture; - // REMOVE_START +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; // REMOVE_END From 80e57b2957db035752c8600f8797a2da6df594bd Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 15:38:35 +0000 Subject: [PATCH 6/9] DOC-4757 try removing command that throws exception --- src/test/java/io/redis/examples/async/ListExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index d0a1a2f5a..550d1b3f1 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -415,7 +415,7 @@ public void run() { assertThat(res29).isEqualTo("string"); // REMOVE_END - return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); + //return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); }).handle((res, ex) -> { if (ex == null) { return res; From 8759c133aa26bf2889bf6c1308c46d4f614c0fb5 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 15:40:38 +0000 Subject: [PATCH 7/9] DOC-4757 fix formatting error --- src/test/java/io/redis/examples/async/ListExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index 550d1b3f1..39e12042e 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -415,7 +415,7 @@ public void run() { assertThat(res29).isEqualTo("string"); // REMOVE_END - //return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); + // return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); }).handle((res, ex) -> { if (ex == null) { return res; From e651b8d15e6cafb6487e503b24e3e13d87d86cfb Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 15:46:30 +0000 Subject: [PATCH 8/9] DOC-4757 fix up replaced command and assertion --- src/test/java/io/redis/examples/async/ListExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index 39e12042e..5f1cba348 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -416,6 +416,7 @@ public void run() { // REMOVE_END // return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); + return asyncCommands.set("new_bikes", "bike:1"); }).handle((res, ex) -> { if (ex == null) { return res; @@ -435,7 +436,7 @@ public void run() { }) // REMOVE_START .thenApply(res -> { - assertThat(res).isEqualTo(-1L); + // assertThat(res).isEqualTo(-1L); return res; }) // REMOVE_END From e8b1d54a927eb16b7f3dc5ee54b129cbadb19a41 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 28 Jan 2025 16:05:01 +0000 Subject: [PATCH 9/9] DOC-4757 try using different key for exception example --- .../java/io/redis/examples/async/ListExample.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/redis/examples/async/ListExample.java b/src/test/java/io/redis/examples/async/ListExample.java index 5f1cba348..19ae1f2a9 100644 --- a/src/test/java/io/redis/examples/async/ListExample.java +++ b/src/test/java/io/redis/examples/async/ListExample.java @@ -22,7 +22,8 @@ public void run() { try (StatefulRedisConnection connection = redisClient.connect()) { RedisAsyncCommands asyncCommands = connection.async(); // REMOVE_START - CompletableFuture delResult = asyncCommands.del("bikes:repairs", "bikes:finished").toCompletableFuture(); + CompletableFuture delResult = asyncCommands + .del("bikes:repairs", "bikes:finished", "new_bikes", "new_bikes_string").toCompletableFuture(); // REMOVE_END // STEP_START queue @@ -401,22 +402,21 @@ public void run() { // STEP_START rule_1.1 CompletableFuture rule11 = rule1.thenCompose(r -> { - return asyncCommands.set("new_bikes", "bike:1"); + return asyncCommands.set("new_bikes_string", "bike:1"); }).thenCompose(res28 -> { System.out.println(res28); // >>> OK // REMOVE_START assertThat(res28).isEqualTo("OK"); // REMOVE_END - return asyncCommands.type("new_bikes"); + return asyncCommands.type("new_bikes_string"); }).thenCompose(res29 -> { System.out.println(res29); // >>> string // REMOVE_START assertThat(res29).isEqualTo("string"); // REMOVE_END - // return asyncCommands.lpush("new_bikes", "bike:2", "bike:3"); - return asyncCommands.set("new_bikes", "bike:1"); + return asyncCommands.lpush("new_bikes_string", "bike:2", "bike:3"); }).handle((res, ex) -> { if (ex == null) { return res; @@ -436,11 +436,12 @@ public void run() { }) // REMOVE_START .thenApply(res -> { - // assertThat(res).isEqualTo(-1L); + assertThat(res).isEqualTo(-1L); return res; }) // REMOVE_END - .thenAccept(System.out::println).toCompletableFuture(); + .thenAccept(System.out::println) // >>> -1 + .toCompletableFuture(); // STEP_END // STEP_START rule_2