Consider the following Redis commands executed in sequence:
MULTI SET key1 value1 DISCARD GET key1
What will be the result of the GET key1 command?
MULTI SET key1 value1 DISCARD GET key1
Think about what DISCARD does to the queued commands in a transaction.
DISCARD cancels all commands queued in the current transaction. Since SET key1 value1 was discarded, key1 was never set. Therefore, GET key1 returns nil.
Which statement best describes the effect of the DISCARD command inside a Redis transaction?
Think about whether DISCARD executes or cancels commands.
DISCARD cancels all commands queued in the current transaction and ends the transaction without executing any commands.
Identify the command sequence that will cause a syntax error related to transaction commands.
Consider the order and validity of DISCARD and EXEC commands.
After EXEC is called, the transaction ends. Calling DISCARD after EXEC without a new MULTI causes a syntax error because there is no active transaction to discard.
In which scenario is using DISCARD preferable to EXEC in a Redis transaction?
Think about the difference between executing and aborting a transaction.
DISCARD is used to abort a transaction and discard all queued commands without executing them, which is useful if you decide not to proceed.
Given the following Redis commands:
MULTI SET key1 value1 DISCARD GET key1
Why does GET key1 return nil instead of "value1"?
Recall what DISCARD does to queued commands.
DISCARD cancels all commands queued in the transaction, so the SET command never runs. Therefore, key1 is not set and GET returns nil.