0
0
Redisquery~20 mins

EXEC to execute in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis EXEC Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Redis transaction?
Consider the following Redis commands executed in a transaction using MULTI and EXEC:

MULTI
SET key1 value1
INCR counter
GET key1
EXEC

Assuming counter was initially 5, what will EXEC return?
Redis
MULTI
SET key1 value1
INCR counter
GET key1
EXEC
A["OK", 6, "value1"]
B["OK", "6", "value1"]
C["OK", 5, "value1"]
D["OK", 6, null]
Attempts:
2 left
💡 Hint
Remember that INCR returns the new incremented value as an integer.
🧠 Conceptual
intermediate
1:30remaining
What does EXEC do in a Redis transaction?
In Redis, after starting a transaction with MULTI and queuing commands, what is the role of the EXEC command?
AIt executes all queued commands atomically and returns their results.
BIt cancels the transaction and discards all queued commands.
CIt queues another command to be executed later.
DIt resets the database to its initial state.
Attempts:
2 left
💡 Hint
Think about what happens after queuing commands with MULTI.
📝 Syntax
advanced
2:00remaining
Which option shows correct syntax to start and execute a Redis transaction?
Select the option that correctly starts a transaction, queues two commands, and executes them.
A
SET key1 val1
MULTI
INCR counter
EXEC
B
MULTI
SET key1 val1
EXEC
INCR counter
C
MULTI
SET key1 val1
INCR counter
EXEC
D
MULTI
EXEC
SET key1 val1
INCR counter
Attempts:
2 left
💡 Hint
Commands must be queued between MULTI and EXEC.
🔧 Debug
advanced
2:30remaining
Why does EXEC return null in this Redis transaction?
Given the commands:

MULTI
SET key1 value1
WATCH key1
INCR counter
EXEC

Why might EXEC return null?
ABecause INCR counter is invalid syntax inside MULTI.
BBecause SET key1 value1 failed due to wrong arguments.
CBecause EXEC was called before queuing any commands.
DBecause WATCH was called after MULTI, causing the transaction to fail.
Attempts:
2 left
💡 Hint
Remember the order of WATCH and MULTI matters.
optimization
expert
3:00remaining
How to optimize multiple Redis commands for atomic execution?
You want to increment a counter and set a key's value atomically in Redis. Which approach is best for performance and atomicity?
AUse MULTI, queue INCR and SET commands, then EXEC.
BUse Lua scripting to perform both commands atomically.
CSend INCR and SET commands separately without MULTI/EXEC.
DUse WATCH on the key, then send INCR and SET commands.
Attempts:
2 left
💡 Hint
Lua scripts run atomically and can combine commands efficiently.