I encountered a problem wherein asynchronous saving in one of our models with uniqueness validation declared in Application level is not blocked by the said validation. Adding the validation in the Database level is not an option for me due to a toggleable option on my app to enable/disable the uniqueness validation.
While searching I saw that Redis lock is what's best for this kind of case, but since I am new to the term of "Redis lock" I need a bit of advice on which plugin/implementation is better to achieve my needed behaviour.
I saw one of the responses that could be similar to my problem here Ruby - Redis based mutex with expiration implementation, and it says that a plugin is not needed since it could be achieved with Redis alone like this
def lock(key, timeout)
if @redis.set(key, Time.now, nx: true, px: timeout)
begin
yield
ensure
release key
end
end
end
And I also saw that some recommend this redlock plugin found here https://github.com/leandromoreira/redlock-rb but could be an overkill.
Thanks in advance