- Usage:
-
JSON.ARRPOP key [ path ] [ index ]
- Complexity:
- O(N) where N is the number of jsons arrays matched by the path.
- Module:
- valkey-json
- Since module version:
- 1.0.0
- ACL Categories:
- @write, @fast, @json
-
If the path is enhanced syntax:
-
Array reply: Array of bulk strings representing popped values at each path.
-
Nil reply: For each path where the value is an empty array or not an array.
-
-
If the path is restricted syntax:
-
Bulk string reply: The popped JSON value.
-
Nil reply: If the array is empty.
-
-
- if the value at the path is not an array (only for restricted syntax).
-
If the path is enhanced syntax:
-
Array reply: Array of bulk strings representing popped values at each path.
-
Null reply: For each path where the value is an empty array or not an array.
-
-
If the path is restricted syntax:
-
Bulk string reply: The popped JSON value.
-
Null reply: If the array is empty.
-
-
- if the value at the path is not an array (only for restricted syntax).
Remove and return element at the index from the array. Popping an empty array returns null.
Examples
Enhanced path syntax:
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRPOP k1 $[*]
1) (nil)
2) "\"a\""
3) "\"b\""
127.0.0.1:6379> JSON.GET k1
"[[],[],[\"a\"]]"
Restricted path syntax:
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRPOP k1
"[\"a\",\"b\"]"
127.0.0.1:6379> JSON.GET k1
"[[],[\"a\"]]"
127.0.0.1:6379> JSON.SET k2 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRPOP k2 . 0
"[]"
127.0.0.1:6379> JSON.GET k2
"[[\"a\"],[\"a\",\"b\"]]"