Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,21 @@ public RedisFuture<List<JsonValue>> jsonArrpop(K key) {
return dispatch(jsonCommandBuilder.jsonArrpop(key, JsonPath.ROOT_PATH, -1));
}

@Override
public RedisFuture<List<String>> jsonArrpopRaw(K key, JsonPath jsonPath, int index) {
return dispatch(jsonCommandBuilder.jsonArrpopRaw(key, jsonPath, index));
}

@Override
public RedisFuture<List<String>> jsonArrpopRaw(K key, JsonPath jsonPath) {
return dispatch(jsonCommandBuilder.jsonArrpopRaw(key, jsonPath, -1));
}

@Override
public RedisFuture<List<String>> jsonArrpopRaw(K key) {
return dispatch(jsonCommandBuilder.jsonArrpopRaw(key, JsonPath.ROOT_PATH, -1));
}

@Override
public RedisFuture<List<Long>> jsonArrtrim(K key, JsonPath jsonPath, JsonRangeArgs range) {
return dispatch(jsonCommandBuilder.jsonArrtrim(key, jsonPath, range));
Expand All @@ -1827,11 +1842,26 @@ public RedisFuture<Long> jsonDel(K key, JsonPath jsonPath) {
return dispatch(jsonCommandBuilder.jsonDel(key, jsonPath));
}

@Override
public RedisFuture<List<String>> jsonGetRaw(K key, JsonGetArgs options, JsonPath... jsonPaths) {
return dispatch(jsonCommandBuilder.jsonGetRaw(key, options, jsonPaths));
}

@Override
public RedisFuture<List<String>> jsonGetRaw(K key, JsonPath... jsonPaths) {
return dispatch(jsonCommandBuilder.jsonGetRaw(key, JsonGetArgs.Builder.defaults(), jsonPaths));
}

@Override
public RedisFuture<Long> jsonDel(K key) {
return dispatch(jsonCommandBuilder.jsonDel(key, JsonPath.ROOT_PATH));
}

@Override
public RedisFuture<List<String>> jsonMGetRaw(JsonPath jsonPath, K... keys) {
return dispatch(jsonCommandBuilder.jsonMGetRaw(jsonPath, keys));
}

@Override
public RedisFuture<List<JsonValue>> jsonGet(K key, JsonGetArgs options, JsonPath... jsonPaths) {
return dispatch(jsonCommandBuilder.jsonGet(key, options, jsonPaths));
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,21 @@ public Flux<JsonValue> jsonArrpop(K key) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrpop(key, JsonPath.ROOT_PATH, -1));
}

@Override
public Flux<String> jsonArrpopRaw(K key, JsonPath jsonPath, int index) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrpopRaw(key, jsonPath, index));
}

@Override
public Flux<String> jsonArrpopRaw(K key, JsonPath jsonPath) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrpopRaw(key, jsonPath, -1));
}

@Override
public Flux<String> jsonArrpopRaw(K key) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrpopRaw(key, JsonPath.ROOT_PATH, -1));
}

@Override
public Flux<Long> jsonArrtrim(K key, JsonPath jsonPath, JsonRangeArgs range) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrtrim(key, jsonPath, range));
Expand All @@ -1891,6 +1906,17 @@ public Mono<Long> jsonDel(K key, JsonPath jsonPath) {
return createMono(() -> jsonCommandBuilder.jsonDel(key, jsonPath));
}

@Override
public Flux<String> jsonGetRaw(K key, JsonGetArgs options, JsonPath... jsonPaths) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonGetRaw(key, options, jsonPaths));
}

@Override
public Flux<String> jsonGetRaw(K key, JsonPath... jsonPaths) {
final JsonGetArgs args = JsonGetArgs.Builder.defaults();
return createDissolvingFlux(() -> jsonCommandBuilder.jsonGetRaw(key, args, jsonPaths));
}

