1
1
Redis has several commands that allow you to manipulate JSON arrays. Simple documents will be used to demonstrate each command.
2
2
3
- ``` redis Create a document
3
+ ``` redis:[run_confirmation=true] Create a document
4
4
JSON.SET doc $ '{"a": [10, 20, 30, 40, 50]}'
5
5
```
6
6
@@ -12,14 +12,14 @@ JSON.ARRLEN doc $.a
12
12
13
13
- ` JSON.ARRAPPEND ` - append one or more values to an array:
14
14
15
- ``` redis Append two values to $.a
15
+ ``` redis:[run_confirmation=true] Append two values to $.a
16
16
JSON.ARRAPPEND doc $.a 60 '"foo"'
17
17
JSON.GET doc $.a
18
18
```
19
19
20
20
- ` JSON.ARRPOP ` - remove an element from an array:
21
21
22
- ``` redis Remove the last item from $.a
22
+ ``` redis:[run_confirmation=true] Remove the last item from $.a
23
23
JSON.ARRPOP doc $.a
24
24
JSON.GET doc $.a
25
25
```
@@ -30,25 +30,25 @@ For example, `-1` mean the last element and `-2` means the second to last elemen
30
30
31
31
- ` JSON.ARRTRIM ` - trim an array so that it contains only the specified inclusive range of elements.
32
32
33
- ``` redis Trim $.a to just the first 3 elements
33
+ ``` redis:[run_confirmation=true] Trim $.a to just the first 3 elements
34
34
JSON.ARRTRIM doc $.a 0 2
35
35
JSON.GET doc
36
36
```
37
37
38
38
Now, reset doc to it's original value and trim ` $.a ` to just the last two values:
39
39
40
- ``` redis Re-create the document
40
+ ``` redis:[run_confirmation=true] Re-create the document
41
41
JSON.SET doc $ '{"a": [10, 20, 30, 40, 50]}'
42
42
```
43
43
44
- ``` redis Trim to the last two values
44
+ ``` redis:[run_confirmation=true] Trim to the last two values
45
45
JSON.ARRTRIM doc $.a -2 -1
46
46
JSON.GET doc
47
47
```
48
48
49
49
As discussed earlier in this tutorial, ` JSON.MERGE ` can be used to replace entire arrays.
50
50
51
- ``` redis Replace $.a with a different set of values
51
+ ``` redis:[run_confirmation=true] Replace $.a with a different set of values
52
52
JSON.MERGE doc $.a '["a", "b", "c"]'
53
53
JSON.GET doc
54
- ```
54
+ ```
0 commit comments