1.2.0 • Published 6 years ago

distlock v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

distlock

A distributed lock implementation using redis, supporting promise and typescript

Build Status NPM version Dependency Status Coverage Status

Pseudo-code

def lock(lockId, retry):
  value = redis.get(lockId)
  if value is null:
    redis.set(lockId, True)
  else:
    if retry < 3:
      sleep 100 seconds
      lock(lockId, retry++)
    else
      throw Error
lock(lockId='pid1', retry=0)

Example

import { DistLock } from 'distlock';
import * as redis from 'redis';

async tryToDoSomething(): Promise<void> {
  let l: DistLock;
  try {
    l = new DistLock(redis.redisClient, 'lockName');
    await l.lock();
    await this.doSomething()
  catch (e) {
    console.log(e);
  } finally {
    await l.unlock();
 }
}
1.2.0

6 years ago

1.2.0-rc.2

6 years ago

1.2.0-rc.1

6 years ago

1.2.0-dev

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago