Complete the code to increment the request count for a user key.
redis.call('INCR', [1])
The INCR command increments the count for the given user key.
Complete the code to set the expiration time for the user key.
redis.call('EXPIRE', [1], 60)
The EXPIRE command sets the expiration time on the user key to 60 seconds.
Fix the error in the code to check if the key exists before setting expiration.
if redis.call('EXISTS', [1]) == 1 then redis.call('EXPIRE', [1], 60) end
We check if the user_key exists before setting expiration on it.
Fill both blanks to create a Lua script that increments the user key and sets expiration if it's a new key.
local current = redis.call('INCR', [1]) if current == 1 then redis.call('EXPIRE', [2], 60) end return current
The script increments the user_key and sets expiration on the same key if it's the first increment.
Fill all three blanks to complete the Lua script that increments the user key, sets expiration, and checks if the limit is exceeded.
local current = redis.call('INCR', [1]) if current == 1 then redis.call('EXPIRE', [2], 60) end if current > [3] then return 0 else return 1 end
The script increments the user_key, sets expiration on it, and compares the count to the limit to decide if the request is allowed.