Redis & Caching (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
Why is `KEYS *` dangerous in production and what should you use instead?
junior LevelredisBasic
In Simple Words:
KEYS * runs a linear $O(N)$ scan across all keys in the database:
- Because Redis is single-threaded, a database with 10 million keys will freeze completely for seconds or minutes, blocking all other web requests and triggering production outages!
- Solution: Always use
SCAN(SSCAN,HSCAN,ZSCAN), which iterates over keys incrementally using a cursor in small, non-blocking batches without stalling the server.