Skip to content

Commit

Permalink
Java: add JSON.SET and JSON.GET (#2462)
Browse files Browse the repository at this point in the history
* Java: add JSON.SET and JSON.GET

---------

Signed-off-by: James Xin <james.xin@improving.com>
  • Loading branch information
jamesx-improving authored Oct 17, 2024
1 parent 1125eba commit adcc76f
Show file tree
Hide file tree
Showing 8 changed files with 1,078 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Java: Added `FT.CREATE` ([#2414](https://github.com/valkey-io/valkey-glide/pull/2414))
* Java: Added `FT.DROPINDEX` ([#2440](https://github.com/valkey-io/valkey-glide/pull/2440))
* Java: Added `FT.SEARCH` ([#2439](https://github.com/valkey-io/valkey-glide/pull/2439))
* Java: Added `JSON.SET` and `JSON.GET` ([#2462](https://github.com/valkey-io/valkey-glide/pull/2462))
* Core: Update routing for commands from server modules ([#2461](https://github.com/valkey-io/valkey-glide/pull/2461))

#### Breaking Changes
Expand Down
460 changes: 460 additions & 0 deletions java/client/src/main/java/glide/api/commands/servermodules/Json.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands.json;

import glide.api.commands.servermodules.Json;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;

/** Additional parameters for {@link Json#get} command. */
@Builder
public final class JsonGetOptions {
/** ValKey API string to designate INDENT */
public static final String INDENT_VALKEY_API = "INDENT";

/** ValKey API string to designate NEWLINE */
public static final String NEWLINE_VALKEY_API = "NEWLINE";

/** ValKey API string to designate SPACE */
public static final String SPACE_VALKEY_API = "SPACE";

/** ValKey API string to designate SPACE */
public static final String NOESCAPE_VALKEY_API = "NOESCAPE";

/** Sets an indentation string for nested levels. */
private String indent;

/** Sets a string that's printed at the end of each line. */
private String newline;

/** Sets a string that's put between a key and a value. */
private String space;

/** Allowed to be present for legacy compatibility and has no other effect. */
private boolean noescape;

/**
* Converts JsonGetOptions into a String[].
*
* @return String[]
*/
public String[] toArgs() {
List<String> args = new ArrayList<>();
if (indent != null) {
args.add(INDENT_VALKEY_API);
args.add(indent);
}

if (newline != null) {
args.add(NEWLINE_VALKEY_API);
args.add(newline);
}

if (space != null) {
args.add(SPACE_VALKEY_API);
args.add(space);
}

if (noescape) {
args.add(NOESCAPE_VALKEY_API);
}

return args.toArray(new String[0]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands.json;

import static glide.api.models.GlideString.gs;

import glide.api.commands.servermodules.Json;
import glide.api.models.GlideString;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;

/** GlideString version of additional parameters for {@link Json#get} command. */
@Builder
public final class JsonGetOptionsBinary {
/** ValKey API string to designate INDENT */
public static final GlideString INDENT_VALKEY_API = gs("INDENT");

/** ValKey API string to designate NEWLINE */
public static final GlideString NEWLINE_VALKEY_API = gs("NEWLINE");

/** ValKey API string to designate SPACE */
public static final GlideString SPACE_VALKEY_API = gs("SPACE");

/** ValKey API string to designate SPACE */
public static final GlideString NOESCAPE_VALKEY_API = gs("NOESCAPE");

/** Sets an indentation string for nested levels. */
private GlideString indent;

/** Sets a string that's printed at the end of each line. */
private GlideString newline;

/** Sets a string that's put between a key and a value. */
private GlideString space;

/** Allowed to be present for legacy compatibility and has no other effect. */
private boolean noescape;

/**
* Converts JsonGetOptions into a GlideString[].
*
* @return GlideString[]
*/
public GlideString[] toArgs() {
List<GlideString> args = new ArrayList<>();
if (indent != null) {
args.add(INDENT_VALKEY_API);
args.add(indent);
}

if (newline != null) {
args.add(NEWLINE_VALKEY_API);
args.add(newline);
}

if (space != null) {
args.add(SPACE_VALKEY_API);
args.add(space);
}

if (noescape) {
args.add(NOESCAPE_VALKEY_API);
}

return args.toArray(new GlideString[0]);
}
}
1 change: 1 addition & 0 deletions java/client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
exports glide.api.models.commands.scan;
exports glide.api.models.commands.stream;
exports glide.api.models.commands.FT;
exports glide.api.models.commands.json;
exports glide.api.models.configuration;
exports glide.api.models.exceptions;
exports glide.api.commands.servermodules;
Expand Down
Loading

0 comments on commit adcc76f

Please sign in to comment.