0
0
Redisquery~10 mins

Cache invalidation strategies 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 set a cache key with an expiration time in Redis.

Redis
redis.set('user:123', 'data', [1]=3600)
Drag options to blanks, or click blank then click option'
Aex
Bexpire
Ctimeout
Dttl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'expire' which is a separate command, not a parameter here.
Using 'ttl' which returns time to live, not sets it.
2fill in blank
medium

Complete the code to delete a cache key in Redis.

Redis
redis.[1]('user:123')
Drag options to blanks, or click blank then click option'
Aremove
Bdel
Cdelete
Dunset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'del' which is the Redis protocol command but not the Python client method.
Using 'remove' or 'unset' which are not Redis client methods.
3fill in blank
hard

Fix the error in the code to check if a cache key exists in Redis.

Redis
exists = redis.[1]('user:123')
Drag options to blanks, or click blank then click option'
Ahas
Bexists
Ccontains
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'has' or 'contains' which are not Redis commands.
Using 'check' which is not a Redis command.
4fill in blank
hard

Fill both blanks to set a cache key with a value and expiration time using Redis pipeline.

Redis
pipe = redis.pipeline()
pipe.set('session:[1]', '[2]')
pipe.expire('session:123', 1800)
pipe.execute()
Drag options to blanks, or click blank then click option'
A123
Bactive
Cuser
Dinactive
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching key suffix and expire key.
Using 'inactive' instead of 'active' for session state.
5fill in blank
hard

Fill all three blanks to implement a cache invalidation strategy that deletes a key and logs the action.

Redis
def invalidate_cache(redis, key):
    redis.[1](key)
    log_message = f"Cache key [2] invalidated at [3]"
    print(log_message)
Drag options to blanks, or click blank then click option'
Adel
Bkey
Cdatetime.now()
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'del' instead of 'delete' for Redis client method.
Not using the key variable in the log message.
Not including current time in the log.