Skip to content

Commit ae68952

Browse files
roshkhatrizackcamKarthikSubbaraoNikhil-Mangloremadolson
authored
Adds valkey-json module commands documentation to the website. (#243)
One of the three PRs Required for module documentation to be included on the website Related PRs: valkey-io/valkey-json#42 Will wait for valkey-io/valkey-io.github.io#212 to het merged so we can use the framework to display documentation We have merged the bloom changes in PR too as it depends on that, we would only review the changes related to JSON for this PR --------- Signed-off-by: zackcam <[email protected]> Signed-off-by: Nikhil Manglore <[email protected]> Signed-off-by: Roshan Khatri <[email protected]> Signed-off-by: Nikhil Manglore <[email protected]> Signed-off-by: Roshan Khatri <[email protected]> Signed-off-by: Madelyn Olson <[email protected]> Co-authored-by: zackcam <[email protected]> Co-authored-by: KarthikSubbarao <[email protected]> Co-authored-by: Nikhil Manglore <[email protected]> Co-authored-by: Nikhil Manglore <[email protected]> Co-authored-by: Madelyn Olson <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent ec1d172 commit ae68952

32 files changed

+1887
-7
lines changed

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ DATE ?= 2025-03-31
99
# Path to the code repo.
1010
VALKEY_ROOT ?= ../valkey
1111
VALKEY_BLOOM_ROOT ?= ../valkey-bloom
12+
VALKEY_JSON_ROOT ?= ../valkey-json
13+
1214
# Where to install man pages
1315
INSTALL_MAN_DIR ?= /usr/local/share/man
1416

@@ -34,6 +36,10 @@ ifeq ("$(wildcard $(VALKEY_BLOOM_ROOT))","")
3436
$(info Valkey bloom variable pointed to nothing, skipping bloom filter commands)
3537
endif
3638

39+
ifeq ("$(wildcard $(VALKEY_JSON_ROOT))","")
40+
$(error Please provide the VALKEY_JSON_ROOT variable pointing to the valkey-json source code)
41+
endif
42+
3743
ifeq ("$(shell which pandoc)","")
3844
$(error Please install pandoc)
3945
endif
@@ -58,9 +64,12 @@ endif
5864

5965
documented_commands = $(wildcard commands/*.md)
6066
commands_json_files = $(wildcard $(VALKEY_ROOT)/src/commands/*.json)
67+
6168
bloom_commands_json_files = $(wildcard $(VALKEY_BLOOM_ROOT)/src/commands/*.json)
69+
valkey_json_commands_json_files = $(wildcard $(VALKEY_JSON_ROOT)/src/commands/*.json)
6270
existing_commands = $(commands_json_files:$(VALKEY_ROOT)/src/commands/%.json=commands/%.md) \
63-
$(bloom_commands_json_files:$(VALKEY_BLOOM_ROOT)/src/commands/%.json=commands/%.md)
71+
$(bloom_commands_json_files:$(VALKEY_BLOOM_ROOT)/src/commands/%.json=commands/%.md) \
72+
$(valkey_json_commands_json_files:$(VALKEY_JSON_ROOT)/src/commands/%.json=commands/%.md)
6473

6574
topics = $(wildcard topics/*)
6675
commands = $(filter $(existing_commands),$(documented_commands))
@@ -73,7 +82,8 @@ topics_pics = $(filter-out %.md,$(topics))
7382
# JSON files for the commands that have a .md file (excluding undocumented commands).
7483
json_for_documented_commands = \
7584
$(patsubst commands/%.md,$(VALKEY_ROOT)/src/commands/%.json,$(filter $(commands_json_files:$(VALKEY_ROOT)/src/commands/%.json=commands/%.md),$(commands))) \
76-
$(patsubst commands/%.md,$(VALKEY_BLOOM_ROOT)/src/commands/%.json,$(filter $(bloom_commands_json_files:$(VALKEY_BLOOM_ROOT)/src/commands/%.json=commands/%.md),$(commands)))
85+
$(patsubst commands/%.md,$(VALKEY_BLOOM_ROOT)/src/commands/%.json,$(filter $(bloom_commands_json_files:$(VALKEY_BLOOM_ROOT)/src/commands/%.json=commands/%.md),$(commands))) \
86+
$(patsubst commands/%.md,$(VALKEY_JSON_ROOT)/src/commands/%.json,$(filter $(valkey_json_commands_json_files:$(VALKEY_JSON_ROOT)/src/commands/%.json=commands/%.md),$(commands)))
7787

7888
$(BUILD_DIR)/.commands-per-group.json: $(VALKEY_ROOT)/src/commands/. utils/build-command-groups.py | $(BUILD_DIR)
7989
utils/build-command-groups.py $(json_for_documented_commands) > $@~~
@@ -187,13 +197,14 @@ $(MAN_DIR)/man1/valkey-%.1.gz: topics/%.md $(man_scripts)
187197
--version $(VERSION) --date $(DATE) \$< \
188198
| utils/links-to-man.py - | $(to_man) > $@
189199
$(MAN_DIR)/man3/%.3valkey.gz: commands/%.md $(BUILD_DIR)/.commands-per-group.json $(man_scripts)
200+
$(eval VALKEY_ROOTS := $(VALKEY_ROOT) $(VALKEY_JSON_ROOT))
190201
$(eval FINAL_ROOT := $(firstword $(foreach root,$(VALKEY_ROOTS),$(if $(wildcard $(root)/src/commands/$*.json),$(root)))))
191-
$(if $(FINAL_ROOT), \
202+
$(if $(FINAL_ROOT),,$(eval FINAL_ROOT := $(lastword $(VALKEY_ROOTS))))
192203
utils/preprocess-markdown.py --man --page-type command \
193204
--version $(VERSION) --date $(DATE) \
194205
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
195206
--valkey-root $(FINAL_ROOT) $< \
196-
| utils/links-to-man.py - | $(to_man) > $@)
207+
| utils/links-to-man.py - | $(to_man) > $@
197208
$(MAN_DIR)/man5/%.5.gz: topics/%.md $(man_scripts)
198209
utils/preprocess-markdown.py --man --page-type config \
199210
--version $(VERSION) --date $(DATE) $< \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ for generating content for the website and man pages.
77

88
This repo comes with a Makefile to build and install man pages.
99

10-
make VALKEY_ROOT=path/to/valkey VALKEY_BLOOM_ROOT=path/to/valkey-bloom
10+
make VALKEY_ROOT=path/to/valkey VALKEY_BLOOM_ROOT=path/to/valkey-bloom VALKEY_JSON_ROOT=path/to/valkey-json
1111
sudo make install INSTALL_MAN_DIR=/usr/local/share/man
1212

1313
Prerequisites: GNU Make, Python 3, Python 3 YAML (pyyaml), Pandoc.
1414
Additionally, the scripts need access to the valkey code repo,
1515
where metadata files about the commands are stored. Additionally
16-
access to the valkey-bloom repo is optional.
16+
access to the valkey-bloom and valkey-json repos are optional.
1717

1818
The pages are generated under `_build/man/` by default. The default install
1919
location is `/usr/local/share/man` (in the appropriate subdirectories).

commands/json.arrappend.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Append one or more values to the array values at the path.
2+
3+
## Examples
4+
5+
Enhanced path syntax:
6+
7+
```bash
8+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
9+
OK
10+
127.0.0.1:6379> JSON.ARRAPPEND k1 $[*] '"c"'
11+
1) (integer) 1
12+
2) (integer) 2
13+
3) (integer) 3
14+
127.0.0.1:6379> JSON.GET k1
15+
"[[\"c\"],[\"a\",\"c\"],[\"a\",\"b\",\"c\"]]"
16+
```
17+
18+
Restricted path syntax:
19+
20+
```bash
21+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
22+
OK
23+
127.0.0.1:6379> JSON.ARRAPPEND k1 [-1] '"c"'
24+
(integer) 3
25+
127.0.0.1:6379> JSON.GET k1
26+
"[[],[\"a\"],[\"a\",\"b\",\"c\"]]"
27+
```

commands/json.arrindex.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Search for the first occurrence of a scalar JSON value in the arrays at the path.
2+
3+
4+
* Out of range errors are treated by rounding the index to the array's start and end.
5+
* If start > end, return -1 (not found).
6+
7+
## Examples
8+
9+
Enhanced path syntax:
10+
11+
```bash
12+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
13+
OK
14+
127.0.0.1:6379> JSON.ARRINDEX k1 $[*] '"b"'
15+
1) (integer) -1
16+
2) (integer) -1
17+
3) (integer) 1
18+
4) (integer) 1
19+
```
20+
21+
Restricted path syntax:
22+
23+
```bash
24+
127.0.0.1:6379> JSON.SET k1 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}'
25+
OK
26+
127.0.0.1:6379> JSON.ARRINDEX k1 .children '"Tom"'
27+
(integer) 2
28+
```

commands/json.arrinsert.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Insert one or more values into the array values at path before the index.
2+
3+
4+
* Inserting at index 0 prepends to the array.
5+
* A negative index values is interpreted as starting from the end.
6+
* The index must be in the array's boundary.
7+
8+
## Examples
9+
10+
Enhanced path syntax:
11+
12+
```bash
13+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
14+
OK
15+
127.0.0.1:6379> JSON.ARRINSERT k1 $[*] 0 '"c"'
16+
1) (integer) 1
17+
2) (integer) 2
18+
3) (integer) 3
19+
127.0.0.1:6379> JSON.GET k1
20+
"[[\"c\"],[\"c\",\"a\"],[\"c\",\"a\",\"b\"]]"
21+
```
22+
23+
Restricted path syntax:
24+
25+
```bash
26+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
27+
OK
28+
127.0.0.1:6379> JSON.ARRINSERT k1 . 0 '"c"'
29+
(integer) 4
30+
127.0.0.1:6379> JSON.GET k1
31+
"[\"c\",[],[\"a\"],[\"a\",\"b\"]]"
32+
```

commands/json.arrlen.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Get length of the array at the path.
2+
3+
## Examples
4+
5+
Enhanced path syntax:
6+
7+
```bash
8+
127.0.0.1:6379> JSON.SET k1 . '[[], [\"a\"], [\"a\", \"b\"], [\"a\", \"b\", \"c\"]]'
9+
(error) SYNTAXERR Failed to parse JSON string due to syntax error
10+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
11+
OK
12+
127.0.0.1:6379> JSON.ARRLEN k1 $[*]
13+
1) (integer) 0
14+
2) (integer) 1
15+
3) (integer) 2
16+
4) (integer) 3
17+
18+
127.0.0.1:6379> JSON.SET k2 . '[[], "a", ["a", "b"], ["a", "b", "c"], 4]'
19+
OK
20+
127.0.0.1:6379> JSON.ARRLEN k2 $[*]
21+
1) (integer) 0
22+
2) (nil)
23+
3) (integer) 2
24+
4) (integer) 3
25+
5) (nil)
26+
```
27+
28+
```bash
29+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
30+
OK
31+
127.0.0.1:6379> JSON.ARRLEN k1 [*]
32+
(integer) 0
33+
127.0.0.1:6379> JSON.ARRLEN k1 $[3]
34+
1) (integer) 3
35+
36+
127.0.0.1:6379> JSON.SET k2 . '[[], "a", ["a", "b"], ["a", "b", "c"], 4]'
37+
OK
38+
127.0.0.1:6379> JSON.ARRLEN k2 [*]
39+
(integer) 0
40+
127.0.0.1:6379> JSON.ARRLEN k2 $[1]
41+
1) (nil)
42+
127.0.0.1:6379> JSON.ARRLEN k2 $[2]
43+
1) (integer) 2
44+
```

commands/json.arrpop.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Remove and return element at the index from the array. Popping an empty array returns null.
2+
3+
## Examples
4+
5+
Enhanced path syntax:
6+
7+
```bash
8+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
9+
OK
10+
127.0.0.1:6379> JSON.ARRPOP k1 $[*]
11+
1) (nil)
12+
2) "\"a\""
13+
3) "\"b\""
14+
127.0.0.1:6379> JSON.GET k1
15+
"[[],[],[\"a\"]]"
16+
```
17+
18+
Restricted path syntax:
19+
20+
```bash
21+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
22+
OK
23+
127.0.0.1:6379> JSON.ARRPOP k1
24+
"[\"a\",\"b\"]"
25+
127.0.0.1:6379> JSON.GET k1
26+
"[[],[\"a\"]]"
27+
28+
127.0.0.1:6379> JSON.SET k2 . '[[], ["a"], ["a", "b"]]'
29+
OK
30+
127.0.0.1:6379> JSON.ARRPOP k2 . 0
31+
"[]"
32+
127.0.0.1:6379> JSON.GET k2
33+
"[[\"a\"],[\"a\",\"b\"]]"
34+
```

commands/json.arrtrim.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Trim arrays at the path so that it becomes subarray [start, end], both inclusive.
2+
3+
4+
* If the array is empty, do nothing, return 0.
5+
* If start < 0, treat it as 0.
6+
* If end >= size (size of the array), treat it as size-1.
7+
* If start >= size or start > end, empty the array and return 0.
8+
9+
## Examples
10+
11+
Enhanced path syntax:
12+
13+
```bash
14+
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
15+
OK
16+
127.0.0.1:6379> JSON.ARRTRIM k1 $[*] 0 1
17+
1) (integer) 0
18+
2) (integer) 1
19+
3) (integer) 2
20+
4) (integer) 2
21+
127.0.0.1:6379> JSON.GET k1
22+
"[[],[\"a\"],[\"a\",\"b\"],[\"a\",\"b\"]]"
23+
```
24+
25+
Restricted path syntax:
26+
27+
```bash
28+
127.0.0.1:6379> JSON.SET k1 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}'
29+
OK
30+
127.0.0.1:6379> JSON.ARRTRIM k1 .children 0 1
31+
(integer) 2
32+
127.0.0.1:6379> JSON.GET k1 .children
33+
"[\"John\",\"Jack\"]"
34+
```

commands/json.clear.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Clear the arrays or objects at the path.
2+
3+
## Examples
4+
5+
```bash
6+
127.0.0.1:6379> JSON.SET k1 . '[[], [0], [0,1], [0,1,2], 1, true, null, "d"]'
7+
OK
8+
127.0.0.1:6379> JSON.CLEAR k1 $[*]
9+
(integer) 6
10+
127.0.0.1:6379> JSON.CLEAR k1 $[*]
11+
(integer) 0
12+
127.0.0.1:6379> JSON.SET k2 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}'
13+
OK
14+
127.0.0.1:6379> JSON.CLEAR k2 .children
15+
(integer) 1
16+
127.0.0.1:6379> JSON.GET k2 .children
17+
"[]"
18+
```

commands/json.debug.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Report information. Supported subcommands are:
2+
3+
4+
* MEMORY <key> [path] - report memory usage in bytes of a JSON value. Path defaults to the root if not provided.
5+
* DEPTH <key> - report the maximum path depth of the JSON document.
6+
* FIELDS <key> [path] - report the number of fields at the specified document path. Path defaults to the root if not provided.
7+
Each non-container JSON value counts as one field. Objects and arrays recursively count one field for each of their
8+
containing JSON values. Each container value, except the root container, counts as one additional field.
9+
* HELP - print help messages of the command.
10+
11+
## Examples
12+
13+
Enhanced path syntax:
14+
15+
```bash
16+
127.0.0.1:6379> JSON.SET k1 . '[1, 2.3, "foo", true, null, {}, [], {"a":1, "b":2}, [1,2,3]]'
17+
OK
18+
127.0.0.1:6379> JSON.DEBUG MEMORY k1 $[*]
19+
1) (integer) 16
20+
2) (integer) 16
21+
3) (integer) 19
22+
4) (integer) 16
23+
5) (integer) 16
24+
6) (integer) 16
25+
7) (integer) 16
26+
8) (integer) 50
27+
9) (integer) 64
28+
127.0.0.1:6379> JSON.DEBUG FIELDS k1 $[*]
29+
1) (integer) 1
30+
2) (integer) 1
31+
3) (integer) 1
32+
4) (integer) 1
33+
5) (integer) 1
34+
6) (integer) 0
35+
7) (integer) 0
36+
8) (integer) 2
37+
9) (integer) 3
38+
```
39+
40+
Restricted path syntax:
41+
42+
```bash
43+
127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}'
44+
OK
45+
127.0.0.1:6379> JSON.DEBUG MEMORY k1
46+
(integer) 632
47+
127.0.0.1:6379> JSON.DEBUG MEMORY k1 .phoneNumbers
48+
(integer) 166
49+
50+
127.0.0.1:6379> JSON.DEBUG FIELDS k1
51+
(integer) 19
52+
127.0.0.1:6379> JSON.DEBUG FIELDS k1 .address
53+
(integer) 4
54+
```
55+
56+
```bash
57+
127.0.0.1:6379> JSON.DEBUG HELP
58+
1) JSON.DEBUG MEMORY <key> [path] - report memory size (bytes) of the JSON element. Path defaults to root if not provided.
59+
2) JSON.DEBUG FIELDS <key> [path] - report number of fields in the JSON element. Path defaults to root if not provided.
60+
3) JSON.DEBUG DEPTH <key> - report depth of JSON doc.
61+
3) JSON.DEBUG HELP - print help message.
62+
```

0 commit comments

Comments
 (0)