From 127d29e3ef666714141ba057957af1b11e3513a8 Mon Sep 17 00:00:00 2001 From: Tihomir Mateev Date: Fri, 2 Aug 2024 20:18:47 +0300 Subject: [PATCH] Formatting --- .../core/AbstractRedisReactiveCommands.java | 3 ++ .../lettuce/core/RedisAsyncCommandsImpl.java | 15 ++++++++++ .../lettuce/core/RedisJsonCommandBuilder.java | 6 ++-- .../core/RedisReactiveCommandsImpl.java | 15 ++++++++++ .../core/StatefulRedisConnectionImpl.java | 10 ------- .../core/api/StatefulRedisConnection.java | 4 --- .../core/api/async/RedisAsyncCommands.java | 5 ++++ .../api/reactive/RedisReactiveCommands.java | 5 ++++ .../lettuce/core/api/sync/RedisCommands.java | 5 ++++ .../lettuce/core/json/DelegateJsonValue.java | 4 ++- .../java/io/lettuce/core/json/JsonArray.java | 2 +- .../java/io/lettuce/core/json/JsonObject.java | 4 +-- .../java/io/lettuce/core/json/JsonValue.java | 28 +++++++++++++++++++ .../core/RedisContainerIntegrationTests.java | 4 +-- 14 files changed, 87 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 9f2c81f7da..4b5aa4928a 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -26,6 +26,8 @@ import io.lettuce.core.codec.Base16; import io.lettuce.core.codec.RedisCodec; import io.lettuce.core.internal.LettuceAssert; +import io.lettuce.core.json.JsonParser; +import io.lettuce.core.json.JsonParserRegistry; import io.lettuce.core.json.JsonPath; import io.lettuce.core.json.JsonValue; import io.lettuce.core.json.arguments.JsonGetArgs; @@ -80,6 +82,7 @@ * @author dengliming * @author Andrey Shlykov * @author Ali Takavci + * @author Tihomir Mateev * @since 4.0 */ public abstract class AbstractRedisReactiveCommands diff --git a/src/main/java/io/lettuce/core/RedisAsyncCommandsImpl.java b/src/main/java/io/lettuce/core/RedisAsyncCommandsImpl.java index aeb17c53e8..4c14d8418b 100644 --- a/src/main/java/io/lettuce/core/RedisAsyncCommandsImpl.java +++ b/src/main/java/io/lettuce/core/RedisAsyncCommandsImpl.java @@ -4,6 +4,8 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.json.JsonParser; +import io.lettuce.core.json.JsonParserRegistry; /** * An asynchronous and thread-safe API for a Redis connection. @@ -15,6 +17,8 @@ public class RedisAsyncCommandsImpl extends AbstractRedisAsyncCommands implements RedisAsyncCommands, RedisClusterAsyncCommands { + private final RedisCodec codec; + /** * Initialize a new instance. * @@ -24,6 +28,7 @@ public class RedisAsyncCommandsImpl extends AbstractRedisAsyncCommands connection, RedisCodec codec) { super(connection, codec); + this.codec = codec; } @Override @@ -31,4 +36,14 @@ public StatefulRedisConnection getStatefulConnection() { return (StatefulRedisConnection) super.getConnection(); } + @Override + public JsonParser getJsonParser() { + return JsonParserRegistry.getJsonParser(this.codec); + } + + @Override + public void setJsonParser(JsonParser jsonParser) { + throw new UnsupportedOperationException("Setting a custom JsonParser is not supported"); + } + } diff --git a/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java b/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java index aa8a316f91..7b19c98e89 100644 --- a/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java @@ -73,7 +73,7 @@ Command> jsonArrappend(K key, JsonPath jsonPath, JsonValue value : jsonValues) { - args.addValue(value.toValue()); + args.add(value.asByteBuffer().array()); } return createCommand(JSON_ARRAPPEND, new IntegerListOutput<>(codec), args); @@ -88,7 +88,7 @@ RedisCommand> jsonArrindex(K key, JsonPath jsonPath, JsonValue< args.add(jsonPath.toString()); } - args.addValue(value.toValue()); + args.add(value.asByteBuffer().array()); if (range != null) { // OPTIONAL as per API @@ -208,7 +208,7 @@ RedisCommand jsonSet(K key, JsonPath jsonPath, JsonValue val args.add(jsonPath.toString()); } - args.addValue(value.toValue()); + args.add(value.asByteBuffer().array()); if (options != null) { options.build(args); diff --git a/src/main/java/io/lettuce/core/RedisReactiveCommandsImpl.java b/src/main/java/io/lettuce/core/RedisReactiveCommandsImpl.java index 6b28b8e051..b3ee424307 100644 --- a/src/main/java/io/lettuce/core/RedisReactiveCommandsImpl.java +++ b/src/main/java/io/lettuce/core/RedisReactiveCommandsImpl.java @@ -4,6 +4,8 @@ import io.lettuce.core.api.reactive.RedisReactiveCommands; import io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands; import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.json.JsonParser; +import io.lettuce.core.json.JsonParserRegistry; /** * A reactive and thread-safe API for a Redis Sentinel connection. @@ -15,6 +17,8 @@ public class RedisReactiveCommandsImpl extends AbstractRedisReactiveCommands implements RedisReactiveCommands, RedisClusterReactiveCommands { + private final RedisCodec codec; + /** * Initialize a new instance. * @@ -24,6 +28,7 @@ public class RedisReactiveCommandsImpl extends AbstractRedisReactiveComman */ public RedisReactiveCommandsImpl(StatefulRedisConnection connection, RedisCodec codec) { super(connection, codec); + this.codec = codec; } @Override @@ -31,4 +36,14 @@ public StatefulRedisConnection getStatefulConnection() { return (StatefulRedisConnection) super.getConnection(); } + @Override + public JsonParser getJsonParser() { + return JsonParserRegistry.getJsonParser(this.codec); + } + + @Override + public void setJsonParser(JsonParser jsonParser) { + throw new UnsupportedOperationException("Setting a custom JsonParser is not supported"); + } + } diff --git a/src/main/java/io/lettuce/core/StatefulRedisConnectionImpl.java b/src/main/java/io/lettuce/core/StatefulRedisConnectionImpl.java index d8688ce9ca..25f3bde262 100644 --- a/src/main/java/io/lettuce/core/StatefulRedisConnectionImpl.java +++ b/src/main/java/io/lettuce/core/StatefulRedisConnectionImpl.java @@ -154,16 +154,6 @@ public void removeListener(PushListener listener) { pushHandler.removeListener(listener); } - @Override - public JsonParser getJsonParser() { - return JsonParserRegistry.getJsonParser(this.codec); - } - - @Override - public void setJsonParser(JsonParser jsonParser) { - throw new UnsupportedOperationException("Setting a custom JsonParser is not supported"); - } - @Override public boolean isMulti() { return multi != null; diff --git a/src/main/java/io/lettuce/core/api/StatefulRedisConnection.java b/src/main/java/io/lettuce/core/api/StatefulRedisConnection.java index 429625cdb7..2c6a4883c9 100644 --- a/src/main/java/io/lettuce/core/api/StatefulRedisConnection.java +++ b/src/main/java/io/lettuce/core/api/StatefulRedisConnection.java @@ -63,8 +63,4 @@ public interface StatefulRedisConnection extends StatefulConnection */ void removeListener(PushListener listener); - JsonParser getJsonParser(); - - void setJsonParser(JsonParser jsonParser); - } diff --git a/src/main/java/io/lettuce/core/api/async/RedisAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisAsyncCommands.java index ed9db4a43d..89c97ca4c8 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisAsyncCommands.java @@ -22,6 +22,7 @@ import io.lettuce.core.RedisFuture; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; +import io.lettuce.core.json.JsonParser; /** * A complete asynchronous and thread-safe Redis API with 400+ Methods. @@ -81,4 +82,8 @@ public interface RedisAsyncCommands extends BaseRedisAsyncCommands, @Deprecated StatefulRedisConnection getStatefulConnection(); + JsonParser getJsonParser(); + + void setJsonParser(JsonParser jsonParser); + } diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisReactiveCommands.java index 2f75efcc92..8d807e680f 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisReactiveCommands.java @@ -21,6 +21,7 @@ import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands; +import io.lettuce.core.json.JsonParser; import reactor.core.publisher.Mono; /** @@ -81,4 +82,8 @@ public interface RedisReactiveCommands extends BaseRedisReactiveCommands getStatefulConnection(); + JsonParser getJsonParser(); + + void setJsonParser(JsonParser jsonParser); + } diff --git a/src/main/java/io/lettuce/core/api/sync/RedisCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisCommands.java index 0c813e396e..0f9a27b1d6 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisCommands.java @@ -21,6 +21,7 @@ import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.json.JsonParser; /** * @@ -80,4 +81,8 @@ public interface RedisCommands extends BaseRedisCommands, RedisAclCo @Deprecated StatefulRedisConnection getStatefulConnection(); + JsonParser getJsonParser(); + + void setJsonParser(JsonParser jsonParser); + } diff --git a/src/main/java/io/lettuce/core/json/DelegateJsonValue.java b/src/main/java/io/lettuce/core/json/DelegateJsonValue.java index 0f5629d719..3aaec40a82 100644 --- a/src/main/java/io/lettuce/core/json/DelegateJsonValue.java +++ b/src/main/java/io/lettuce/core/json/DelegateJsonValue.java @@ -82,7 +82,9 @@ public boolean isString() { } @Override - public String asString() { return node.asText(); } + public String asString() { + return node.asText(); + } @Override public boolean isNumber() { diff --git a/src/main/java/io/lettuce/core/json/JsonArray.java b/src/main/java/io/lettuce/core/json/JsonArray.java index 6297d60b6f..c943373d62 100644 --- a/src/main/java/io/lettuce/core/json/JsonArray.java +++ b/src/main/java/io/lettuce/core/json/JsonArray.java @@ -75,7 +75,7 @@ public interface JsonArray extends JsonValue { JsonValue getFirst(); /** - * Get an {@link Iterator} allowing access to all the {@link JsonValue}s in the array. + * Get an {@link Iterator} allowing access to all the {@link JsonValue}s in the array. * * @return the last {@link JsonValue} in the array or {@code null} if the array is empty */ diff --git a/src/main/java/io/lettuce/core/json/JsonObject.java b/src/main/java/io/lettuce/core/json/JsonObject.java index 0a3682207a..7afd9f1cf1 100644 --- a/src/main/java/io/lettuce/core/json/JsonObject.java +++ b/src/main/java/io/lettuce/core/json/JsonObject.java @@ -35,8 +35,8 @@ public interface JsonObject extends JsonValue { /** - * Add (if there is no value with the same key already) or replace (if there is) a new {@link JsonValue} to the object - * under the provided key. Supports chaining of calls. + * Add (if there is no value with the same key already) or replace (if there is) a new {@link JsonValue} to the object under + * the provided key. Supports chaining of calls. * * @param key the key of the {@link JsonValue} to add or replace * @param element the value to add or replace diff --git a/src/main/java/io/lettuce/core/json/JsonValue.java b/src/main/java/io/lettuce/core/json/JsonValue.java index 2c3e0e6b92..f96ddc212b 100644 --- a/src/main/java/io/lettuce/core/json/JsonValue.java +++ b/src/main/java/io/lettuce/core/json/JsonValue.java @@ -55,20 +55,48 @@ public interface JsonValue { */ ByteBuffer asByteBuffer(); + /** + * @return {@code true} if this {@link JsonValue} represents a JSON array + */ boolean isJsonArray(); + /** + * @return the {@link JsonArray} representation of this {@link JsonValue} + * @see #isJsonArray() + */ JsonArray asJsonArray(); + /** + * @return {@code true} if this {@link JsonValue} represents a JSON object + */ boolean isJsonObject(); + /** + * @return the {@link JsonObject} representation of this {@link JsonValue} + * @see #isJsonObject() + */ JsonObject asJsonObject(); + /** + * @return {@code true} if this {@link JsonValue} represents a JSON string + */ boolean isString(); + /** + * @return the {@link String} representation of this {@link JsonValue} + * @see #isString() + */ String asString(); + /** + * @return {@code true} if this {@link JsonValue} represents a JSON number + */ boolean isNumber(); + /** + * @return the {@link Number} representation of this {@link JsonValue} + * @see #isNumber() + */ Number asNumber(); } diff --git a/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java b/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java index cca5e8df5b..1aebbfb73b 100644 --- a/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java +++ b/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java @@ -36,8 +36,8 @@ public class RedisContainerIntegrationTests { @BeforeAll static void setup() { - RedisURI redisURI = RedisURI.Builder.redis("").withPort(19897) - .withPassword("").withTimeout(Duration.ofSeconds(30)).build(); + RedisURI redisURI = RedisURI.Builder.redis("redis-19897.c55.eu-central-1-1.ec2.redns.redis-cloud.com").withPort(19897) + .withPassword("9CH6niJKjHFzAiPtp9jvoI9OvErZ7urh").withTimeout(Duration.ofSeconds(30)).build(); redisClient = RedisClient.create(redisURI); StatefulRedisConnection connect = redisClient.connect(); redis = connect.async();