JSON.ARRINSERT

Syntax
JSON.ARRINSERT key path index value [value ...]
Available in:
Redis Stack / JSON 1.0.0
Time complexity:
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

Inserts 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.

Return

Array reply of Integer reply - for each path, the array's new size, or Null reply if the matching JSON value is not an array.

Examples

redis> JSON.SET doc $ '{"a":[3], "nested": {"a": [3,4]}}'
OK
redis> JSON.ARRINSERT doc $..a 0 1 2
1) (integer) 3
2) (integer) 4
redis> JSON.GET doc $
"[{\"a\":[1,2,3],\"nested\":{\"a\":[1,2,3,4]}}]"
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)

Feedback

If you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository.