Recall & Review
beginner
What is the purpose of the SCAN command in Redis?
The SCAN command is used to safely iterate over keys in a Redis database without blocking the server or causing performance issues.
Click to reveal answer
beginner
How does SCAN differ from the KEYS command in Redis?
Unlike KEYS, which returns all matching keys at once and can block Redis, SCAN returns a small subset of keys per call, allowing safe, incremental iteration.
Click to reveal answer
intermediate
What does the cursor returned by SCAN represent?
The cursor is a position marker used by SCAN to keep track of the iteration state. You pass it back to SCAN to continue scanning from where you left off.
Click to reveal answer
intermediate
Why is SCAN considered 'safe' for key iteration in Redis?
Because SCAN returns keys in small batches and does not block the server, it allows other operations to continue smoothly, avoiding performance hits.
Click to reveal answer
intermediate
What is a common pattern to use SCAN to iterate all keys matching a pattern?
Start with cursor 0, call SCAN with MATCH pattern and COUNT options repeatedly, updating the cursor each time until it returns 0, collecting keys along the way.
Click to reveal answer
What does the SCAN command return in Redis?
✗ Incorrect
SCAN returns a cursor to continue scanning and a list of keys found in the current batch.
Why should you prefer SCAN over KEYS for large Redis databases?
✗ Incorrect
SCAN is incremental and non-blocking, making it safer for large datasets.
What does a cursor value of 0 mean when returned by SCAN?
✗ Incorrect
A cursor of 0 signals that the full iteration over keys is done.
Which option can you use with SCAN to filter keys by pattern?
✗ Incorrect
The MATCH option filters keys returned by SCAN to those matching a pattern.
What is the effect of the COUNT option in SCAN?
✗ Incorrect
COUNT hints how many keys SCAN should return in each batch, but it is not guaranteed.
Explain how to safely iterate over all keys in a Redis database using SCAN.
Think about how SCAN returns partial results and a cursor to continue.
You got /5 concepts.
Why is SCAN preferred over KEYS for production Redis environments?
Consider server performance and responsiveness.
You got /4 concepts.