0
0
Redisquery~10 mins

Write-behind 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 add a key-value pair to Redis cache.

Redis
redis_client.[1]('user:1', 'John Doe')
Drag options to blanks, or click blank then click option'
Aexpire
Bset
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' to store data.
Using 'expire' which sets a timeout, not stores data.
2fill in blank
medium

Complete the code to retrieve the value of a key from Redis cache.

Redis
value = redis_client.[1]('user:1')
Drag options to blanks, or click blank then click option'
Aget
Bset
Cdelete
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' instead of 'get' to retrieve data.
Using 'exists' which only checks if a key exists.
3fill in blank
hard

Fix the error in the code to schedule a write-behind update after caching.

Redis
def update_cache_and_db(key, value):
    redis_client.set(key, value)
    schedule_write_[1](key, value)
Drag options to blanks, or click blank then click option'
Aahead
Bnow
Cbehind
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'schedule_write_ahead' which is the opposite pattern.
Using 'schedule_write_now' which is immediate writing, not delayed.
4fill in blank
hard

Fill both blanks to create a dictionary for pending writes with keys and values.

Redis
pending_writes = { [1]: [2] for [1] in cache_keys }
Drag options to blanks, or click blank then click option'
Akey
Bcache[key]
Cvalue
Dcache[value]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' as the loop variable which is undefined.
Using 'cache[value]' which is incorrect indexing.
5fill in blank
hard

Fill all three blanks to filter keys with pending writes and update the database.

Redis
for [1] in pending_writes:
    if pending_writes[[2]] [3] None:
        update_database([1], pending_writes[[2]])
Drag options to blanks, or click blank then click option'
Akey
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' which would skip updates.
Using different variable names for loop and dictionary access.