0
0
Redisquery~10 mins

Write-through pattern 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 key-value pair in Redis cache.

Redis
redis_client.[1]('user:1', 'Alice')
Drag options to blanks, or click blank then click option'
Aset
Bget
Cdelete
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' to store data.
2fill in blank
medium

Complete the code to update the database after setting the cache in write-through pattern.

Redis
database.[1]('UPDATE users SET name = %s WHERE id = %s', ('Alice', 1))
Drag options to blanks, or click blank then click option'
Acommit
Bfetch
Cexecute
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fetch' which is for retrieving data, not updating.
3fill in blank
hard

Fix the error in the write-through update code by completing the missing Redis command.

Redis
def write_through_update(key, value):
    redis_client.[1](key, value)
    database.execute('UPDATE users SET name = %s WHERE id = %s', (value, 1))
    database.commit()
Drag options to blanks, or click blank then click option'
Aset
Bget
Cdelete
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' which only reads data, not updates.
4fill in blank
hard

Fill both blanks to complete the write-through pattern: update cache and then update database.

Redis
def write_through_update(key, value):
    redis_client.[1](key, value)
    database.[2]('UPDATE users SET name = %s WHERE id = %s', (value, 1))
    database.commit()
Drag options to blanks, or click blank then click option'
Aset
Bexecute
Cget
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'set' and 'execute' commands.
5fill in blank
hard

Fill all three blanks to implement a write-through update: set cache key, execute DB update, and commit transaction.

Redis
def write_through_update(key, value):
    redis_client.[1](key, value)
    database.[2]('UPDATE users SET name = %s WHERE id = %s', (value, 1))
    database.[3]()
Drag options to blanks, or click blank then click option'
Aget
Bexecute
Ccommit
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to commit the database transaction.