On the redis documentation, I found a primitive lock can be implemented via SETNX:
http://redis.io/commands/setnx
C4 sends SETNX lo
Use SET
instead of SETNX
. SET
accepts arguments for expiration time in seconds and milliseconds instead of UNIX timestamp value.
The old SETNX based pattern is documented only for historical reasons.
From SETNX
description:
NOTE: Starting with Redis 2.6.12 it is possible to create a much simpler locking primitive using the SET command to acquire the lock, and a simple Lua script to release the lock. The pattern is documented in the SET command page.