JSON.ARRPOP
Syntax
JSON.ARRPOP key [path [index]]
- 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 and the specified index is not the last element, O(1) when path is evaluated to a single value and the specified index is the last element, or O(N) when path is evaluated to multiple values, where N is the size of the key
Removes and returns an element from the index in the array.
path
defaults to root if not provided. index
is the position in the array to start popping from (defaults to -1, meaning the last element). Out-of-range indexes round to their respective array ends. Popping an empty array returns null.
Return
Array reply of Bulk string reply - for each path, the popped JSON value, 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.ARRPOP doc $..a
1) "3"
2) "4"
redis> JSON.GET doc $
"[{\"a\":[],\"nested\":{\"a\":[3]}}]"
redis> JSON.SET doc $ '{"a":["foo", "bar"], "nested": {"a": false}, "nested2": {"a":[]}}'
OK
redis> JSON.ARRPOP doc $..a
1) "\"bar\""
2) (nil)
3) (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.