zeit/redis-semaphore

Name: redis-semaphore

Owner: ZEIT

Description: Distributed mutex and semaphore based on Redis

Forked from: swarthy/redis-semaphore

Created: 2018-02-06 20:00:41.0

Updated: 2018-05-03 18:33:38.0

Pushed: 2018-03-19 18:27:16.0

Homepage: null

Size: 51

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

redis-semaphore

NPM version Build status Dependency Status Coverage Status Code Climate Known Vulnerabilities

Mutex and Semaphore implementations based on Redis ready for distributed systems

Features
Usage
Mutex
new Mutex(redisClient, key [, { lockTimeout = 10000, acquireTimeout = 10000, retryInterval = 10, refreshInterval = acquireTimeout * 0.8 }]) Example
t Mutex = require('redis-semaphore').Mutex
t redis = require('redis')

t redisClient = redis.createClient()

c function doSomething() {
nst mutex = new Mutex(redisClient, 'lockingResource')
ait mutex.acquire()
 critical code
ait mutex.release()

Semaphore
new Semaphore(redisClient, key, maxCount [, { lockTimeout = 10000, acquireTimeout = 10000, retryInterval = 10, refreshInterval = acquireTimeout * 0.8 }]) Example
t Semaphore = require('redis-semaphore').Semaphore
t redis = require('redis')

t redisClient = redis.createClient()

c function doSomething() {
nst semaphore = new Semaphore(redisClient, 'lockingResource', 5)
ait semaphore.acquire()
 maximum 5 simultaneously executions
ait semaphore.release()

Installation
install --save redis-semaphore

 add redis-semaphore
License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.