0
0
Redisquery~20 mins

Why caching patterns matter in Redis - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Caching Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What happens when you cache data without expiration?

Consider a Redis cache where keys are set without expiration time. What is the likely outcome after continuous data updates?

Redis
SET user:123 "John Doe"
# No expiration set
AThe cache will automatically clear old keys to save space.
BThe cache will grow indefinitely, possibly causing memory issues.
CRedis will throw an error when memory is full.
DThe cached data will expire after 24 hours by default.
Attempts:
2 left
💡 Hint

Think about what happens if keys never expire and new data keeps adding.

🧠 Conceptual
intermediate
2:00remaining
Why use cache aside pattern?

Which benefit best explains why the cache aside pattern is used in caching?

AIt allows the application to control when to load data into the cache, reducing stale data.
BIt ensures the cache is always updated automatically without application logic.
CIt forces Redis to handle all database writes directly.
DIt disables caching for write-heavy applications.
Attempts:
2 left
💡 Hint

Think about who controls the cache loading in cache aside.

📝 Syntax
advanced
2:00remaining
Which Redis command sets a key with expiration in one step?

Choose the Redis command that sets a key "session:1" with value "active" and expires after 60 seconds.

ASET session:1 active EX 60
BEXPIRE session:1 60 SET active
CSET session:1 active PX 60000
DSETEX session:1 60 active
Attempts:
2 left
💡 Hint

Look for the command that combines setting and expiration in one.

optimization
advanced
2:00remaining
How to avoid cache stampede in Redis?

When many clients request the same missing cache key simultaneously, what is a good strategy to prevent all from querying the database at once?

AUse a distributed lock to allow only one client to load data and others wait.
BIncrease Redis memory to handle more keys.
CDisable caching for hot keys to avoid stale data.
DSet very short expiration times to refresh cache frequently.
Attempts:
2 left
💡 Hint

Think about controlling who loads data when cache is missing.

🔧 Debug
expert
3:00remaining
Why does this Redis cache update fail to reflect new data?

Given this sequence:
1. Cache key "product:10" set with old data.
2. Database updated with new product info.
3. Cache key deleted.
4. Application reads cache key "product:10" expecting new data.
Why might the application still see old data?

ARedis does not support deleting keys, so cache remains unchanged.
BThe cache was deleted before the database update, so stale data was re-cached.
CThe cache deletion and database update were not atomic, causing race condition.
DThe application is reading from the database, not the cache.
Attempts:
2 left
💡 Hint

Consider timing between cache deletion and database update.