JSON.ARRAPPEND
Syntax
JSON.ARRAPPEND key [path] value [value ...]
- Available in:
- Redis Stack / JSON 1.0.0
- Time complexity:
- O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
将json
值追加到path
处的数组中的最后一个元素之后
必需的参数
key
是修改的关键。
value
是一个或多个要附加到一个或多个数组的值。
可选参数
path
是JSONPath指定的。默认是根 $
。
返回值
JSON.ARRAPEND
返回一个数组,其中包含每个路径的整数回复,数组的新大小,或者如果匹配的JSON值不是数组,则返回nil
。
有关回复的更多信息,请参阅Redis序列化协议规范。
示例
Add a new color to a list of product colors
创建一个关于黑色和银色降噪耳机的文档。
redis> JSON.SET item:1 $ '{"name":"Noise-cancelling Bluetooth headphones","description":"Wireless Bluetooth headphones with noise-cancelling technology","connection":{"wireless":true,"type":"Bluetooth"},"price":99.98,"stock":25,"colors":["black","silver"]}'
OK
将颜色 blue
添加到 colors
数组的末尾。JSON.ARRAPEND
返回数组的新大小。
redis> JSON.ARRAPPEND item:1 $.colors '"blue"'
1) (integer) 3
返回colors
数组的新长度。
redis> JSON.GET item:1
"{\"name\":\"Noise-cancelling Bluetooth headphones\",\"description\":\"Wireless Bluetooth headphones with noise-cancelling technology\",\"connection\":{\"wireless\":true,\"type\":\"Bluetooth\"},\"price\":99.98,\"stock\":25,\"colors\":[\"black\",\"silver\",\"blue\"]}"
另请参阅
JSON.ARRINDEX
| JSON.ARRINSERT