You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/commands/json.debug-memory/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ title: JSON.DEBUG MEMORY
36
36
Report a value's memory usage in bytes
37
37
38
38
{{< warning >}}
39
-
The actual total memory consumption could be much lower than the reported value because of an internal JSON reference-counting mechanism.
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" >}}).
Copy file name to clipboardExpand all lines: content/develop/data-types/json/ram.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,6 @@ weight: 6
19
19
Because of ongoing feature additions, improvements, and optimizations, JSON memory consumption may vary depending on the Redis version.
20
20
Redis 8 in Redis Open Source was used for the examples on this page.
21
21
{{< /note >}}
22
-
<br />
23
-
{{< warning >}}
24
-
The actual total memory consumption could be much lower than the reported value because of an internal JSON reference-counting mechanism.
25
-
{{< /warning >}}
26
22
27
23
Every key in Redis takes memory and requires at least the amount of RAM to store the key name, as
28
24
well as some per-key overhead that Redis uses. On top of that, the value in the key also requires
@@ -127,3 +123,14 @@ JSON. The _MessagePack_ column is for reference purposes and reflects the length
127
123
128
124
> Note: In the current version, deleting values from containers **does not** free the container's
129
125
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.
135
+
136
+
Because the string cache is global and unaware of keys, documents, or shards, the reported per-key memory usage might overstate actual consumption, particularly when repeated strings are present.
0 commit comments