0
0
Redisquery~20 mins

Transaction execution model in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Transaction 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 as a transaction:

MULTI
SET key1 value1
INCR counter
EXEC

Assuming counter was not set before, what will be the result of the EXEC command?

Redis
MULTI
SET key1 value1
INCR counter
EXEC
A["OK", 0]
B["OK", "1"]
C["OK", "0"]
D["OK", 1]
Attempts:
2 left
💡 Hint

Remember that INCR initializes the key to 0 before incrementing if it does not exist.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes Redis transactions?

Which of the following statements about Redis transactions is true?

ARedis transactions guarantee atomicity and durability but not isolation.
BRedis transactions guarantee atomicity, isolation, and durability.
CRedis transactions guarantee atomicity and isolation but not durability.
DRedis transactions guarantee isolation and durability but not atomicity.
Attempts:
2 left
💡 Hint

Think about what Redis transactions do and do not guarantee.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Redis transaction block

Which option contains a syntax error that will cause the Redis transaction to fail?

MULTI
SET key1 value1
INCR
EXEC
A
MULTI
SET key1 value1
INCR
EXEC
B
MULTI
SET key1 value1
INCR counter
EXEC
C
MULTI
SET key1 value1
INCR counter
DISCARD
D
CEXE
retnuoc RCNI
1eulav 1yek TES
ITLUM
Attempts:
2 left
💡 Hint

Check the command arguments carefully.

🔧 Debug
advanced
2:00remaining
Why does this Redis transaction not execute any commands?

Given the commands:

WATCH key1
MULTI
SET key1 value1
EXEC

Assuming another client modifies key1 after WATCH but before EXEC, what will be the result of EXEC?

AEXEC returns null and no commands are executed.
BEXEC executes all commands and returns their results.
CEXEC returns an error because the watched key changed.
DEXEC retries the transaction automatically.
Attempts:
2 left
💡 Hint

Think about what happens when a watched key is modified before EXEC.

optimization
expert
3:00remaining
How to optimize Redis transactions to avoid race conditions?

You want to increment a counter only if a key exists, using a Redis transaction. Which approach best avoids race conditions?

AUse WATCH on the key, then MULTI, check existence with GET, then INCR, finally EXEC.
BUse Lua scripting to check and increment atomically without WATCH or MULTI.
CUse MULTI, then GET, then INCR, then EXEC without WATCH.
DUse MULTI, then INCR, then EXEC, ignoring key existence.
Attempts:
2 left
💡 Hint

Think about atomic operations and avoiding race conditions.