0
0
Redisquery~20 mins

DISCARD to abort in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Transaction Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output after DISCARD aborts a transaction?

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?

Redis
MULTI
SET key1 value1
DISCARD
GET key1
A"(empty string)"
Bnil (key1 does not exist)
CError: EXEC without MULTI
D"value1"
Attempts:
2 left
💡 Hint

Think about what DISCARD does to the queued commands in a transaction.

🧠 Conceptual
intermediate
2:00remaining
What does DISCARD do in a Redis transaction?

Which statement best describes the effect of the DISCARD command inside a Redis transaction?

APauses the transaction without executing or canceling commands
BExecutes all queued commands and ends the transaction
CCancels all queued commands and ends the transaction
DRestarts the transaction from the beginning
Attempts:
2 left
💡 Hint

Think about whether DISCARD executes or cancels commands.

📝 Syntax
advanced
2:00remaining
Which Redis command sequence causes a syntax error?

Identify the command sequence that will cause a syntax error related to transaction commands.

A
DISCARD
MULTI
SET key1 value1
EXEC
B
MULTI
SET key1 value1
DISCARD
EXEC
C
MULTI
SET key1 value1
EXEC
D
MULTI
SET key1 value1
EXEC
DISCARD
Attempts:
2 left
💡 Hint

Consider the order and validity of DISCARD and EXEC commands.

optimization
advanced
2:00remaining
Why use DISCARD instead of EXEC in some Redis transactions?

In which scenario is using DISCARD preferable to EXEC in a Redis transaction?

AWhen you want to cancel all queued commands without executing them
BWhen you want to partially execute queued commands
CWhen you want to execute all queued commands atomically
DWhen you want to queue additional commands after execution
Attempts:
2 left
💡 Hint

Think about the difference between executing and aborting a transaction.

🔧 Debug
expert
3:00remaining
Why does this Redis transaction fail to set a key?

Given the following Redis commands:

MULTI
SET key1 value1
DISCARD
GET key1

Why does GET key1 return nil instead of "value1"?

ABecause DISCARD cancels the SET command before execution
BBecause key1 was deleted by DISCARD
CBecause GET is not allowed after DISCARD
DBecause MULTI was not called before SET
Attempts:
2 left
💡 Hint

Recall what DISCARD does to queued commands.