Skip to content

Commit a9cc6c9

Browse files
authored
DEV: (MOD-9575) memory reporting updates (#1508)
* DEV: (MOD-9575) memory reporting updates * Apply review comments. * Apply more review comments * Apply more review comments
1 parent ee234c9 commit a9cc6c9

File tree

2 files changed

+13
-0
lines changed
  • content

2 files changed

+13
-0
lines changed

content/commands/json.debug-memory/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ title: JSON.DEBUG MEMORY
3535
---
3636
Report a value's memory usage in bytes
3737

38+
{{< warning >}}
39+
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" >}}).
40+
{{< /warning >}}
41+
3842
[Examples](#examples)
3943

4044
## Required arguments

content/develop/data-types/json/ram.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ JSON. The _MessagePack_ column is for reference purposes and reflects the length
123123

124124
> Note: In the current version, deleting values from containers **does not** free the container's
125125
allocated memory.
126+
127+
## JSON string reuse mechanism
128+
129+
Redis uses a global string reuse mechanism to reduce memory usage. When a string value appears multiple times, either within the same JSON document
130+
or across different documents on the same node, Redis stores only a single copy of that string and uses references to it.
131+
This approach is especially efficient when many documents share similar structures.
132+
133+
However, the `JSON.DEBUG MEMORY` command reports memory usage as if each string instance is stored independently, even when it's actually reused.
134+
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.

0 commit comments

Comments
 (0)