@@ -29,7 +29,7 @@ import TabItem from '@theme/TabItem';
29
29
</tr >
30
30
<tr >
31
31
<td >JSON.SET</td >
32
- <td >JSON.SET key path json [ NX | XX ] </td >
32
+ <td >JSON.SET key path value </td >
33
33
<td >
34
34
<pre >
35
35
<code >{ `
@@ -42,14 +42,13 @@ JSON.SET employee_profile:1 . '{"name":"Alice"}'
42
42
<tr >
43
43
<td colspan = " 4" >
44
44
<em >Description:</em > Sets JSON value at path in key.
45
+ <em >Time Complexity:</em > O(M+N) where M is the original size and N is the
46
+ new size
45
47
</td >
46
48
</tr >
47
49
<tr >
48
50
<td >JSON.GET</td >
49
- <td >
50
- JSON.GET key [ INDENT indentation-string] [ NEWLINE line-break-string]
51
- [ SPACE space-string] [ path]
52
- </td >
51
+ <td >JSON.GET key [ path [ path ...]] </td >
53
52
<td >
54
53
<pre >
55
54
<code >{ `
@@ -68,6 +67,9 @@ JSON.GET employee_profile:1
68
67
<tr >
69
68
<td colspan = " 4" >
70
69
<em >Description:</em > Returns the JSON value at path in key.
70
+ <em >Time Complexity:</em > O(N) when path is evaluated to a single value where
71
+ N is the size of the value, O(N) when path is evaluated to multiple values,
72
+ where N is the size of the key
71
73
</td >
72
74
</tr >
73
75
<tr >
@@ -86,6 +88,9 @@ JSON.NUMINCRBY employee_profile:1 .age 5
86
88
<tr >
87
89
<td colspan = " 4" >
88
90
<em >Description:</em > Increments a number inside a JSON document.
91
+ <em >Time Complexity:</em > O(1) when path is evaluated to a single value,
92
+ O(N) when path is evaluated to multiple values, where N is the size of the
93
+ key
89
94
</td >
90
95
</tr >
91
96
<tr >
@@ -103,7 +108,9 @@ JSON.OBJKEYS employee_profile:1
103
108
<tr >
104
109
<td colspan = " 4" >
105
110
<em >Description:</em > Return the keys in the object that's referenced by
106
- path
111
+ path. <em >Time Complexity:</em > O(N) when path is evaluated to a single
112
+ value, where N is the number of keys in the object, O(N) when path is
113
+ evaluated to multiple values, where N is the size of the key
107
114
</td >
108
115
</tr >
109
116
<tr >
@@ -121,12 +128,14 @@ JSON.OBJLEN employee_profile:1
121
128
<tr >
122
129
<td colspan = " 4" >
123
130
<em >Description:</em > Report the number of keys in the JSON object at
124
- path in key
131
+ path in key. <em >Time Complexity:</em > O(1) when path is evaluated to a
132
+ single value, O(N) when path is evaluated to multiple values, where N is
133
+ the size of the key
125
134
</td >
126
135
</tr >
127
136
<tr >
128
137
<td >JSON.ARRAPPEND</td >
129
- <td >JSON.ARRAPPEND key path json ...</td >
138
+ <td >JSON.ARRAPPEND key [ path] value [ value ...] </td >
130
139
<td >
131
140
<pre >
132
141
<code >{ `
@@ -135,17 +144,19 @@ JSON.ARRAPPEND employee_profile:1 .colors '"yellow"'
135
144
` } </code >
136
145
</pre >
137
146
</td >
138
- <td >(integer) 3 </td >
147
+ <td >(integer) 4 </td >
139
148
</tr >
140
149
<tr >
141
150
<td colspan = " 4" >
142
- <em >Description:</em > Appends the specified JSON value(s) to the JSON
143
- array at the specified path.
151
+ <em >Description:</em > Append the json values into the array at path
152
+ after the last element in it. <em >Time Complexity:</em > O(1) for each
153
+ value added, O(N) for multiple values added where N is the size of the
154
+ key
144
155
</td >
145
156
</tr >
146
157
<tr >
147
158
<td >JSON.ARRINSERT</td >
148
- <td >JSON.ARRINSERT key path index json ...</td >
159
+ <td >JSON.ARRINSERT key path index value [ value ...] </td >
149
160
<td >
150
161
<pre >
151
162
<code >{ `
@@ -157,13 +168,16 @@ JSON.ARRINSERT employee_profile:1 .colors 2 '"purple"'
157
168
</tr >
158
169
<tr >
159
170
<td colspan = " 4" >
160
- <em >Description:</em > Inserts the JSON value(s) in the JSON array at the
161
- specified path.
171
+ <em >Description:</em > Insert the json values into the array at path
172
+ before the index (shifts to the right). <em >Time Complexity:</em > O(N)
173
+ when path is evaluated to a single value where N is the size of the
174
+ array, O(N) when path is evaluated to multiple values, where N is the
175
+ size of the key
162
176
</td >
163
177
</tr >
164
178
<tr >
165
179
<td >JSON.ARRINDEX</td >
166
- <td >JSON.ARRINDEX key path json [ start [ stop]] </td >
180
+ <td >JSON.ARRINDEX key path value [ start [ stop]] </td >
167
181
<td >
168
182
<pre >
169
183
<code >{ `
@@ -176,7 +190,9 @@ JSON.ARRINDEX employee_profile:1 .colors '"purple"'
176
190
<tr >
177
191
<td colspan = " 4" >
178
192
<em >Description:</em > Searches for the first occurrence of a JSON value
179
- in an array.
193
+ in an array. <em >Time Complexity:</em > O(N) when path is evaluated to a
194
+ single value where N is the size of the array, O(N) when path is
195
+ evaluated to multiple values, where N is the size of the key
180
196
</td >
181
197
</tr >
182
198
</tbody >
@@ -186,6 +202,97 @@ JSON.ARRINDEX employee_profile:1 .colors '"purple"'
186
202
187
203
<TabItem value = " NODE_JS" >
188
204
205
+ ``` js
206
+ /*
207
+ JSON.SET key path value
208
+ Sets JSON value at path in key.
209
+ O(M+N) where M is the original size and N is the new size
210
+ */
211
+ const setResult = await client .json .set (' employee_profile:1' , ' .' , {
212
+ name: ' Alice' ,
213
+ });
214
+ console .log (setResult); // OK
215
+
216
+ /*
217
+ JSON.GET key [path [path ...]]
218
+ Returns the JSON value at path in key.
219
+ O(N) when path is evaluated to a single value where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
220
+ */
221
+ const getResult = await client .json .get (' employee_profile:1' );
222
+ console .log (getResult); // { name: 'Alice' }
223
+
224
+ /*
225
+ JSON.NUMINCRBY key path number
226
+ Increments a number inside a JSON document.
227
+ O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
228
+ */
229
+ await client .json .set (' employee_profile:1' , ' .age' , 30 );
230
+ const incrementResult = await client .json .numIncrBy (
231
+ ' employee_profile:1' ,
232
+ ' .age' ,
233
+ 5 ,
234
+ );
235
+ console .log (incrementResult); // 35
236
+
237
+ /*
238
+ JSON.OBJKEYS key [path]
239
+ Return the keys in the object that's referenced by path
240
+ O(N) when path is evaluated to a single value, where N is the number of keys in the object, O(N) when path is evaluated to multiple values, where N is the size of the key
241
+ */
242
+ const objKeysResult = await client .json .objKeys (' employee_profile:1' );
243
+ console .log (objKeysResult); // [ 'name', 'age' ]
244
+
245
+ /*
246
+ JSON.OBJLEN key [path]
247
+ Report the number of keys in the JSON object at path in key
248
+ O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
249
+ */
250
+ const objLenResult = await client .json .objLen (' employee_profile:1' );
251
+ console .log (objLenResult); // 2
252
+
253
+ /*
254
+ JSON.ARRAPPEND key [path] value [value ...]
255
+ Append the json values into the array at path after the last element in it
256
+ O(1) for each value added, O(N) for multiple values added where N is the size of the key
257
+ */
258
+ await client .json .set (' employee_profile:1' , ' .colors' , [
259
+ ' red' ,
260
+ ' green' ,
261
+ ' blue' ,
262
+ ]);
263
+ const arrAppendResult = await client .json .arrAppend (
264
+ ' employee_profile:1' ,
265
+ ' .colors' ,
266
+ ' yellow' ,
267
+ );
268
+ console .log (arrAppendResult); // 4
269
+
270
+ /*
271
+ JSON.ARRINSERT key path index value [value ...]
272
+ Insert the json values into the array at path before the index (shifts to the right)
273
+ O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
274
+ */
275
+ const arrInsertResult = await client .json .arrInsert (
276
+ ' employee_profile:1' ,
277
+ ' .colors' ,
278
+ 2 ,
279
+ ' purple' ,
280
+ );
281
+ console .log (arrInsertResult); // 5
282
+
283
+ /*
284
+ JSON.ARRINDEX key path json [start [stop]]
285
+ Searches for the first occurrence of a JSON value in an array.
286
+ O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
287
+ */
288
+ const arrIndexResult = await client .json .arrIndex (
289
+ ' employee_profile:1' ,
290
+ ' .colors' ,
291
+ ' purple' ,
292
+ );
293
+ console .log (arrIndexResult); // 2
294
+ ```
295
+
189
296
</TabItem >
190
297
191
298
</Tabs >
0 commit comments