Complete the code to start a Lua script in Redis that runs atomically.
[1] "return redis.call('SET', 'key', 'value')" 0
The EVAL command runs Lua scripts atomically in Redis.
Complete the code to return a value from a Lua script in Redis.
return redis.call([1], 'GET', 'key')
The GET command retrieves the value of a key in Redis.
Fix the error in the Lua script to ensure atomic execution.
redis.call('SET', 'counter', redis.call([1], 'INCR', 'counter'))
The INCR command increments a counter atomically in Redis.
Fill both blanks to create a Lua script that atomically checks and sets a key.
if redis.call([1], 'EXISTS', 'lock') == 0 then redis.call([2], 'SET', 'lock', '1') end
The script checks if 'lock' exists and sets it if not, all atomically.
Fill all three blanks to write a Lua script that atomically increments a counter only if it exists.
if redis.call([1], 'EXISTS', 'counter') == 1 then return redis.call([2], 'INCR', 'counter') else return redis.call([3], 'SET', 'counter', '1') end
This script checks if 'counter' exists, increments it if yes, or sets it to 1 if no, all atomically.
