Challenge - 5 Problems
Redis EXEC Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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
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
Attempts:
2 left
💡 Hint
Remember that INCR returns the new incremented value as an integer.
✗ Incorrect
The SET command returns OK, INCR increments counter from 5 to 6 and returns 6, GET returns the string value1. EXEC returns an array of these results.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about what happens after queuing commands with MULTI.
✗ Incorrect
EXEC runs all commands queued after MULTI in a single atomic operation and returns their results as an array.
📝 Syntax
advanced2: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.
Attempts:
2 left
💡 Hint
Commands must be queued between MULTI and EXEC.
✗ Incorrect
Only option C queues commands between MULTI and EXEC properly. Other options execute or queue commands out of order.
🔧 Debug
advanced2: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?
MULTI
SET key1 value1
WATCH key1
INCR counter
EXEC
Why might EXEC return null?
Attempts:
2 left
💡 Hint
Remember the order of WATCH and MULTI matters.
✗ Incorrect
WATCH must be called before MULTI. Calling WATCH after MULTI causes the transaction to fail and EXEC returns null.
❓ optimization
expert3: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?
Attempts:
2 left
💡 Hint
Lua scripts run atomically and can combine commands efficiently.
✗ Incorrect
Lua scripting allows combining multiple commands into one atomic operation with better performance than MULTI/EXEC.