Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the key exists in Redis cache.
Redis
if redis_client.[1](key):
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'exists' returns the value, not presence.
Using 'set' or 'delete' changes data instead of checking.
✗ Incorrect
The exists command checks if a key is present in Redis.
2fill in blank
mediumComplete the code to retrieve a value from Redis cache.
Redis
value = redis_client.[1](key) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exists' returns a boolean, not the value.
Using 'set' writes data, not reads it.
✗ Incorrect
The get command fetches the value stored at the given key.
3fill in blank
hardFix the error in the code to store data in Redis cache.
Redis
redis_client.[1](key, value) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' tries to read instead of write.
Using 'exists' checks presence, not store.
✗ Incorrect
The set command stores a value at the given key in Redis.
4fill in blank
hardFill both blanks to implement cache-aside pattern: check cache and fetch from DB if missing.
Redis
if redis_client.[1](key): value = redis_client.[2](key) else: value = fetch_from_db(key)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check presence causes errors if key missing.
Using 'set' or 'delete' in place of 'get' is incorrect.
✗ Incorrect
First, exists checks if key is in cache. Then, get retrieves the value.
5fill in blank
hardFill all three blanks to complete cache-aside: fetch from DB, store in cache, then return value.
Redis
if not redis_client.[1](key): value = fetch_from_db(key) redis_client.[2](key, value) else: value = redis_client.[3](key)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check presence causes errors.
Forgetting to store fetched data in cache.
✗ Incorrect
Check if key exists. If not, fetch from DB and set in cache. Otherwise, get from cache.