Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Aug 2, 2024
1 parent c4dc288 commit 127d29e
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,6 +82,7 @@
* @author dengliming
* @author Andrey Shlykov
* @author Ali Takavci
* @author Tihomir Mateev
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/lettuce/core/RedisAsyncCommandsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,6 +17,8 @@
public class RedisAsyncCommandsImpl<K, V> extends AbstractRedisAsyncCommands<K, V>
implements RedisAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V> {

private final RedisCodec<K,V> codec;

/**
* Initialize a new instance.
*
Expand All @@ -24,11 +28,22 @@ public class RedisAsyncCommandsImpl<K, V> extends AbstractRedisAsyncCommands<K,
*/
public RedisAsyncCommandsImpl(StatefulRedisConnection<K, V> connection, RedisCodec<K, V> codec) {
super(connection, codec);
this.codec = codec;
}

@Override
public StatefulRedisConnection<K, V> getStatefulConnection() {
return (StatefulRedisConnection<K, V>) super.getConnection();
}

@Override
public JsonParser<K, V> getJsonParser() {
return JsonParserRegistry.getJsonParser(this.codec);
}

@Override
public void setJsonParser(JsonParser<K, V> jsonParser) {
throw new UnsupportedOperationException("Setting a custom JsonParser is not supported");
}

}
6 changes: 3 additions & 3 deletions src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Command<K, V, List<Long>> jsonArrappend(K key, JsonPath jsonPath, JsonValue<K, V
}

for (JsonValue<K, V> value : jsonValues) {
args.addValue(value.toValue());
args.add(value.asByteBuffer().array());
}

return createCommand(JSON_ARRAPPEND, new IntegerListOutput<>(codec), args);
Expand All @@ -88,7 +88,7 @@ RedisCommand<K, V, List<Long>> 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
Expand Down Expand Up @@ -208,7 +208,7 @@ RedisCommand<K, V, String> jsonSet(K key, JsonPath jsonPath, JsonValue<K, V> val
args.add(jsonPath.toString());
}

args.addValue(value.toValue());
args.add(value.asByteBuffer().array());

if (options != null) {
options.build(args);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/lettuce/core/RedisReactiveCommandsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,6 +17,8 @@
public class RedisReactiveCommandsImpl<K, V> extends AbstractRedisReactiveCommands<K, V>
implements RedisReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V> {

private final RedisCodec<K,V> codec;

/**
* Initialize a new instance.
*
Expand All @@ -24,11 +28,22 @@ public class RedisReactiveCommandsImpl<K, V> extends AbstractRedisReactiveComman
*/
public RedisReactiveCommandsImpl(StatefulRedisConnection<K, V> connection, RedisCodec<K, V> codec) {
super(connection, codec);
this.codec = codec;
}

@Override
public StatefulRedisConnection<K, V> getStatefulConnection() {
return (StatefulRedisConnection<K, V>) super.getConnection();
}

@Override
public JsonParser<K, V> getJsonParser() {
return JsonParserRegistry.getJsonParser(this.codec);
}

@Override
public void setJsonParser(JsonParser<K, V> jsonParser) {
throw new UnsupportedOperationException("Setting a custom JsonParser is not supported");
}

}
10 changes: 0 additions & 10 deletions src/main/java/io/lettuce/core/StatefulRedisConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ public void removeListener(PushListener listener) {
pushHandler.removeListener(listener);
}

@Override
public JsonParser<K, V> getJsonParser() {
return JsonParserRegistry.getJsonParser(this.codec);
}

@Override
public void setJsonParser(JsonParser<K, V> jsonParser) {
throw new UnsupportedOperationException("Setting a custom JsonParser is not supported");
}

@Override
public boolean isMulti() {
return multi != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,4 @@ public interface StatefulRedisConnection<K, V> extends StatefulConnection<K, V>
*/
void removeListener(PushListener listener);

JsonParser<K, V> getJsonParser();

void setJsonParser(JsonParser<K, V> jsonParser);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -81,4 +82,8 @@ public interface RedisAsyncCommands<K, V> extends BaseRedisAsyncCommands<K, V>,
@Deprecated
StatefulRedisConnection<K, V> getStatefulConnection();

JsonParser<K, V> getJsonParser();

void setJsonParser(JsonParser<K, V> jsonParser);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -81,4 +82,8 @@ public interface RedisReactiveCommands<K, V> extends BaseRedisReactiveCommands<K
@Deprecated
StatefulRedisConnection<K, V> getStatefulConnection();

JsonParser<K, V> getJsonParser();

void setJsonParser(JsonParser<K, V> jsonParser);

}
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import io.lettuce.core.json.JsonParser;

/**
*
Expand Down Expand Up @@ -80,4 +81,8 @@ public interface RedisCommands<K, V> extends BaseRedisCommands<K, V>, RedisAclCo
@Deprecated
StatefulRedisConnection<K, V> getStatefulConnection();

JsonParser<K, V> getJsonParser();

void setJsonParser(JsonParser<K, V> jsonParser);

}
4 changes: 3 additions & 1 deletion src/main/java/io/lettuce/core/json/DelegateJsonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public boolean isString() {
}

@Override
public String asString() { return node.asText(); }
public String asString() {
return node.asText();
}

@Override
public boolean isNumber() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/json/JsonArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface JsonArray<K, V> extends JsonValue<K, V> {
JsonValue<K, V> 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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/json/JsonObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
public interface JsonObject<K, V> extends JsonValue<K, V> {

/**
* 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
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/io/lettuce/core/json/JsonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,48 @@ public interface JsonValue<K, V> {
*/
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<K, V> 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<K, V> 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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> connect = redisClient.connect();
redis = connect.async();
Expand Down

0 comments on commit 127d29e

Please sign in to comment.