本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
JSON.RESP
在 Valkey 或 Redis OSS 序列化协议 () 中返回给定路径上的JSON值。RESP如果值为容器,则响应为RESP数组或嵌套数组。
JSONnull 映射到RESP空批量字符串。
JSON布尔值映射到相应的RESP简单字符串。
整数映射为RESP整数。
64 位IEEE双浮点数映射到RESP批量字符串。
JSON字符串映射到RESP批量字符串。
JSON数组表示为RESP数组,其中第一个元素是简单的字符串 [,后面是数组的元素。
JSON对象表示为RESP数组,其中第一个元素是简单的字符串 {,后面是键值对,每个键值对都是RESP批量字符串。
语法
JSON.RESP <key> [path]
密钥(必填)— JSON 文档类型的密钥
路径(可选)— JSON 路径。如果未提供,则默认为根目录
Return
如果路径是增强的语法:
数组的数组。每个数组元素代表一条路径上值的RESP形式。
-
如果文档键不存在,则为空数组。
如果路径是受限的语法:
数组,表示路径中值的RESP形式。
-
如果文档键不存在,则为 Null。
示例
增强的路径语法:
127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}' OK 127.0.0.1:6379> JSON.RESP k1 $.address 1) 1) { 2) 1) "street" 2) "21 2nd Street" 3) 1) "city" 2) "New York" 4) 1) "state" 2) "NY" 5) 1) "zipcode" 2) "10021-3100" 127.0.0.1:6379> JSON.RESP k1 $.address.* 1) "21 2nd Street" 2) "New York" 3) "NY" 4) "10021-3100" 127.0.0.1:6379> JSON.RESP k1 $.phoneNumbers 1) 1) [ 2) 1) { 2) 1) "type" 2) "home" 3) 1) "number" 2) "555 555-1234" 3) 1) { 2) 1) "type" 2) "office" 3) 1) "number" 2) "555 555-4567" 127.0.0.1:6379> JSON.RESP k1 $.phoneNumbers[*] 1) 1) { 2) 1) "type" 2) "home" 3) 1) "number" 2) "212 555-1234" 2) 1) { 2) 1) "type" 2) "office" 3) 1) "number" 2) "555 555-4567"
受限的路径语法:
127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}' OK 127.0.0.1:6379> JSON.RESP k1 .address 1) { 2) 1) "street" 2) "21 2nd Street" 3) 1) "city" 2) "New York" 4) 1) "state" 2) "NY" 5) 1) "zipcode" 2) "10021-3100" 127.0.0.1:6379> JSON.RESP k1 1) { 2) 1) "firstName" 2) "John" 3) 1) "lastName" 2) "Smith" 4) 1) "age" 2) (integer) 27 5) 1) "weight" 2) "135.25" 6) 1) "isAlive" 2) true 7) 1) "address" 2) 1) { 2) 1) "street" 2) "21 2nd Street" 3) 1) "city" 2) "New York" 4) 1) "state" 2) "NY" 5) 1) "zipcode" 2) "10021-3100" 8) 1) "phoneNumbers" 2) 1) [ 2) 1) { 2) 1) "type" 2) "home" 3) 1) "number" 2) "212 555-1234" 3) 1) { 2) 1) "type" 2) "office" 3) 1) "number" 2) "555 555-4567" 9) 1) "children" 2) 1) [ 10) 1) "spouse" 2) (nil)