JSON.DEBUG - Amazon MemoryDB
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

JSON.DEBUG

报告信息。支持的子命令有:

  • MEMORY<key>[path]-以JSON值的字节为单位报告内存使用情况。如果未提供,则路径默认为根目录。

  • DEPTH<key>[path]-报告JSON文档的最大路径深度。

    注意

    此子命令仅在 Valkey 7.2 或更高版本或 Redis OSS 引擎版本 6.2.6.R2 或更高版本中可用。

  • FIELDS<key>[path]-报告指定文档路径上的字段数。如果未提供,则路径默认为根目录。每个非容器JSON值都算作一个字段。对象和数组以递归方式计算每个包含JSON值的字段。除根容器外,每个容器值均计为一个额外字段。

  • HELP— 打印命令的帮助消息。

语法

JSON.DEBUG <subcommand & arguments>

取决于子命令:

MEMORY

  • 如果路径是增强的语法:

    • 返回一个整数数组,表示每个路径上JSON值的内存大小(以字节为单位)。

    • 如果密钥不存在,则返回一个空数组。

  • 如果路径是受限的语法:

    • 返回一个整数,内存大小以字节为单位的JSON值。

    • 如果密钥不存在,则返回 null。

DEPTH

  • 返回一个表示JSON文档最大路径深度的整数。

  • 如果密钥不存在,则返回 null。

FIELDS

  • 如果路径是增强的语法:

    • 返回一个整数数组,表示每条路径的JSON值字段数。

    • 如果密钥不存在,则返回一个空数组。

  • 如果路径是受限的语法:

    • 返回一个整数,即该JSON值的字段数。

    • 如果密钥不存在,则返回 null。

HELP— 返回一组帮助消息。

示例

增强的路径语法:

127.0.0.1:6379> JSON.SET k1 . '[1, 2.3, "foo", true, null, {}, [], {"a":1, "b":2}, [1,2,3]]' OK 127.0.0.1:6379> JSON.DEBUG MEMORY k1 $[*] 1) (integer) 16 2) (integer) 16 3) (integer) 19 4) (integer) 16 5) (integer) 16 6) (integer) 16 7) (integer) 16 8) (integer) 50 9) (integer) 64 127.0.0.1:6379> JSON.DEBUG FIELDS k1 $[*] 1) (integer) 1 2) (integer) 1 3) (integer) 1 4) (integer) 1 5) (integer) 1 6) (integer) 0 7) (integer) 0 8) (integer) 2 9) (integer) 3

受限的路径语法:

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.DEBUG MEMORY k1 (integer) 632 127.0.0.1:6379> JSON.DEBUG MEMORY k1 .phoneNumbers (integer) 166 127.0.0.1:6379> JSON.DEBUG FIELDS k1 (integer) 19 127.0.0.1:6379> JSON.DEBUG FIELDS k1 .address (integer) 4 127.0.0.1:6379> JSON.DEBUG HELP 1) JSON.DEBUG MEMORY <key> [path] - report memory size (bytes) of the JSON element. Path defaults to root if not provided. 2) JSON.DEBUG FIELDS <key> [path] - report number of fields in the JSON element. Path defaults to root if not provided. 3) JSON.DEBUG HELP - print help message.