0
0
Redisquery~10 mins

Cache-aside pattern in Redis - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the key exists in Redis cache.

Redis
if redis_client.[1](key):
Drag options to blanks, or click blank then click option'
Aexists
Bget
Cset
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'exists' returns the value, not presence.
Using 'set' or 'delete' changes data instead of checking.
2fill in blank
medium

Complete the code to retrieve a value from Redis cache.

Redis
value = redis_client.[1](key)
Drag options to blanks, or click blank then click option'
Aget
Bset
Cexists
Dexpire
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exists' returns a boolean, not the value.
Using 'set' writes data, not reads it.
3fill in blank
hard

Fix the error in the code to store data in Redis cache.

Redis
redis_client.[1](key, value)
Drag options to blanks, or click blank then click option'
Adelete
Bexists
Cget
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' tries to read instead of write.
Using 'exists' checks presence, not store.
4fill in blank
hard

Fill both blanks to implement cache-aside pattern: check cache and fetch from DB if missing.

Redis
if redis_client.[1](key):
    value = redis_client.[2](key)
else:
    value = fetch_from_db(key)
Drag options to blanks, or click blank then click option'
Aexists
Bget
Cset
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check presence causes errors if key missing.
Using 'set' or 'delete' in place of 'get' is incorrect.
5fill in blank
hard

Fill all three blanks to complete cache-aside: fetch from DB, store in cache, then return value.

Redis
if not redis_client.[1](key):
    value = fetch_from_db(key)
    redis_client.[2](key, value)
else:
    value = redis_client.[3](key)
Drag options to blanks, or click blank then click option'
Aexists
Bset
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check presence causes errors.
Forgetting to store fetched data in cache.