本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
從多個文件金鑰取得路徑上的序列化 JSONs。為不存在的金鑰或 JSON 路徑傳回 null。
語法
JSON.MGET <key> [key ...] <path>
金鑰 (必要) – 文件類型的一或多個金鑰。
路徑 (必要) – JSON 路徑
傳回
大量字串陣列。陣列的大小等於命令中的索引鍵數量。陣列的每個元素都會填入 (a) 路徑所在的序列化 JSON,或 (b) 如果金鑰不存在或文件中不存在路徑或路徑無效 (語法錯誤),則為 Null。
-
如果有任何指定的索引鍵,且不是 JSON 索引鍵,命令會傳回
WRONGTYPE
錯誤。
範例
增強型路徑語法:
127.0.0.1:6379> JSON.SET k1 . '{"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021"}}'
OK
127.0.0.1:6379> JSON.SET k2 . '{"address":{"street":"5 main Street","city":"Boston","state":"MA","zipcode":"02101"}}'
OK
127.0.0.1:6379> JSON.SET k3 . '{"address":{"street":"100 Park Ave","city":"Seattle","state":"WA","zipcode":"98102"}}'
OK
127.0.0.1:6379> JSON.MGET k1 k2 k3 $.address.city
1) "[\"New York\"]"
2) "[\"Boston\"]"
3) "[\"Seattle\"]"
受限路徑語法:
127.0.0.1:6379> JSON.SET k1 . '{"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021"}}'
OK
127.0.0.1:6379> JSON.SET k2 . '{"address":{"street":"5 main Street","city":"Boston","state":"MA","zipcode":"02101"}}'
OK
127.0.0.1:6379> JSON.SET k3 . '{"address":{"street":"100 Park Ave","city":"Seattle","state":"WA","zipcode":"98102"}}'
OK
127.0.0.1:6379> JSON.MGET k1 k2 k3 .address.city
1) "\"New York\""
2) "\"Seattle\""
3) "\"Seattle\""