diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/ReactiveTransactionalJsonCommands.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/ReactiveTransactionalJsonCommands.java index a71ba1a74fbf8..a7f681014584e 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/ReactiveTransactionalJsonCommands.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/ReactiveTransactionalJsonCommands.java @@ -21,6 +21,21 @@ public interface ReactiveTransactionalJsonCommands extends ReactiveTransactio */ Uni jsonSet(K key, String path, T value); + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + * + * @param key the key, must not be {@code null} + * @param value the value, encoded to JSON + * @param the type for the value + * @return A {@code Uni} emitting {@code null} when the command has been enqueued successfully in the transaction, a failure + * otherwise. In the case of failure, the transaction is discarded. + **/ + default Uni jsonSet(K key, T value) { + return jsonSet(key, "$", value); + } + /** * Execute the command JSON.SET. * Summary: Sets the JSON value at path in key. @@ -48,6 +63,22 @@ public interface ReactiveTransactionalJsonCommands extends ReactiveTransactio */ Uni jsonSet(K key, String path, JsonObject json, JsonSetArgs args); + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + *

+ * This variant uses {@code $} as path. + * + * @param key the key, must not be {@code null} + * @param json the JSON object to store, must not be {@code null} + * @return A {@code Uni} emitting {@code null} when the command has been enqueued successfully in the transaction, a failure + * otherwise. In the case of failure, the transaction is discarded. + **/ + default Uni jsonSet(K key, JsonObject json) { + return jsonSet(key, "$", json); + } + /** * Execute the command JSON.SET. * Summary: Sets the JSON value at path in key. @@ -61,6 +92,20 @@ public interface ReactiveTransactionalJsonCommands extends ReactiveTransactio */ Uni jsonSet(K key, String path, JsonArray json); + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + * + * @param key the key, must not be {@code null} + * @param json the JSON array to store, must not be {@code null} + * @return A {@code Uni} emitting {@code null} when the command has been enqueued successfully in the transaction, a failure + * otherwise. In the case of failure, the transaction is discarded. + **/ + default Uni jsonSet(K key, JsonArray json) { + return jsonSet(key, "$", json); + } + /** * Execute the command JSON.SET. * Summary: Sets the JSON value at path in key. @@ -255,6 +300,22 @@ default Uni jsonArrIndex(K key, String path, T value) { */ Uni jsonArrPop(K key, Class clazz, String path, int index); + /** + * Execute the command JSON.ARRPOP. + * Summary: Removes and returns an element from the index in the array. + * Group: json + *

+ * + * @param key the key, must not be {@code null} + * @param clazz the type of the popped object + * @param path path the path, defaults to root if not provided. + * @return A {@code Uni} emitting {@code null} when the command has been enqueued successfully in the transaction, a failure + * otherwise. In the case of failure, the transaction is discarded. + **/ + default Uni jsonArrPop(K key, Class clazz, String path) { + return jsonArrPop(key, clazz, path, -1); + } + /** * Execute the command JSON.ARRTRIM. * Summary: Trims an array so that it contains only the specified inclusive range of elements. diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/TransactionalJsonCommands.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/TransactionalJsonCommands.java index cd44cdd07bffc..5e9ffb763ca33 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/TransactionalJsonCommands.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/json/TransactionalJsonCommands.java @@ -18,6 +18,19 @@ public interface TransactionalJsonCommands extends TransactionalRedisCommands */ void jsonSet(K key, String path, T value); + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + * + * @param key the key, must not be {@code null} + * @param value the value, encoded to JSON + * @param the type for the value + **/ + default void jsonSet(K key, T value) { + jsonSet(key, "$", value); + } + /** * Execute the command JSON.SET. * Summary: Sets the JSON value at path in key. @@ -29,6 +42,32 @@ public interface TransactionalJsonCommands extends TransactionalRedisCommands */ void jsonSet(K key, String path, JsonObject json); + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + *

