I've read the post about distributed locks with Redis at http://redis.io/topics/distlock. There's a lua script to describe how to do "unlock".
if redis.call("get",KEYS[1]) == ARGV[1] then
return redis.call("del",KEYS[1])
else
return 0
end
I think there is a race condition with this model:
SET key randomstring1 NX PX 3000
if redis.call("get",KEYS[1]) == ARGV[1] then
SET key randomstring2 NX PX 3000
No, here is no race condition. LUA scripts executes in atomic way. This means that no any commands from other connections (clients) would be processed before LUA script finish they work (even Redis internal cron which actually process expired items).