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 to start a transaction instead of MULTI.
Using WATCH which is for monitoring keys, not starting transactions.
✗ Incorrect
The MULTI command starts a Redis transaction block.
2fill in blank
mediumComplete the code to execute all commands queued in a Redis transaction.
Redis
redis.call('[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using MULTI instead of EXEC to run commands.
Using DISCARD which cancels the transaction.
✗ Incorrect
The EXEC command executes all commands queued in the current transaction.
3fill in blank
hardFix the error in the Lua script to atomically increment a key and return its new value.
Redis
local newVal = redis.call('INCR', '[1]') return newVal
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using command names like MULTI or EXEC as key names.
Leaving the key name blank or incorrect.
✗ Incorrect
The key name to increment must be provided as a string, here 'counter'.
4fill in blank
hardFill both blanks to watch a key and start a transaction in Redis.
Redis
redis.call('[1]', 'mykey') 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 instead of MULTI.
✗ Incorrect
WATCH monitors the key for changes, and MULTI starts the transaction.
5fill in blank
hardFill all three blanks to write a Lua script that increments a key only if it has not changed since watching it.
Redis
redis.call('[1]', KEYS[1]) redis.call('[2]') redis.call('INCR', KEYS[1]) local val = redis.call('[3]') return val[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DISCARD instead of EXEC.
Not watching the key before starting the transaction.
✗ Incorrect
The script watches the key, starts a transaction, increments the key, then executes the transaction.