On the redis documentation, I found a primitive lock can be implemented via SETNX:
http://redis.io/commands/setnx
C4 sends SETNX lo
I gem'ed out the SET EX NX solution that misterion mentioned to a cool gem - simple_redis_lock
SET EX NX
The code is simple and looks like this:
def lock(key, timeout) if @redis.set(key, Time.now, nx: true, px: timeout) begin yield ensure release key end end end