diff --git a/content/commands/json.debug-memory/index.md b/content/commands/json.debug-memory/index.md index d119304917..534fdbb222 100644 --- a/content/commands/json.debug-memory/index.md +++ b/content/commands/json.debug-memory/index.md @@ -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 diff --git a/content/develop/data-types/json/ram.md b/content/develop/data-types/json/ram.md index d7f174264c..2d3efe4f4b 100644 --- a/content/develop/data-types/json/ram.md +++ b/content/develop/data-types/json/ram.md @@ -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. \ No newline at end of file