JSON.MGET
Syntax
JSON.MGET key [key ...] path
- Available in:
- Redis Stack / JSON 1.0.0
- Time complexity:
- O(M*N) when path is evaluated to a single value where M is the number of keys and N is the size of the value, O(N1+N2+...+Nm) when path is evaluated to multiple values where m is the number of keys and Ni is the size of the i-th key
从多个key
参数中返回path
处的值
Warning:
当启用集群模式时,所有指定的键必须位于同一个hash slot中。
当数据库有多个分片,并且指定的键位于不同的分片中时,Redis不会报告CROSSSLOT错误(以避免破坏性更改),结果可能是部分的。
必需的参数
key
是解析的关键。对于不存在的键返回null
。
可选参数
path
是JSONPath指定的。对于不存在的路径返回null
。
返回
JSON.MGET 返回一个批量字符串回复的数组,这些回复被指定为每个键路径上值的 JSON 序列化。 有关回复的更多信息,请参阅 Redis 序列化协议规范。
示例
Return the values at path
from multiple key
arguments
创建两个JSON文档。
redis> JSON.SET doc1 $ '{"a":1, "b": 2, "nested": {"a": 3}, "c": null}'
OK
redis> JSON.SET doc2 $ '{"a":4, "b": 5, "nested": {"a": 6}, "c": null}'
OK
从文档中的所有参数获取值。
redis> JSON.MGET doc1 doc2 $..a
1) "[1,3]"
2) "[4,6]"