Complete the code to add a key-value pair to Redis cache.
redis_client.[1]('user:1', 'John Doe')
The set command stores a key-value pair in Redis.
Complete the code to retrieve the value of a key from Redis cache.
value = redis_client.[1]('user:1')
The get command retrieves the value of a key from Redis.
Fix the error in the code to schedule a write-behind update after caching.
def update_cache_and_db(key, value): redis_client.set(key, value) schedule_write_[1](key, value)
The write-behind pattern schedules updates to the database after caching, so schedule_write_behind is the correct function name.
Fill both blanks to create a dictionary for pending writes with keys and values.
pending_writes = { [1]: [2] for [1] in cache_keys }We use key as the dictionary key and cache[key] as the value to map keys to their cached values.
Fill all three blanks to filter keys with pending writes and update the database.
for [1] in pending_writes: if pending_writes[[2]] [3] None: update_database([1], pending_writes[[2]])
We loop over key, check if the value is not None using !=, then update the database.