Complete the code to set a key-value pair in Redis.
redis_client.[1]('user:1', 'Alice')
The set command stores a value for a key in Redis.
Complete the code to retrieve a value by key from Redis.
value = redis_client.[1]('user:1')
The get command fetches the value stored at a given key.
Fix the error in the code to set a key with expiration time.
redis_client.set('session:123', 'active', [1]=3600)
The ex parameter sets the expiration time in seconds when using set.
Fill both blanks to implement a cache check and set pattern.
value = redis_client.[1]('item:42') if value is None: value = fetch_from_db('item:42') redis_client.[2]('item:42', value, ex=300)
First, get tries to read from cache. If missing, fetch from DB and set caches it with expiration.
Fill all three blanks to implement a cache invalidation after update.
redis_client.[1]('product:99') update_database('product:99', new_data) redis_client.[2]('product:99', new_data) redis_client.[3]('product:99', 600)
First, delete old cache with delete. Then update DB and cache with set. Finally, set expiration with expire.
