Quick revision
The short answer
For big keys, redis-cli --bigkeys scans the keyspace with SCAN and reports the largest key per type by element count or length, --memkeys ranks keys by bytes using MEMORY USAGE, and an offline RDB analysis gives the full picture without touching production. For hot keys, --hotkeys reads LFU access counters and only works with an LFU eviction policy, and client-side counters per key are often the better source. All scanning tools add load, so run them on a replica, and never use KEYS in production.
What to remember
In this answer, we saw that --bigkeys finds the largest key per type by element count, --memkeys and MEMORY USAGE measure bytes, and offline RDB analysis covers every key without touching production. For hot keys, --hotkeys needs an LFU policy because it reads OBJECT FREQ, and client-side counters or a brief MONITOR capture are common alternatives. Every scanning tool adds load, so replicas are the right target, and SCAN, never KEYS, is the way to walk a keyspace.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
For big keys, redis-cli --bigkeys scans the keyspace with SCAN and reports the largest key per type by element count or length, --memkeys ranks keys by bytes using MEMORY USAGE, and an offline RDB analysis gives the full picture without touching production. For hot keys, --hotkeys reads LFU access counters and only works with an LFU eviction policy, and client-side counters per key are often the better source. All scanning tools add load, so run them on a replica, and never use KEYS in production.
Why this question is asked
Big keys and hot keys cause some of the worst Redis incidents, a delete that blocks a node or a promotion that saturates one shard, and they are hard to see from the application, which just sees slow calls. Interviewers ask how we find them because the obvious tools have pitfalls: some measure elements rather than bytes, one needs a specific eviction policy, and the one everyone knows, KEYS, can cause an outage itself. In this answer, we will define both problems, go through each tool and what it actually measures, and see how to use them without hurting the instance.
1A Quick Recap: Big Keys and Hot Keys
A big key holds a large value: a string of many megabytes, or a hash, list, set or sorted set with hundreds of thousands or millions of elements. Big keys hurt because commands on them take long on the single main thread, deleting them is slow, and moving them during resharding is hard.
A hot key receives a large share of all requests, for example a configuration key every request reads, or a counter for a viral item. Because a key lives in one slot on one primary, a hot key concentrates load on one thread of one node, however many nodes the cluster has. A key can be both, which is the worst case.
2Finding Big Keys With redis-cli
redis-cli --bigkeys walks the whole keyspace with SCAN and, for each key, asks for its type and size: STRLEN for strings, HLEN, LLEN, SCARD or ZCARD for collections. At the end it prints the biggest key of each type and a summary. Notice what it measures: element counts and string lengths, not bytes. A hash with 10,000 tiny fields can use less memory than one with 1,000 large values, but --bigkeys ranks it higher.
redis-cli --memkeys does the same walk but calls MEMORY USAGE on each key, so it ranks keys by bytes. It is slower and heavier, because MEMORY USAGE on a collection samples elements. Both tools add a steady stream of commands to the instance, and the -i option adds a sleep between SCAN calls to soften that. The safest habit is to run them against a replica, which holds the same data.
3Measuring One Key, and the Whole Keyspace Offline
MEMORY USAGE key returns the bytes used by one key and its value. For collections it samples 5 elements by default and extrapolates; SAMPLES n changes the sample, and SAMPLES 0 counts everything, which on a key with millions of elements is itself a slow command.
For a complete, safe view, the best tool is offline. Take an RDB snapshot (from a replica, or the latest backup) and run an RDB analysis tool on another machine. It parses every key and reports type, encoding, bytes, element count and TTL, which we can sort and group by prefix. Production is never touched, and the result covers every key, not just the biggest per type.
4Finding Hot Keys
redis-cli --hotkeys reports keys by access frequency. It works only when maxmemory-policy is an LFU policy, allkeys-lfu or volatile-lfu, because it reads the per-key access counter that Redis keeps for LFU eviction, through OBJECT FREQ. With an LRU policy or noeviction, the counter is not maintained and the tool refuses to run. The counter is also logarithmic and decays over time, so it ranks keys roughly rather than counting requests.
Often the client side is the easier place to look. If the application or a client library wrapper counts requests per key prefix, or per key for a sample of requests, and exports the counts as metrics, the hot key shows up in the dashboard with the service that calls it. A few seconds of MONITOR on the primary, piped into a script that counts keys, also works and gives exact counts, but MONITOR is expensive: it copies every command to the monitoring client, can cut throughput noticeably, and must stay brief.
| Tool | Measures | Cost and caveat |
|---|---|---|
| --bigkeys | largest key per type by elements or length | SCAN walk; run on a replica |
| --memkeys | keys ranked by bytes (MEMORY USAGE) | heavier walk; run on a replica |
| MEMORY USAGE key | bytes of one key, sampled | SAMPLES 0 is exact but slow |
| Offline RDB analysis | every key: type, encoding, bytes, TTL | no production load |
| --hotkeys | LFU access counters (OBJECT FREQ) | needs an LFU maxmemory-policy |
| Client metrics / brief MONITOR | requests per key | MONITOR is costly, keep it short |
5Why KEYS Is Never the Answer
KEYS pattern walks the entire keyspace in one command on the main thread. With 50 million keys that takes seconds, during which nothing else is served. SCAN does the same walk in small steps: each call returns a cursor and a batch of keys, about COUNT entries (10 by default) per call, and other clients run between the calls.
SCAN has its own rules. It guarantees that every key present for the whole scan is returned at least once, but it can return a key more than once, and keys added or deleted during the scan may or may not appear. So scripts that use SCAN should deduplicate or be safe to run twice on the same key.
6Follow-up questions
Why can SCAN return the same key twice?
SCAN walks the buckets of the keyspace hash table using a cursor that counts in reversed binary order, which keeps it correct when the table grows or shrinks. When a resize happens during the scan, keys move between buckets, and some buckets of the new table correspond to buckets of the old one that were already visited, so a key can be reported again. Redis accepts duplicates to avoid missing keys and to avoid keeping any state per scan on the server.
Is it safe to run --bigkeys on the primary?
It usually works, but it adds load to the one thread every client depends on, and MEMORY USAGE in --memkeys can be slow on big collections. On a busy primary we use a replica instead, or the offline RDB analysis, and if we must use the primary we add a sleep with -i.
Can we find hot keys without switching to an LFU policy?
Yes: client-side metrics, sampling of requests in a proxy, or a short MONITOR capture. Switching the eviction policy just to read counters changes which keys get evicted, so it is a decision in its own right.
7Conclusion
In this answer, we saw that --bigkeys finds the largest key per type by element count, --memkeys and MEMORY USAGE measure bytes, and offline RDB analysis covers every key without touching production. For hot keys, --hotkeys needs an LFU policy because it reads OBJECT FREQ, and client-side counters or a brief MONITOR capture are common alternatives. Every scanning tool adds load, so replicas are the right target, and SCAN, never KEYS, is the way to walk a keyspace.
Open with
For big keys I use redis-cli --bigkeys, which walks the keyspace with SCAN and reports the largest key per type by element count or string length, so it is about counts, not bytes. --memkeys ranks by bytes using MEMORY USAGE.
Then, if they want more
Both add load, so I run them against a replica, with a small sleep between calls. For a single key, MEMORY USAGE key with SAMPLES gives the bytes, and SAMPLES 0 is exact but slow on huge keys.
For the whole keyspace without touching production, I analyse an RDB file offline, which gives type, encoding, size and TTL for every key. For hot keys, redis-cli --hotkeys reads the LFU counters through OBJECT FREQ, so it only works when maxmemory-policy is allkeys-lfu or volatile-lfu.
Often hot keys are easier to find on the client side, with per-key or per-prefix request counters. A few seconds of MONITOR on the primary also works, but it is expensive and has to stay brief.
And I never run KEYS in production; SCAN with a COUNT is incremental and non-blocking, though it can return a key more than once, so whatever consumes it has to tolerate duplicates.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you find big keys and hot keys in a running Redis instance without hurting it...": https://scrivio-interview-library.netlify.app/databases/redis-internals/50f33f1479/