Skip to content

Commit

Permalink
Node: Add command JSON.GET and JSON.SET
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Zhang <[email protected]>
  • Loading branch information
TJ Zhang committed Oct 8, 2024
1 parent abc8666 commit c7f1269
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4141,3 +4141,54 @@ export function createScriptFlush(mode?: FlushMode): command_request.Command {
export function createScriptKill(): command_request.Command {
return createCommand(RequestType.ScriptKill, []);
}

/** Represents options for formatting JSON data, to be used in the [JSON.GET](https://redis.io/commands/json.get/) command.
Args:
indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None. */
export type JsonGetOptions = {
paths?: string | string[];
indent?: string;
newline?: string;
space?: string;
};

function jsonGetOptionsToArgs(options: JsonGetOptions): string[] {
const result: string[] = [];

if (options.paths !== undefined) {
result.push(...options.paths);
}

if (options.indent !== undefined) {
result.push("INDENT", options.indent);
}

if (options.newline !== undefined) {
result.push("NEWLINE", options.newline);
}

if (options.space !== undefined) {
result.push("SPACE", options.space);
}

return result;
}

/**
* @internal
*/
export function createJsonGet(
key: string,
options?: JsonGetOptions,
): command_request.Command {
if (options) {
return createCommand(
RequestType.ScriptFlush,
jsonGetOptionsToArgs(options),
);
} else {
return createCommand(RequestType.ScriptFlush, []);
}
}

0 comments on commit c7f1269

Please sign in to comment.