@Override
public Mono<Long> jsonDel(K key) {
return createMono(() -> jsonCommandBuilder.jsonDel(key, JsonPath.ROOT_PATH));
Expand Down Expand Up @@ -1927,6 +1953,11 @@ public Mono<String> jsonMSet(List<JsonMsetArgs<K, V>> arguments) {
return createMono(() -> jsonCommandBuilder.jsonMSet(arguments));
}

@Override
public Flux<String> jsonMGetRaw(JsonPath jsonPath, K... keys) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonMGetRaw(jsonPath, keys));
}

@Override
public Flux<Number> jsonNumincrby(K key, JsonPath jsonPath, Number number) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonNumincrby(key, jsonPath, number));
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ Command<K, V, List<JsonValue>> jsonArrpop(K key, JsonPath jsonPath, int index) {
return createCommand(JSON_ARRPOP, new JsonValueListOutput<>(codec, parser.get()), args);
}

Command<K, V, List<String>> jsonArrpopRaw(K key, JsonPath jsonPath, int index) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);

if (jsonPath != null) {
if (index != -1) {
// OPTIONAL as per API
args.add(jsonPath.toString());
args.add(index);
} else if (!jsonPath.isRootPath()) {
// OPTIONAL as per API
args.add(jsonPath.toString());
}
}
Comment on lines +175 to +186
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) : Repeats the code in the overloaded method. We can extract it in a helper method to avoid code duplication & eventually getting methods out of sync


return createCommand(JSON_ARRPOP, new StringListOutput<>(codec), args);
}

Command<K, V, List<Long>> jsonArrtrim(K key, JsonPath jsonPath, JsonRangeArgs range) {

notNullKey(key);
Expand Down Expand Up @@ -218,6 +237,28 @@ Command<K, V, List<JsonValue>> jsonGet(K key, JsonGetArgs options, JsonPath... j
return createCommand(JSON_GET, new JsonValueListOutput<>(codec, parser.get()), args);
}

Command<K, V, List<String>> jsonGetRaw(K key, JsonGetArgs options, JsonPath... jsonPaths) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);

if (options != null) {
// OPTIONAL as per API
options.build(args);
}

if (jsonPaths != null) {
// OPTIONAL as per API
for (JsonPath jsonPath : jsonPaths) {
if (jsonPath != null) {
args.add(jsonPath.toString());
}
}
}
Comment on lines +243 to +257
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) : Repeats the code in the overloaded method. We can extract it in a helper method to avoid code duplication & eventually getting methods out of sync


return createCommand(JSON_GET, new StringListOutput<>(codec), args);
}

Command<K, V, String> jsonMerge(K key, JsonPath jsonPath, JsonValue value) {

notNullKey(key);
Expand Down Expand Up @@ -248,6 +289,15 @@ Command<K, V, List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys) {
return createCommand(JSON_MGET, new JsonValueListOutput<>(codec, parser.get()), args);
}

Command<K, V, List<String>> jsonMGetRaw(JsonPath jsonPath, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKeys(keys);
args.add(jsonPath.toString());

return createCommand(JSON_MGET, new StringListOutput<>(codec), args);
}

