- 用法
-
JSON.ARRTRIM key path start end
- 复杂度
- O(N),其中 N 是路径匹配到的 JSON 数组的数量。
- 模块
- valkey-json
- 模块版本
- 1.0.0
- ACL 类别
- @write, @fast, @json
- 如果数组为空,则不执行任何操作,返回 0。
- 如果 start < 0,则将其视为 0。
- 如果 end ≥ size (数组的大小),则将其视为 size-1。
- 如果 start ≥ size 或 start > end,则清空数组并返回 0。
-
如果路径是增强语法
-
如果路径是受限语法
-
-
如果路径上的值不是数组(仅适用于受限语法)。
-
如果索引参数超出范围。
-
修剪路径上的数组,使其变为子数组 [start, end],包含 start 和 end 索引。
示例
增强路径语法
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
OK
127.0.0.1:6379> JSON.ARRTRIM k1 $[*] 0 1
1) (integer) 0
2) (integer) 1
3) (integer) 2
4) (integer) 2
127.0.0.1:6379> JSON.GET k1
"[[],[\"a\"],[\"a\",\"b\"],[\"a\",\"b\"]]"
受限路径语法
127.0.0.1:6379> JSON.SET k1 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}'
OK
127.0.0.1:6379> JSON.ARRTRIM k1 .children 0 1
(integer) 2
127.0.0.1:6379> JSON.GET k1 .children
"[\"John\",\"Jack\"]"