JSON.ARRLEN
Syntax
JSON.ARRLEN key [path]
- Available in:
- Redis Stack / JSON 1.0.0
- Time complexity:
- O(1) where path is evaluated to a single value, O(N) where path is evaluated to multiple values, where N is the size of the key
报告在key
中的path
处的JSON数组的长度
必需的参数
key
是解析的关键。
可选参数
path
是JSONPath指定的。如果没有提供,默认是根$
。如果key
或path
不存在,则返回null。
返回
JSON.ARRLEN
返回一个整数回复的数组,每个匹配值对应一个整数,每个整数是数组的长度,如果匹配值不是数组,则返回nil
。
有关回复的更多信息,请参阅Redis序列化协议规范。
示例
Get lengths of JSON arrays in a document
为无线耳机创建一个文档。
redis> JSON.SET item:2 $ '{"name":"Wireless earbuds","description":"Wireless Bluetooth in-ear headphones","connection":{"wireless":true,"type":"Bluetooth"},"price":64.99,"stock":17,"colors":["black","white"], "max_level":[80, 100, 120]}'
OK
查找文档中所有对象的数组长度。
redis> JSON.ARRLEN item:2 '$.[*]'
1) (nil)
2) (nil)
3) (nil)
4) (nil)
5) (nil)
6) (integer) 2
7) (integer) 3
返回max_level
数组的长度。
redis> JSON.ARRLEN item:2 '$..max_level'
1) (integer) 3
获取所有最大级别值。
redis> JSON.GET item:2 '$..max_level'
"[[80,100,120]]"
另请参阅
JSON.ARRINDEX
| JSON.ARRINSERT