Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions content/commands/json.debug-memory/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ title: JSON.DEBUG MEMORY
---
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](#examples)

## Required arguments
Expand Down
9 changes: 9 additions & 0 deletions content/develop/data-types/json/ram.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ JSON. The _MessagePack_ column is for reference purposes and reflects the length

> Note: In the current version, deleting values from containers **does not** free the container's
allocated memory.

## JSON string reuse mechanism

Redis uses a global string reuse mechanism to reduce memory usage. When a string value appears multiple times, either within the same JSON document
or across different documents on the same node, Redis stores only a single copy of that string and uses references to it.
This approach is especially efficient when many documents share similar structures.

However, the `JSON.DEBUG MEMORY` command reports memory usage as if each string instance is stored independently, even when it's actually reused.
For example, the document `{"foo": ["foo", "foo"]}` reuses the string `"foo"` internally, but the reported memory usage counts the string three times: once for the key and once for each array element.