Complete the code to set a cache key with an expiration time in Redis.
redis.set('user:123', 'data', [1]=3600)
The ex parameter sets the expiration time in seconds when setting a key in Redis.
Complete the code to delete a cache key in Redis.
redis.[1]('user:123')
The Redis Python client method to delete a key is delete.
Fix the error in the code to check if a cache key exists in Redis.
exists = redis.[1]('user:123')
The Redis command to check if a key exists is exists.
Fill both blanks to set a cache key with a value and expiration time using Redis pipeline.
pipe = redis.pipeline() pipe.set('session:[1]', '[2]') pipe.expire('session:123', 1800) pipe.execute()
The key suffix is '123' and the value is 'active' to represent an active session.
Fill all three blanks to implement a cache invalidation strategy that deletes a key and logs the action.
def invalidate_cache(redis, key): redis.[1](key) log_message = f"Cache key [2] invalidated at [3]" print(log_message)
The delete method deletes the key, key is the variable name, and datetime.now() gets the current time for logging.