Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 6ec9d18

Browse files
committed
docs: add documentation
1 parent ee90fee commit 6ec9d18

File tree

2 files changed

+114
-39
lines changed

2 files changed

+114
-39
lines changed

docs/src/content/docs/commands/JSON.DEBUG.md

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,90 @@ description: Documentation for the DiceDB command JSON.DEBUG
55

66
The `JSON.DEBUG` command in DiceDB is part of the DiceDBJSON module, which allows for the manipulation and querying of JSON data stored in DiceDB. This command is primarily used for debugging purposes, providing insights into the internal representation of JSON data within DiceDB.
77

8-
## Parameters
9-
10-
### Syntax
8+
## Syntax
119

1210
```bash
1311
JSON.DEBUG <subcommand> <key> [path]
1412
```
1513

16-
### Parameters Description
14+
## Parameters
1715

18-
- `subcommand`: (Required) The specific debug operation to perform. Currently, the supported subcommand is `MEMORY`.
19-
- `key`: (Required) The key under which the JSON data is stored.
20-
- `path`: (Optional) The JSON path to the specific part of the JSON data to debug. Defaults to the root if not provided.
16+
| Parameter | Description | Type | Required |
17+
| --------- | --------------------------------------------------------------------------------------- | ------ | -------- |
18+
| `subcommand` | The specific debug operation to perform. Currently, the supported subcommand is `MEMORY`. | String | Yes |
19+
| `key` | The key under which the JSON data is stored. | String | Yes |
20+
| `path` | The JSON path to the specific part of the JSON data to debug. Defaults to the root if not provided. | String | No |
2121

2222
### Subcommands
2323

2424
- `MEMORY`: This subcommand returns the memory usage of the JSON value at the specified path.
2525

2626
## Return Value
2727

28-
The return value of the `JSON.DEBUG` command depends on the subcommand used:
29-
30-
- `MEMORY`: Returns an integer representing the memory usage in bytes of the JSON value at the specified path.
28+
| Condition | Return Value |
29+
| ----------------------- | ----------------------------------- |
30+
| if `MEMORY` subcommand is used | Memory usage in bytes of the JSON value at the specified path. |
3131

3232
## Behaviour
3333

34-
When the `JSON.DEBUG` command is executed, DiceDB will perform the specified debug operation on the JSON data stored at the given key and path. For the `MEMORY` subcommand, it will calculate and return the memory usage of the JSON value at the specified path. If the path is not provided, it defaults to the root of the JSON data.
34+
- For the `MEMORY` subcommand, it will calculate and return the memory usage of the JSON value at the specified path.
35+
- If the path is not provided, it defaults to the root of the JSON data.
3536

3637
## Errors
3738

38-
The `JSON.DEBUG` command can raise errors in the following scenarios:
39-
40-
1. `Invalid Subcommand`: If an unsupported subcommand is provided, DiceDB will return an error.
41-
42-
- `Error Message`: `ERR unknown subcommand '<subcommand>'`
43-
44-
2. `Non-Existent Key`: If the specified key does not exist in the DiceDB database, DiceDB will return an error.
45-
46-
- `Error Message`: `ERR no such key`
47-
48-
3. `Invalid Path`: If the specified path does not exist within the JSON data, DiceDB will return an error.
39+
1. `Invalid Subcommand`:
40+
- Error Message: `ERR unknown subcommand '<subcommand>'`
41+
- Occurs when an unsupported subcommand is provided.
42+
43+
2. `Invalid Path`:
44+
- Error Message: `ERR Path '<path>' does not exist`
45+
- If the specified path does not exist within the JSON data, DiceDB will return an error.
4946

50-
- `Error Message`: `ERR path '<path>' does not exist`
51-
52-
4. `Wrong Type`: If the key exists but does not hold JSON data, DiceDB will return an error.
53-
54-
- `Error Message`: `WRONGTYPE Operation against a key holding the wrong kind of value`
47+
4. `Wrong Type`:
48+
- Error Message: `WRONGTYPE Operation against a key holding the wrong kind of value`
49+
- If the key exists but does not hold JSON data, DiceDB will return an error.
5550

5651
## Example Usage
5752

5853
### Debugging Memory Usage of Entire JSON Data
5954

55+
The `JSON.DEBUG MEMORY` command is used to get the memory usage of the entire JSON data stored under the key `myjson`. The command returns `89`, indicating that the JSON data occupies 89 bytes of memory.
56+
6057
```bash
58+
127.0.0.1:7379> JSON.SET myjson $ '{"a":1}',
59+
OK
6160
127.0.0.1:7379> JSON.DEBUG MEMORY myjson
62-
(integer) 256
61+
(integer) 89
6362
```
6463

65-
In this example, the `JSON.DEBUG MEMORY` command is used to get the memory usage of the entire JSON data stored under the key `myjson`. The command returns `256`, indicating that the JSON data occupies 256 bytes of memory.
66-
6764
### Debugging Memory Usage of a Specific Path
6865

