0
0
Redisquery~20 mins

Cache-aside pattern in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache-Aside Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Cache Miss Handling in Cache-Aside Pattern

In the cache-aside pattern, what happens when the requested data is not found in the cache?

AThe cache automatically fetches data from the database and updates itself without application intervention.
BThe application returns an error immediately without querying the database.
CThe application fetches data from the database, stores it in the cache, then returns it.
DThe cache deletes the missing key and waits for the database to push data.
Attempts:
2 left
💡 Hint

Think about who is responsible for loading data into the cache when it is missing.

query_result
intermediate
2:00remaining
Result of Cache-Aside Data Retrieval Sequence

Given the following sequence in a cache-aside pattern using Redis:
1. Application checks Redis key 'user:123'.
2. Key is missing.
3. Application queries database and gets user data: {"id":123, "name":"Alice"}.
4. Application stores this data in Redis under 'user:123'.
5. Application reads 'user:123' from Redis.
What is the output of the final Redis read?

A{"id":123, "name":"Alice"}
Bnull
C"user:123"
DAn error because Redis cannot store JSON
Attempts:
2 left
💡 Hint

Consider what data was stored in Redis and what is returned when reading that key.

📝 Syntax
advanced
2:00remaining
Identify the Correct Redis Command to Store Data in Cache-Aside Pattern

Which Redis command correctly stores the user data JSON string '{"id":123, "name":"Alice"}' under the key 'user:123'?

ASET user:123 '{"id":123, "name":"Alice"}'
BGET user:123 '{"id":123, "name":"Alice"}'
CPUT user:123 '{"id":123, "name":"Alice"}'
DSTORE user:123 '{"id":123, "name":"Alice"}'
Attempts:
2 left
💡 Hint

Remember the Redis command to set a key's value.

optimization
advanced
2:00remaining
Optimizing Cache Expiration in Cache-Aside Pattern

To prevent stale data in a cache-aside pattern, which approach optimizes cache expiration for user data in Redis?

ANever expire cached keys to ensure data is always available.
BSet a TTL (time-to-live) on cached keys to automatically expire after a fixed time.
CManually delete keys only when the database is updated, without TTL.
DUse Redis transactions to lock keys indefinitely.
Attempts:
2 left
💡 Hint

Think about automatic ways to keep cache fresh without manual intervention.

🔧 Debug
expert
3:00remaining
Diagnosing Cache Inconsistency in Cache-Aside Pattern

An application uses the cache-aside pattern with Redis. After updating user data in the database, the cache is not updated, causing stale data to be served. What is the most likely cause?

AThe cache key expired too soon, causing stale data.
BRedis automatically updates cached data when the database changes.
CThe database update failed silently, so cache was correct.
DThe application did not invalidate or update the Redis cache after the database update.
Attempts:
2 left
💡 Hint

Consider the responsibilities of the application in cache-aside pattern after database writes.