{"repo":"AmrSaber/simple-redis-mutex","free":true,"listed":false,"github":"https://github.com/AmrSaber/simple-redis-mutex","clone":"git clone https://github.com/AmrSaber/simple-redis-mutex.git","description":"Simple and powerful distributed locking using Redis","language":"TypeScript","stars":34,"topics":["lock","mutex","redis"],"license":null,"category":"databases-storage","readme_excerpt":"Simple Redis Mutex Implements distributed mutex lock using redis as described in redis docs. The term simple is opposed to the more complex Redlock , that was also proposed by Redis in their docs for use in case of distributed redis instances. Locks have timeout (expire time) and fail after options. Also, Redis Pub/Sub is used so that released lock can be immediately acquired by another waiting process instead of depending on polling. Manual polling is still supported though in case lock expires. Install Install the package using npm . Or with bun Examples Usage There are 2 methods to acquire a lock: - lock : which attempts to acquire the lock in a blocking way, if lock is already acquired, it blocks until lock is available. - tryLock : which attempts to acquire the lock, if lock is already acquired it returns immediately. API lock As per the code: tryLock As per the code: ReleaseFunc Notes Redis Client This package has Peer Dependency on redis, the is the redis client that must be passed to lock functions. Same client must always be provided within same process, this is because pub/sub depends on the provided client and its lifecycle. Lock options The same lock can be acquired with different options each time, and it can be acquired using lock and tryLock in different places or under different circumstances (actually lock internally uses tryLock to acquire the lock). You can mix and match as you see fit, but I recommend always using the same options in same places for more c","default_branch":null,"files":null,"tree":[],"storefront":"/r/AmrSaber","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/AmrSaber/simple-redis-mutex/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."}