yoklainterview sim

Database Redis Transactions Scripting Interview Questions

75 verified Database Redis Transactions Scripting interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Redis Transactions ScriptingDifficulty 1
What does the MULTI command do in Redis?
  • aImmediately runs several commands in parallel on separate worker threads and returns their combined replies
  • bMarks the start of a transaction block; subsequent commands are queued instead of executed
  • cOpens a new connection so multiple clients can share one transaction
  • dDuplicates the current database into a second logical database
Explanation:MULTI starts a transaction block. Every command issued after it (until EXEC or DISCARD) is queued on the connection rather than run immediately.
Redis Transactions ScriptingDifficulty 1
Which command actually executes the commands queued after MULTI?
  • aCOMMIT
  • bRUN
  • cEXEC
  • dFLUSH
Explanation:EXEC executes all commands queued since MULTI, atomically, and returns their replies as an array.
Redis Transactions ScriptingDifficulty 1
What does DISCARD do inside an open Redis transaction?
  • aCancels the transaction and clears the queued commands without running them
  • bRuns every queued command, returns their replies, and then rolls back all resulting changes before closing the transaction
  • cDeletes the key that was being watched
  • dRemoves only the last queued command, keeping the rest
Explanation:DISCARD flushes the queued command list and closes the transaction; nothing in it is executed.
Redis Transactions ScriptingDifficulty 2
What is WATCH used for in a Redis transaction?
  • aLogging every command executed inside the transaction to a file
  • bBlocking every other client from reading or writing the watched key until the watching connection commits or disconnects
  • cPeriodically refreshing a key's TTL while the transaction is open
  • dMaking the following EXEC abort if any watched key was modified since the WATCH
Explanation:WATCH key implements optimistic locking: if the watched key changes (by any client) between WATCH and EXEC, the transaction aborts and EXEC returns a null reply instead of running the queued commands.
Redis Transactions ScriptingDifficulty 2
WATCH balance
val = GET balance
MULTI
SET balance <val - 10>
EXEC

What happens if another client changes balance right after the GET but before EXEC?
  • aEXEC runs anyway, overwriting the other client's change with the stale value
  • bEXEC returns null (nil array), and the SET is never applied
  • cRedis merges both writes automatically using the latest value
  • dThe WATCH call itself raises an error at that point
Explanation:Because balance was modified after WATCH and before EXEC, the transaction aborts: EXEC returns a nil reply, and none of the queued commands (the SET) run. The application must detect this and retry.
Redis Transactions ScriptingDifficulty 2
Does Redis support rolling back individual commands inside a transaction if one of them fails at runtime (e.g. wrong type error)?
  • aNo — other commands in the same EXEC still run; Redis transactions have no per-command rollback
  • bYes — a runtime failure automatically undoes every earlier successful command and prevents all later queued commands from running
  • cYes, but only if WATCH was used before MULTI
  • dNo — the entire connection is closed and the client must reconnect
Explanation:Redis transactions don't support rollback. If a command fails at runtime during EXEC (e.g. calling a list command on a string key), the other queued commands still execute; only that one command's error is reported in the reply array.

Test yourself against the 2475-question Database bank.

Start interview