0
0
Redisquery~10 mins

Cache-aside (lazy loading) deep dive 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 fetch data from cache or load from database if missing.

Redis
value = redis_client.get([1])
if value is None:
    value = db_load(key)
    redis_client.set(key, value)
Drag options to blanks, or click blank then click option'
Akey
B'key'
Cvalue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string literal instead of the variable key.
2fill in blank
medium

Complete the code to set the cache expiration time after loading from database.

Redis
if value is None:
    value = db_load(key)
    redis_client.set(key, value, [1]=3600)
Drag options to blanks, or click blank then click option'
Attl
Bex
Ctimeout
Dexpire
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'timeout' or 'ttl'.
3fill in blank
hard

Fix the error in the cache-aside pattern code to avoid race conditions.

Redis
value = redis_client.get(key)
if value is None:
    [1]
    redis_client.set(key, value, ex=3600)
Drag options to blanks, or click blank then click option'
Avalue = None
Bvalue = redis_client.get(key)
Cvalue = db_load(key)
Dvalue = cache_load(key)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get from cache again inside the miss block.
4fill in blank
hard

Fill both blanks to implement cache-aside with explicit cache invalidation.

Redis
def update_data(key, new_value):
    db_update(key, new_value)
    redis_client.[1](key)
    redis_client.[2](key, new_value, ex=3600)
Drag options to blanks, or click blank then click option'
Adelete
Bset
Cdel
Dexpire
Attempts:
3 left
💡 Hint
Common Mistakes
Using del which is not a Redis client method.
5fill in blank
hard

Fill all three blanks to implement cache-aside with fallback and expiration.

Redis
def get_data(key):
    value = redis_client.[1](key)
    if value is None:
        value = db_load([2])
        redis_client.[3](key, value, ex=3600)
    return value
Drag options to blanks, or click blank then click option'
Aget
Bkey
Cset
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'load' or wrong variable names.