-
Notifications
You must be signed in to change notification settings - Fork 337
[DOC] JSON command edits #846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
89d9b50
Partial fix for REDISIO-186: JSON broken links
nermiller abe9242
Merge branch 'master' into master
nermiller b93ba70
Applied feedback from Chayim
nermiller 20b2e92
Merge branch 'master' of https://github.com/nermiller/RedisJSON
nermiller 228cfa7
Merge branch 'master' into master
nermiller 75f43c6
Merge branch 'RedisJSON:master' into master
nermiller ed0f4f7
Merge branch 'RedisJSON:master' into master
nermiller 9c9c611
Updates examples and restructures sections
nermiller d5207fa
Merge branch 'master' into json-command-edits
nermiller d5c425b
Update docs/commands/json.arrappend.md
nermiller 361e58a
Update docs/commands/json.arrappend.md
nermiller 6ef4638
Update docs/commands/json.arrindex.md
nermiller 34bd29b
Update docs/commands/json.arrindex.md
nermiller 3c37a64
Update docs/commands/json.arrinsert.md
nermiller 6917b22
Update docs/commands/json.arrindex.md
nermiller 4c88fc5
Update docs/commands/json.arrindex.md
nermiller f40b9d9
Update docs/commands/json.arrinsert.md
nermiller 4f60c27
Update docs/commands/json.arrlen.md
nermiller 1de0aca
Update docs/commands/json.arrpop.md
nermiller 4e1ae1d
Update docs/commands/json.arrtrim.md
nermiller 93cb491
Update docs/commands/json.numincrby.md
nermiller 0d47cdf
Update docs/commands/json.resp.md
nermiller fd0ac10
Update docs/commands/json.set.md
nermiller 42c97d1
Update docs/commands/json.strappend.md
nermiller 28dd011
Update docs/commands/json.toggle.md
nermiller fdb107d
Update docs/commands/json.arrpop.md
nermiller 5339ee8
Update docs/commands/json.arrpop.md
nermiller 9533a38
Update docs/commands/json.arrinsert.md
nermiller 95736ca
Update json.arrtrim.md
nermiller 2340356
Update docs/commands/json.arrappend.md
nermiller 7c6cebc
Update docs/commands/json.arrinsert.md
nermiller 9a88738
Update docs/commands/json.arrtrim.md
nermiller bc336b7
Update docs/commands/json.arrpop.md
nermiller eaa2e01
Merge branch 'master' into json-command-edits
nermiller 564b1eb
Merge branch 'master' into json-command-edits
oshadmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,68 @@ | ||
| Append the `json` values into the array at `path` after the last element in it. | ||
| Append the `json` values into the array at `path` after the last element in it | ||
|
|
||
| @return | ||
| [Examples](#examples) | ||
|
|
||
| @array-reply of @integer-reply - for each path, the array's new size, or @nil-reply if the matching JSON value is not an array. | ||
| ## Required arguments | ||
|
|
||
| @examples | ||
| <details open><summary><code>key</code></summary> | ||
|
|
||
| ``` | ||
| redis> JSON.SET doc $ '{"a":[1], "nested": {"a": [1,2]}, "nested2": {"a": 42}}' | ||
| is key to modify. | ||
| </details> | ||
|
|
||
| <details open><summary><code>value</code></summary> | ||
|
|
||
| is one or more values to append to one or more arrays. | ||
|
|
||
| {{% alert title="About using strings with JSON commands" color="warning" %}} | ||
| To specify a string as an array value to append, wrap the quoted string with an additional set of single quotes. Example: `'"silver"'`. For more detailed use, see [Examples](#examples). | ||
| {{% /alert %}} | ||
| </details> | ||
|
|
||
| ## Optional arguments | ||
|
|
||
| <details open><summary><code>path</code></summary> | ||
|
|
||
| is JSONPath to specify. Default is root `$`. | ||
| </details> | ||
|
|
||
| ## Return value | ||
|
|
||
| `JSON.ARRAPEND` returns an [array](/docs/reference/protocol-spec/#resp-arrays) of integer replies for each path, the array's new size, or `nil`, if the matching JSON value is not an array. | ||
| For more information about replies, see [Redis serialization protocol specification](/docs/reference/protocol-spec). | ||
|
|
||
| ## Examples | ||
|
|
||
| <details open> | ||
| <summary><b>Add a new color to a list of product colors</b></summary> | ||
|
|
||
| Create a document for noise-cancelling headphones in black and silver colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.SET item:1 $ '{"name":"Noise-cancelling Bluetooth headphones","description":"Wireless Bluetooth headphones with noise-cancelling technology","connection":{"wireless":true,"type":"Bluetooth"},"price":99.98,"stock":25,"colors":["black","silver"]}' | ||
| OK | ||
| redis> JSON.ARRAPPEND doc $..a 3 4 | ||
| {{< / highlight >}} | ||
|
|
||
| Add color `blue` to the end of the `colors` array. `JSON.ARRAPEND` returns the array's new size. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRAPPEND item:1 $.colors '"blue"' | ||
| 1) (integer) 3 | ||
| 2) (integer) 4 | ||
| 3) (nil) | ||
| redis> JSON.GET doc $ | ||
| "[{\"a\":[1,3,4],\"nested\":{\"a\":[1,2,3,4]},\"nested2\":{\"a\":42}}]" | ||
| ``` | ||
| {{< / highlight >}} | ||
|
|
||
| Return the new length of the `colors` array. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.GET item:1 | ||
| "{\"name\":\"Noise-cancelling Bluetooth headphones\",\"description\":\"Wireless Bluetooth headphones with noise-cancelling technology\",\"connection\":{\"wireless\":true,\"type\":\"Bluetooth\"},\"price\":99.98,\"stock\":25,\"colors\":[\"black\",\"silver\",\"blue\"]}" | ||
| {{< / highlight >}} | ||
|
|
||
| </details> | ||
|
|
||
| ## See also | ||
|
|
||
| `JSON.ARRINDEX` | `JSON.ARRINSERT` | ||
|
|
||
| ## Related topics | ||
|
|
||
| * [RedisJSON](/docs/stack/json) | ||
| * [Index and search JSON documents](/docs/stack/search/indexing_json) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,107 @@ | ||
| Searches for the first occurrence of a scalar JSON value in an array. | ||
| Search for the first occurrence of a scalar JSON value in an array | ||
|
|
||
| The optional inclusive `start` (default 0) and exclusive `stop` (default 0, meaning that the last element is included) specify a slice of the array to search. | ||
| Negative values are interpreted as starting from the end. | ||
| [Examples](#examples) | ||
|
|
||
| ## Required arguments | ||
|
|
||
| Note: out-of-range indexes round to the array's start and end. An inverse index range (such as the range from 1 to 0) will return unfound. | ||
| <details open><summary><code>key</code></summary> | ||
|
|
||
| @return | ||
| is key to parse. | ||
| </details> | ||
|
|
||
| @array-reply of @integer-reply - the first position in the array of each JSON value that matches the path, -1 if unfound in the array, or @nil-reply if the matching JSON value is not an array. | ||
| <details open><summary><code>value</code></summary> | ||
|
|
||
| @examples | ||
| is value to find its index in one or more arrays. | ||
|
|
||
| ``` | ||
| redis> JSON.SET doc $ '{"a":[1,2,3,2], "nested": {"a": [3,4]}}' | ||
| OK | ||
| redis> JSON.ARRINDEX doc $..a 2 | ||
| 1) (integer) 1 | ||
| 2) (integer) -1 | ||
| ``` | ||
| {{% alert title="About using strings with JSON commands" color="warning" %}} | ||
| To specify a string as an array value to index, wrap the quoted string with an additional set of single quotes. Example: `'"silver"'`. For more detailed use, see [Examples](#examples). | ||
| {{% /alert %}} | ||
| </details> | ||
|
|
||
| ## Optional arguments | ||
|
|
||
| <details open><summary><code>start</code></summary> | ||
|
|
||
| is inclusive start value to specify in a slice of the array to search. Default is `0`. | ||
| </details> | ||
|
|
||
|
|
||
| <details open><summary><code>stop</code></summary> | ||
|
|
||
| is exclusive stop value to specify in a slice of the array to search, including the last element. Default is `0`. Negative values are interpreted as starting from the end. | ||
| </details> | ||
|
|
||
| ``` | ||
| redis> JSON.SET doc $ '{"a":[1,2,3,2], "nested": {"a": false}}' | ||
| {{% alert title="About out-of-range indexes" color="warning" %}} | ||
|
|
||
| Out-of-range indexes round to the array's start and end. An inverse index range (such as the range from 1 to 0) returns unfound or `-1`. | ||
| {{% /alert %}} | ||
|
|
||
| ## Return value | ||
|
|
||
| `JSON.ARRINDEX` returns an [array](/docs/reference/protocol-spec/#resp-arrays) of integer replies for each path, the first position in the array of each JSON value that matches the path, `-1` if unfound in the array, or `nil`, if the matching JSON value is not an array. | ||
| For more information about replies, see [Redis serialization protocol specification](/docs/reference/protocol-spec). | ||
|
|
||
| ## Examples | ||
|
|
||
| <details open> | ||
| <summary><b>Find the specific place of a color in a list of product colors</b></summary> | ||
|
|
||
| Create a document for noise-cancelling headphones in black and silver colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.SET item:1 $ '{"name":"Noise-cancelling Bluetooth headphones","description":"Wireless Bluetooth headphones with noise-cancelling technology","connection":{"wireless":true,"type":"Bluetooth"},"price":99.98,"stock":25,"colors":["black","silver"]}' | ||
| OK | ||
| redis> JSON.ARRINDEX doc $..a 2 | ||
| {{< / highlight >}} | ||
|
|
||
| Add color `blue` to the end of the `colors` array. `JSON.ARRAPEND` returns the array's new size. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRAPPEND item:1 $.colors '"blue"' | ||
| 1) (integer) 3 | ||
| {{< / highlight >}} | ||
|
|
||
| Return the new length of the `colors` array. | ||
|
|
||
| {{< highlight bash >}} | ||
| JSON.GET item:1 | ||
| "{\"name\":\"Noise-cancelling Bluetooth headphones\",\"description\":\"Wireless Bluetooth headphones with noise-cancelling technology\",\"connection\":{\"wireless\":true,\"type\":\"Bluetooth\"},\"price\":99.98,\"stock\":25,\"colors\":[\"black\",\"silver\",\"blue\"]}" | ||
| {{< / highlight >}} | ||
|
|
||
| Get the list of colors for the product. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.GET item:1 '$.colors[*]' | ||
| "[\"black\",\"silver\",\"blue\"]" | ||
| {{< / highlight >}} | ||
|
|
||
| Insert two more colors after the second color. You now have five colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRINSERT item:1 $.colors 2 '"yellow"' '"gold"' | ||
| 1) (integer) 5 | ||
| {{< / highlight >}} | ||
|
|
||
| Get the updated list of colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.GET item:1 $.colors | ||
| "[[\"black\",\"silver\",\"yellow\",\"gold\",\"blue\"]]" | ||
| {{< / highlight >}} | ||
|
|
||
| Find the place where color `silver` is located. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRINDEX item:1 $..colors '"silver"' | ||
| 1) (integer) 1 | ||
| 2) (nil) | ||
| ``` | ||
| {{< / highlight >}} | ||
| </details> | ||
|
|
||
| ## See also | ||
|
|
||
| `JSON.ARRAPPEND` | `JSON.ARRINSERT` | ||
|
|
||
| ## Related topics | ||
|
|
||
| * [RedisJSON](/docs/stack/json) | ||
| * [Index and search JSON documents](/docs/stack/search/indexing_json) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,93 @@ | ||
| Inserts the `json` values into the array at `path` before the `index` (shifts to the right). | ||
| Insert the `json` values into the array at `path` before the `index` (shifts to the right) | ||
|
|
||
| The index must be in the array's range. Inserting at `index` 0 prepends to the array. Negative index values start from the end of the array. | ||
| [Examples](#examples) | ||
|
|
||
| @return | ||
| ## Required arguments | ||
|
|
||
| @array-reply of @integer-reply - for each path, the array's new size, or @nil-reply if the matching JSON value is not an array. | ||
| <details open><summary><code>key</code></summary> | ||
|
|
||
| @examples | ||
| is key to modify. | ||
| </details> | ||
|
|
||
| ``` | ||
| redis> JSON.SET doc $ '{"a":[3], "nested": {"a": [3,4]}}' | ||
| <details open><summary><code>value</code></summary> | ||
|
|
||
| is one or more values to insert in one or more arrays. | ||
|
|
||
| {{% alert title="About using strings with JSON commands" color="warning" %}} | ||
| To specify a string as an array value to insert, wrap the quoted string with an additional set of single quotes. Example: `'"silver"'`. For more detailed use, see [Examples](#examples). | ||
| {{% /alert %}} | ||
| </details> | ||
|
|
||
| <details open><summary><code>index</code></summary> | ||
|
|
||
| is position in the array where you want to insert a value. The index must be in the array's range. Inserting at `index` 0 prepends to the array. Negative index values start from the end of the array. | ||
| </details> | ||
|
|
||
| ## Optional arguments | ||
|
|
||
| <details open><summary><code>path</code></summary> | ||
|
|
||
| is JSONPath to specify. Default is root `$`. | ||
| </details> | ||
|
|
||
| ## Return value | ||
|
|
||
| `JSON.ARRINSERT` returns an [array](/docs/reference/protocol-spec/#resp-arrays) of integer replies for each path, the array's new size, or `nil`, if the matching JSON value is not an array. | ||
| For more information about replies, see [Redis serialization protocol specification](/docs/reference/protocol-spec). | ||
|
|
||
| ## Examples | ||
|
|
||
| <details open> | ||
| <summary><b>Add new colors to a specific place in a list of product colors</b></summary> | ||
|
|
||
| Create a document for noise-cancelling headphones in black and silver colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.SET item:1 $ '{"name":"Noise-cancelling Bluetooth headphones","description":"Wireless Bluetooth headphones with noise-cancelling technology","connection":{"wireless":true,"type":"Bluetooth"},"price":99.98,"stock":25,"colors":["black","silver"]}' | ||
| OK | ||
| redis> JSON.ARRINSERT doc $..a 0 1 2 | ||
| {{< / highlight >}} | ||
|
|
||
| Add color `blue` to the end of the `colors` array. `JSON.ARRAPEND` returns the array's new size. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRAPPEND item:1 $.colors '"blue"' | ||
| 1) (integer) 3 | ||
| 2) (integer) 4 | ||
| redis> JSON.GET doc $ | ||
| "[{\"a\":[1,2,3],\"nested\":{\"a\":[1,2,3,4]}}]" | ||
| ``` | ||
| {{< / highlight >}} | ||
|
|
||
| ``` | ||
| redis> JSON.SET doc $ '{"a":[1,2,3,2], "nested": {"a": false}}' | ||
| OK | ||
| redis> JSON.ARRINSERT doc $..a 0 1 2 | ||
| 1) (integer) 6 | ||
| 2) (nil) | ||
| ``` | ||
| Return the new length of the `colors` array. | ||
|
|
||
| {{< highlight bash >}} | ||
| JSON.GET item:1 | ||
| "{\"name\":\"Noise-cancelling Bluetooth headphones\",\"description\":\"Wireless Bluetooth headphones with noise-cancelling technology\",\"connection\":{\"wireless\":true,\"type\":\"Bluetooth\"},\"price\":99.98,\"stock\":25,\"colors\":[\"black\",\"silver\",\"blue\"]}" | ||
| {{< / highlight >}} | ||
|
|
||
| Get the list of colors for the product. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.GET item:1 '$.colors[*]' | ||
| "[\"black\",\"silver\",\"blue\"]" | ||
| {{< / highlight >}} | ||
|
|
||
| Insert two more colors after the second color. You now have five colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.ARRINSERT item:1 $.colors 2 '"yellow"' '"gold"' | ||
| 1) (integer) 5 | ||
| {{< / highlight >}} | ||
|
|
||
| Get the updated list of colors. | ||
|
|
||
| {{< highlight bash >}} | ||
| 127.0.0.1:6379> JSON.GET item:1 $.colors | ||
| "[[\"black\",\"silver\",\"yellow\",\"gold\",\"blue\"]]" | ||
| {{< / highlight >}} | ||
| </details> | ||
|
|
||
| ## See also | ||
|
|
||
| `JSON.ARRAPPEND` | `JSON.ARRINDEX` | ||
|
|
||
| ## Related topics | ||
|
|
||
| * [RedisJSON](/docs/stack/json) | ||
| * [Index and search JSON documents](/docs/stack/search/indexing_json) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we specify indices are "zero-based"? (first element is at index 0, second element is at index 1, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that not expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume most users would expect that, but as far as I am concerned, if we can be formal about indices being zero-based, why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will add.