Back to Redis

JSON.DEBUG MEMORY

content/commands/json.debug-memory.md

latest2.2 KB
Original Source

Report a value's memory usage in bytes

{{< warning >}} The actual total memory consumption by a key could be much lower than the value reported by this command because of an internal JSON string reuse mechanism. For more information, see the [JSON memory usage page]({{< relref "/develop/data-types/json/ram#json-string-reuse-mechanism" >}}). {{< /warning >}}

Examples

Required arguments

<details open><summary><code>key</code></summary>

is key to parse.

</details>

Optional arguments

<details open><summary><code>path</code></summary>

is JSONPath to specify. Default is root $.

</details>

Examples

<details open> <summary><b>Report a value's memory usage in bytes</b></summary>

Create a JSON document.

{{< highlight bash >}} redis> JSON.SET item:2 $ '{"name":"Wireless earbuds","description":"Wireless Bluetooth in-ear headphones","connection":{"wireless":true,"type":"Bluetooth"},"price":64.99,"stock":17,"colors":["black","white"], "max_level":[80, 100, 120]}' OK {{< / highlight >}}

Get the values' memory usage in bytes.

{{< highlight bash >}} redis> JSON.DEBUG MEMORY item:2 (integer) 573 {{< / highlight >}}

</details>

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Flexible & Annual</span> <span title="Supported">✅ Free & Fixed</nobr></span> | |

Return information

{{< multitabs id="json-debug-memory-return-info" tab1="RESP2" tab2="RESP3" >}}

[Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}): the value size in bytes.

-tab-sep-

[Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}): the value size in bytes.

{{< /multitabs >}}

See also

[JSON.SET]({{< relref "commands/json.set/" >}}) | [JSON.ARRLEN]({{< relref "commands/json.arrlen/" >}})

  • [RedisJSON]({{< relref "/develop/data-types/json/" >}})
  • [Index and search JSON documents]({{< relref "/develop/ai/search-and-query/indexing/" >}})