+ * This variant uses {@code $} as path. + * + * @param key the key, must not be {@code null} + * @param json the JSON object to store, must not be {@code null} + **/ + default void jsonSet(K key, JsonObject json) { + jsonSet(key, "$", json); + } + + /** + * Execute the command JSON.SET. + * Summary: Sets the JSON value at path in key. + * Group: json + * + * @param key the key, must not be {@code null} + * @param json the JSON array to store, must not be {@code null} + **/ + default void jsonSet(K key, JsonArray json) { + jsonSet(key, "$", json); + } + /** * Execute the command JSON.SET. * Summary: Sets the JSON value at path in key. @@ -220,6 +259,20 @@ default void jsonArrIndex(K key, String path, T value) { */ void jsonArrPop(K key, Class clazz, String path, int index); + /** + * Execute the command JSON.ARRPOP. + * Summary: Removes and returns an element from the index in the array. + * Group: json + *

+ * + * @param key the key, must not be {@code null} + * @param clazz the type of the popped object + * @param path path the path, defaults to root if not provided. + **/ + default void jsonArrPop(K key, Class clazz, String path) { + jsonArrPop(key, clazz, path, -1); + } + /** * Execute the command JSON.ARRTRIM. * Summary: Trims an array so that it contains only the specified inclusive range of elements. diff --git a/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/TransactionalJsonCommandsTest.java b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/TransactionalJsonCommandsTest.java index ad50d48e42423..8335856ae9395 100644 --- a/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/TransactionalJsonCommandsTest.java +++ b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/TransactionalJsonCommandsTest.java @@ -27,6 +27,7 @@ public class TransactionalJsonCommandsTest extends DatasourceTestBase { Person person = new Person("luke", "skywalker"); Person person2 = new Person("leia", "skywalker"); + Person person3 = new Person("anakin", "skywalker"); @BeforeEach void initialize() { @@ -62,8 +63,12 @@ public void setBlocking() { json.jsonSet("sister", "$", new JsonObject(Json.encode(person2))); json.jsonGet("sister", Person.class); + + json.jsonSet("someone", person3); + json.jsonGetObject("someone"); + }); - assertThat(result.size()).isEqualTo(12); + assertThat(result.size()).isEqualTo(14); assertThat(result.discarded()).isFalse(); assertThat((Void) result.get(0)).isNull(); @@ -82,6 +87,7 @@ public void setBlocking() { assertThat(actual.getJsonArray("a")).isEmpty();// cleared assertThat((Void) result.get(10)).isNull(); assertThat((Person) result.get(11)).isEqualTo(person2); + assertThat(((JsonObject) result.get(13)).mapTo(Person.class)).isEqualTo(person3); } @Test @@ -100,9 +106,11 @@ public void setReactive() { .chain(() -> json.jsonStrLen(key, "$.sister.lastname")) // 8 -> 10 .chain(() -> json.jsonGet(key)) // 9 {...} .chain(() -> json.jsonSet("sister", "$", new JsonObject(Json.encode(person2)))) - .chain(() -> json.jsonGet("sister", Person.class)); + .chain(() -> json.jsonGet("sister", Person.class)) + .chain(() -> json.jsonSet("someone", person3)) + .chain(() -> json.jsonGetObject("someone")); }).await().atMost(Duration.ofSeconds(5)); - assertThat(result.size()).isEqualTo(12); + assertThat(result.size()).isEqualTo(14); assertThat(result.discarded()).isFalse(); assertThat((Void) result.get(0)).isNull(); @@ -121,6 +129,8 @@ public void setReactive() { assertThat(actual.getJsonArray("a")).isEmpty();// cleared assertThat((Void) result.get(10)).isNull(); assertThat((Person) result.get(11)).isEqualTo(person2); + assertThat((Person) result.get(11)).isEqualTo(person2); + assertThat(((JsonObject) result.get(13)).mapTo(Person.class)).isEqualTo(person3); } }