Recall & Review
beginner
What does the
WATCH command do in Redis?The
WATCH command monitors one or more keys for changes. If any watched key changes before the transaction executes, the transaction is aborted to avoid conflicts.Click to reveal answer
intermediate
Explain optimistic locking in Redis using
WATCH.Optimistic locking assumes no conflicts will happen. Redis uses
WATCH to monitor keys. If keys change before EXEC, the transaction fails, so you can retry safely.Click to reveal answer
beginner
What happens if a watched key is modified before
EXEC in Redis?The transaction is aborted and
EXEC returns null. This prevents conflicting updates and ensures data consistency.Click to reveal answer
intermediate
How do you retry a transaction after a
WATCH aborts in Redis?You can retry by re-watching the keys and re-executing the transaction commands in a loop until
EXEC succeeds.Click to reveal answer
advanced
Why is
WATCH considered optimistic locking instead of pessimistic locking?Because it does not lock keys upfront. It only checks for changes at commit time, assuming conflicts are rare and handling them if they occur.
Click to reveal answer
What does Redis do if a key watched by
WATCH changes before EXEC?✗ Incorrect
If a watched key changes, Redis aborts the transaction to avoid conflicts and returns null.
Which Redis command is used to start monitoring keys for optimistic locking?
✗ Incorrect
WATCH is used to monitor keys for changes before running a transaction.What is the purpose of optimistic locking in Redis?
✗ Incorrect
Optimistic locking assumes no conflicts and checks for them only when committing.
Which command executes all commands in a Redis transaction after
WATCH?✗ Incorrect
EXEC runs all queued commands in the transaction if no watched keys changed.If a Redis transaction fails due to
WATCH, what should you do next?✗ Incorrect
You should retry by watching keys again and re-executing the transaction.
Describe how Redis uses the
WATCH command to implement optimistic locking.Think about how Redis checks for conflicts only at commit time.
You got /4 concepts.
Explain the difference between optimistic locking with
WATCH and pessimistic locking.Focus on when locking happens and how conflicts are handled.
You got /4 concepts.