66+
The `JSON.DEBUG MEMORY` command is used to get the memory usage of the JSON value at the path `$.a` within the JSON data stored under the key `myjson`. The command returns `16`, indicating that the specified JSON value occupies 16 bytes of memory.
6967
```bash
70-
127.0.0.1:7379> JSON.DEBUG MEMORY myjson $.store.book[0]
71-
(integer) 64
68+
127.0.0.1:7379> JSON.SET myjson $ '{"a":1,"b":2}',
69+
OK
70+
127.0.0.1:7379> JSON.DEBUG MEMORY myjson $.a
71+
1) (integer) 16
7272
```
7373

74-
In this example, the `JSON.DEBUG MEMORY` command is used to get the memory usage of the JSON value at the path `$.store.book[0]` within the JSON data stored under the key `myjson`. The command returns `64`, indicating that the specified JSON value occupies 64 bytes of memory.
75-
7674
### Handling Non-Existent Key
7775

76+
The `JSON.DEBUG MEMORY` command is used on a non-existent key `nonExistentKey`. DiceDB returns an 0 indicating that the key does not exist.
77+
7878
```bash
7979
127.0.0.1:7379> JSON.DEBUG MEMORY nonExistentKey
80-
(error) ERR no such key
80+
(integer) 0
8181
```
8282

83-
In this example, the `JSON.DEBUG MEMORY` command is used on a non-existent key `nonExistentKey`. DiceDB returns an error indicating that the key does not exist.
84-
8583
### Handling Invalid Path
8684

85+
The `JSON.DEBUG MEMORY` command is used on an invalid path `$.nonExistentPath` within the JSON data stored under the key `myjson`. DiceDB returns an error indicating that the specified path does not exist.
86+
8787
```bash
8888
127.0.0.1:7379> JSON.DEBUG MEMORY myjson $.nonExistentPath
89-
(error) ERR path '$.nonExistentPath' does not exist
89+
(error) ERR Path '$.nonExistentPath' does not exist
9090
```
9191

92-
In this example, the `JSON.DEBUG MEMORY` command is used on an invalid path `$.nonExistentPath` within the JSON data stored under the key `myjson`. DiceDB returns an error indicating that the specified path does not exist.
92+
## Notes
93+
94+
- JSONPath expressions are used to navigate and specify the location within the JSON document. Familiarity with JSONPath syntax is beneficial for effective use of this command.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: JSON.RESP
3+
description: Documentation for the DiceDB command JSON.RESP
4+
---
5+
6+
The `JSON.RESP` command in DiceDB is part of the DiceDBJSON module, which returns the JSON in the specified key in Redis Serialization Protocol Specification (RESP) form.
7+
8+
## Syntax
9+
10+
```bash
11+
JSON.RESP <key> [path]
12+
```
13+
14+
## Parameters
15+
16+
| Parameter | Description | Type | Required |
17+
| --------- | --------------------------------------------------------------------------------------- | ------ | -------- |
18+
| `key` | The key under which the JSON data is stored. | String | Yes |
19+
| `path` | The JSON path to the specific part of the JSON data to fetch. Defaults to the root if not provided. | String | No |
20+
21+
## Return Value
22+
23+
| Condition | Return Value |
24+
| ----------------------- | ----------------------------------- |
25+
| if `path` is provided | JSON value at the specified path in RESP form. |
26+
27+
## Behaviour
28+
29+
- If the path is not provided, it defaults to the root of the JSON data.
30+
31+
## Errors
32+
33+
1. `Wrong Type`:
34+
- Error Message: `WRONGTYPE Operation against a key holding the wrong kind of value`
35+
- If the key exists but does not hold JSON data, DiceDB will return an error.
36+
37+
## Example Usage
38+
39+
### JSON.RESP on array
40+
41+
The `JSON.RESP` command returns the entire JSON data stored under the key `arrayjson` in RESP form.
42+
43+
```bash
44+
127.0.0.1:7379> JSON.SET arrayjson $ '["dice",10,10.5,true,null]'
45+
OK
46+
127.0.0.1:7379> JSON.RESP
47+
1) [
48+
2) "dice"
49+
3) (integer) 10
50+
4) "10.5"
51+
5) true
52+
6) (nil)
53+
```
54+
55+
### JSON.RESP on nested JSON
56+
57+
The `JSON.RESP` command returns the JSON data stored under the key `myjson` at `$.b` in RESP form.
58+
59+
```bash
60+
127.0.0.1:7379> JSON.SET myjson $ '{"a":100,"b":["dice",10,10.5,true,null]}'
61+
OK
62+
127.0.0.1:7379> JSON.RESP myjson $.b
63+
1) 1) [
64+
2) "dice"
65+
3) (integer) 10
66+
4) "10.5"
67+
5) true
68+
6) (nil)
69+
```
70+
71+
## Notes
72+
73+
- JSONPath expressions are used to navigate and specify the location within the JSON document. Familiarity with JSONPath syntax is beneficial for effective use of this command.

0 commit comments

Comments
 (0)