Complete the code to fetch data from cache or load from database if missing.
value = redis_client.get([1]) if value is None: value = db_load(key) redis_client.set(key, value)
The cache key variable should be passed to get to fetch the cached value.
Complete the code to set the cache expiration time after loading from database.
if value is None: value = db_load(key) redis_client.set(key, value, [1]=3600)
Redis set method uses ex to set expiration time in seconds.
Fix the error in the cache-aside pattern code to avoid race conditions.
value = redis_client.get(key) if value is None: [1] redis_client.set(key, value, ex=3600)
When cache miss happens, load data from the database to avoid race conditions.
Fill both blanks to implement cache-aside with explicit cache invalidation.
def update_data(key, new_value): db_update(key, new_value) redis_client.[1](key) redis_client.[2](key, new_value, ex=3600)
del which is not a Redis client method.Use delete to remove old cache, then set to update cache with new value.
Fill all three blanks to implement cache-aside with fallback and expiration.
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
Use get to fetch from cache, key to load from DB, and set to cache the value.
