taoensso.carmine.locks

Alpha - subject to change.
Distributed lock implementation for Carmine based on work by Ronen Narkis
and Josiah Carlson. Redis 2.6+.

Redis keys:
  * carmine:lock:<lock-name> -> ttl str, lock owner's UUID.

Ref. http://goo.gl/5UalQ for implementation details.

acquire-lock

(acquire-lock conn-opts lock-name timeout-ms wait-ms)
Attempts to acquire a distributed lock, returning an owner UUID iff successful.

have-lock?

(have-lock? conn-opts lock-name owner-uuid)

release-lock

(release-lock conn-opts lock-name owner-uuid)
Attempts to release a distributed lock, returning true iff successful.

with-lock

macro

(with-lock conn-opts lock-name timeout-ms wait-ms & body)
Attempts to acquire a distributed lock, executing body and then releasing
lock when successful. Returns {:result <body's result>} on successful release,
or nil if the lock could not be acquired. If the lock is successfully acquired
but expires before being released, throws an exception.