When you use Redis Insight's Database Analysis to prove which keys hold the memory on a shared staging Redis, what does the report measure and what can it miss?
answer
- a per-node sample, not an inventory
- which sections get multiplied, which do not
- total keys over processed keys
- namespace ends at the first delimiter
- SAMPLES 0 walks every element
basics
~10 sDatabase Analysis scans about 10,000 keys per node, reads each one's MEMORY USAGE, and reports by type, namespace, expiry and top keys, extrapolating some totals. It can miss a huge key outside the scan.
solid answer
~50 s**Database Analysis** is a per-node sample, not an inventory. It runs `SCAN` until it has covered about 10,000 keys per node, primaries only on Cluster, then calls `MEMORY USAGE key SAMPLES 0`, `TYPE` and `TTL` on each and builds totals by type, top namespaces, expiry groups and the top 15 keys. When more keys exist, the header shows the share scanned and most totals are multiplied by total keys over processed keys. So it points you at a suspect, but on millions of keys a big key outside the sample never appears, and one giant key inside it gets multiplied into nonsense. Top keys are not extrapolated, so they are only the largest seen. To prove the claim I check the scanned share, compare the extrapolated total with the server's own memory figure, and confirm the suspect key directly.
go deeper
Recall what the report shows: memory and key counts by data type, top namespaces, top keys, expiry groups and recommendations. Remember it may scan only part of the database.
Explain the steps: SCAN up to about 10,000 keys per node, then MEMORY USAGE, TYPE and TTL per key. Know which sections are extrapolated and that top keys is not.
Show how you would avoid being misled: read the scanned share, sanity-check the total against the server's figure, and confirm suspects directly. Say why absence from the table proves nothing.
Weigh the report against the need. It is a cheap lead on staging, but a recurring accounting of memory by team needs a complete traversal or a copy, with someone owning its accuracy.
## What the report actually runs The scenario is common: a developer with a GUI on a shared staging instance is asked to prove which keys use the memory. **Database Analysis** is the screen for it, and its report looks authoritative. Knowing how it is built tells you how far to trust it. 1. On a Cluster connection it picks the **primaries**; otherwise it uses the one node it is connected to. 2. It reads the node's total key count, and tries to list search indexes. 3. It runs `SCAN` from cursor 0 in batches of 2,000, stopping once its counter reaches 10,000 for that node. 4. For the keys returned, it sends three pipelines: `MEMORY USAGE key SAMPLES 0`, `TYPE key` and `TTL key`. 5. It sends one length command per key, chosen by type, such as `HLEN` or `STRLEN`. 6. It builds the report, generates recommendations, and stores the result locally as a dated report. ```text SCAN 0 count 2000 match * MEMORY USAGE user:42 samples 0 TYPE user:42 TTL user:42 HLEN user:42 ``` The word to notice is `SAMPLES 0`. It tells `MEMORY USAGE` to visit every nested value rather than estimate from five, so the size of each key is accurate, but a key with millions of elements costs a full walk on the server. The report is therefore not free, even on staging. ## What it shows | Section | How it is built | Extrapolated? | |---|---|---| | Summary per data type | Memory and key count summed by type | Yes | | Memory likely to be freed | Memory grouped by TTL, from `No Expiry` to `>1 Month` | Yes | | Top namespaces | Top 15 by memory and by key count | Yes | | Top keys | Top 15 by memory and by length | **No** | | Recommendations | Rules run over scanned keys and server replies | Not a measurement | The header states what was scanned, as a percentage and as processed keys over total keys. An **Extrapolate results** switch appears when the two differ, and turns the multiplication off. ## Where it misleads - **Coverage can be tiny.** On 20 million keys, 10,000 is 0.05%. `SCAN` order follows the hash table rather than size or age, so this is an arbitrary slice with no guarantee of being representative. - **The biggest key may be absent.** Top keys ranks only what the scan reached. A single huge key outside the slice appears nowhere in the report. - **Outliers are amplified.** The factor is total keys divided by processed keys. With a factor of 2,000, one 1 GB key that happens to be inside the slice adds about 2 TB to the extrapolated total. - **A namespace is the text before the first delimiter.** `app:session:42` counts under `app`, not `app:session`, and a key with no delimiter is left out of the namespace tables altogether. - **Key sizes are not the whole process.** The report sums per-key figures, so it says nothing about fragmentation or client buffers, which are covered with memory analysis. - **Running it again adds little coverage.** Each run starts from cursor 0, so on a stable keyspace it largely reads the same slice. Reruns are good for comparing trends, not for widening the sample. ## Proving the claim 1. **Read the header first.** Note the share scanned and work out the factor. 2. **Sanity-check the total.** Compare the extrapolated memory with what the server itself reports. A result far above it means an outlier was multiplied, so turn extrapolation off and read the raw figures. 3. **Treat namespaces as leads.** Filter Browser by the suspect prefix and look at real keys and sizes. 4. **Check that a key the report names really is large,** and be clear that the absence of a key from the table proves nothing. 5. **For a claim that needs certainty,** use a full traversal or analyse a copy, because that is what covers every key. 6. **Report it honestly:** say what share was scanned, and whether figures are measured or extrapolated. ## Recommendations The report also produces **recommendations**, such as big hashes, big sets and strings, combining small strings into hashes, list compression, too many Lua scripts or connected clients, multiple logical databases, or no password set. They are simple rules: many ask whether any scanned key crosses a threshold, and others read `INFO` or `CONFIG GET`. Treat them as prompts to investigate. They do not know your workload, and because they inherit the sample they can stay silent about a key the scan never reached. A user who cannot run `CONFIG GET` simply does not get the rules that need it, with no notice in the report, because the provider catches the error and returns nothing.
- Why can a Redis Insight Database Analysis total come out larger than the memory the server is using?Because the total is the sampled sum multiplied by total keys over processed keys. If one very large key falls inside the slice, its size is multiplied too. Compare with the server's own memory figure, and turn off **Extrapolate results** to see what was actually measured.
- Does running Redis Insight's Database Analysis several times widen its coverage?Not usefully. Each run starts `SCAN` from cursor 0 with the same limit, so on a stable keyspace it reads largely the same slice. Stored reports are good for comparing change over time. Certainty about every key needs a full traversal or an analysis of a copy.
- How much should you trust a recommendation from Redis Insight's Database Analysis?As a prompt, not a finding. Each is a simple rule over scanned keys or server replies, such as whether any scanned hash crosses a length threshold. It does not know your access patterns, and it inherits the sample's blind spots. Check the trade-off before changing data shapes or settings.
It is like estimating a warehouse's contents by opening a fixed number of boxes and multiplying: fair for the typical mix, blind to the crate you never opened, and badly wrong if one box you did open holds a piano.
- Database Analysis reads every key, so its top keys table is the true top 15.
- Extrapolated totals are measured values that you can quote as exact.
- Running the report again scans a new part of the keyspace and improves coverage.
- The report costs nothing on the server because it only uses SCAN.
- A namespace in the report is everything before the last delimiter in the key.
- A recommendation in the report is a measured finding you should apply directly.