Command<K, V, String> jsonMSet(List<JsonMsetArgs<K, V>> arguments) {

notEmpty(arguments.toArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonArrpop(K key, JsonPath jsonPath, int index);

/**
* Remove and return the JSON value at a given index in the array at a given {@link JsonPath} as raw JSON strings.
* <p>
* Behaves like {@link #jsonArrpop(Object, JsonPath, int)} but returns {@code List<String>} with raw JSON instead of
* {@link JsonValue} wrappers.
*
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the array inside the document.
* @param index the index of the element to be removed. Default is -1, meaning the last element. Out-of-range indexes round
* to their respective array ends. Popping an empty array returns null.
* @return List<String> the removed element, or null if the specified path is not an array.
* @since 7.0
*/
RedisFuture<List<String>> jsonArrpopRaw(K key, JsonPath jsonPath, int index);

/**
* Remove and return {@link JsonValue} at index -1 (last element) in the array at a given {@link JsonPath}
*
Expand All @@ -187,6 +202,19 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonArrpop(K key, JsonPath jsonPath);

/**
* Remove and return the JSON value at index -1 (last element) in the array at a given {@link JsonPath} as raw JSON strings.
* <p>
* Behaves like {@link #jsonArrpop(Object, JsonPath)} but returns {@code List<String>} with raw JSON instead of
* {@link JsonValue} wrappers.
*
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the array inside the document.
* @return List<String> the removed element, or null if the specified path is not an array.
* @since 7.0
*/
RedisFuture<List<String>> jsonArrpopRaw(K key, JsonPath jsonPath);

/**
* Remove and return {@link JsonValue} at index -1 (last element) in the array at the {@link JsonPath#ROOT_PATH}
*
Expand All @@ -196,6 +224,19 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonArrpop(K key);

/**
* Remove and return the JSON value at index -1 (last element) in the array at the {@link JsonPath#ROOT_PATH} as raw JSON
* strings.
* <p>
* Behaves like {@link #jsonArrpop(Object)} but returns {@code List<String>} with raw JSON instead of {@link JsonValue}
* wrappers.
*
* @param key the key holding the JSON document.
* @return List<String> the removed element, or null if the specified path is not an array.
* @since 7.0
*/
RedisFuture<List<String>> jsonArrpopRaw(K key);

/**
* Trim an array at a given {@link JsonPath} so that it contains only the specified inclusive range of elements. All
* elements with indexes smaller than the start range and all elements with indexes bigger than the end range are trimmed.
Expand Down Expand Up @@ -272,6 +313,20 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonGet(K key, JsonGetArgs options, JsonPath... jsonPaths);

/**
* Return the value at the specified path in JSON serialized form as raw strings.
* <p>
* Behaves like {@link #jsonGet(Object, JsonGetArgs, JsonPath...)} but returns {@code List<String>} with raw JSON instead of
* {@link JsonValue} wrappers.
*
* @param key the key holding the JSON document.
* @param options the {@link JsonGetArgs} to use.
* @param jsonPaths the {@link JsonPath}s to use to identify the values to get.
* @return List<String> the value at path in JSON serialized form, or null if the path does not exist.
* @since 7.0
*/
RedisFuture<List<String>> jsonGetRaw(K key, JsonGetArgs options, JsonPath... jsonPaths);

/**
* Return the value at the specified path in JSON serialized form. Uses defaults for the {@link JsonGetArgs}.
* <p>
Expand All @@ -290,6 +345,19 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonGet(K key, JsonPath... jsonPaths);

/**
* Return the value at the specified path in JSON serialized form as raw strings. Uses defaults for the {@link JsonGetArgs}.
* <p>
* Behaves like {@link #jsonGet(Object, JsonPath...)} but returns {@code List<String>} with raw JSON instead of
* {@link JsonValue} wrappers.
*
* @param key the key holding the JSON document.
* @param jsonPaths the {@link JsonPath}s to use to identify the values to get.
* @return List<String> the value at path in JSON serialized form, or null if the path does not exist.
* @since 7.0
*/
RedisFuture<List<String>> jsonGetRaw(K key, JsonPath... jsonPaths);

/**
* Merge a given {@link JsonValue} with the value matching {@link JsonPath}. Consequently, JSON values at matching paths are
* updated, deleted, or expanded with new children.
Expand Down Expand Up @@ -335,6 +403,19 @@ public interface RedisJsonAsyncCommands<K, V> {
*/
RedisFuture<List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys);

/**
* Return the values at the specified path from multiple key arguments as raw JSON strings.
* <p>
* Behaves like {@link #jsonMGet(JsonPath, Object[])} but returns {@code List<String>} with raw JSON instead of
* {@link JsonValue} wrappers.
*
* @param jsonPath the {@link JsonPath} pointing to the value to fetch.
* @param keys the keys holding the values to fetch.
* @return List<String> the values at path, or null if the path does not exist.
* @since 7.0
*/
RedisFuture<List<String>> jsonMGetRaw(JsonPath jsonPath, K... keys);

/**
* Set or update one or more JSON values according to the specified {@link JsonMsetArgs}
* <p>
Expand Down
Loading