{"repo":"bsm/redislock","free":true,"listed":false,"github":"https://github.com/bsm/redislock","clone":"git clone https://github.com/bsm/redislock.git","description":"Simplified distributed locking implementation using Redis","language":"Go","stars":1766,"topics":["golang","redis","lock","distributed","distlock","distributed-lock"],"license":null,"category":"databases-storage","readme_excerpt":"redislock Simplified distributed locking implementation using Redis. For more information, please see examples. Documentation Full documentation is available on GoDoc Examples Fencing tokens Set Options.FenceKey to mint a fencing token with the lock: a strictly increasing value, incremented atomically on each new acquisition and returned by Lock.FenceToken . Stamp every write to the protected resource with the token and have the resource reject any write carrying an older token. A lock holder that pauses (GC, scheduling) long enough to lose the lock without noticing is then fenced out — its writes carry a stale token and are refused. This is the mitigation described in Martin Kleppmann's How to do distributed locking. A few notes: - Enforcement is the resource's job: redislock mints and returns the token, but the check ( reject if incoming < highest applied ) must happen atomically at the resource, which is the only place the comparison and the write can be made one operation. - You supply FenceKey , so you control its placement. On Redis Cluster it must hash to the same slot as the lock key(s) — share a {hashtag} , e.g. lock {job}:lock with fence {job}:fence — or the script fails with CROSSSLOT . - The counter persists across release so it keeps increasing; it is never reset by Release . - The token is only as monotonic as the underlying Redis. On a single instance it is strict; on a Sentinel/Cluster failover that loses the INCR , it can regress. For strict cross-failover mo","default_branch":null,"files":null,"tree":[],"storefront":"/r/bsm","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/bsm/redislock/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}