Skip to content

Commit 80a37fa

Browse files
committed
Apply more review comments
1 parent 8181497 commit 80a37fa

File tree

2 files changed

+12
-5
lines changed
  • content

2 files changed

+12
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ title: JSON.DEBUG MEMORY
3636
Report a value's memory usage in bytes
3737

3838
{{< 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" >}}).
4040
{{< /warning >}}
4141

4242
[Examples](#examples)

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ weight: 6
1919
Because of ongoing feature additions, improvements, and optimizations, JSON memory consumption may vary depending on the Redis version.
2020
Redis 8 in Redis Open Source was used for the examples on this page.
2121
{{< /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 >}}
2622

2723
Every key in Redis takes memory and requires at least the amount of RAM to store the key name, as
2824
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
127123

128124
> Note: In the current version, deleting values from containers **does not** free the container's
129125
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

Comments
 (0)