Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a Redis transaction.
Redis
redis.call('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXEC instead of MULTI to start the transaction.
Using WATCH which is for monitoring keys, not starting transactions.
✗ Incorrect
The MULTI command starts a Redis transaction block.
2fill in blank
mediumComplete the Lua script to atomically increment a key by 1.
Redis
return redis.call('[1]', KEYS[1]) + 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET and adding 1 in Lua which is not atomic.
Using SET which overwrites the value.
✗ Incorrect
The script uses INCR to atomically increment the key by 1.
3fill in blank
hardFix the error in the Lua script to ensure atomic increment.
Redis
local val = redis.call('[1]', KEYS[1]) if not val then redis.call('[2]', KEYS[1], 1) return 1 end return redis.call('[3]', KEYS[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEL which deletes the key instead of setting or incrementing.
Using GET instead of INCR for incrementing.
✗ Incorrect
The script first GETs the value. If it doesn't exist, it SETs it to 1. Otherwise, it INCRs the value.
4fill in blank
hardFill both blanks to watch a key and start a transaction.
Redis
redis.call('[1]', KEYS[1]) redis.call('[2]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXEC before MULTI.
Using DISCARD which cancels the transaction.
✗ Incorrect
You WATCH the key to monitor changes, then start the transaction with MULTI.
5fill in blank
hardFill all three blanks to execute a transaction with error handling.
Redis
redis.call('[1]') local success = redis.call('[2]') if not success then redis.call('[3]') end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WATCH instead of DISCARD to cancel.
Calling EXEC before MULTI.
✗ Incorrect
You start the transaction with MULTI, execute it with EXEC, and if it fails, cancel with DISCARD.