Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-sp

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-sp

Redis synchronization primitives based on redlock algorithm

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

redis-sp

Redis SP (SP stands for Synchronization Primitives) is a set of synchronization primitives based on the Redlock algorithm.

Installation

npm install redis-sp

Usage

Mutex

Mutex implementation based on the Redlock algorithm

import RedisClient from 'ioredis';
import { RedisMutex } from 'redis-sp';

async function main() {
  const client = new RedisClient();

  const mutex = new RedisMutex([client], getResourceIdSomehow());
  await mutex.lock();

  try {
    // critical section of your code
    await maybeFails();
  } finally {
    await mutex.unlock();
  }
}

Counting Semaphore

Implementation of a counting semaphore according to the Fair semaphores | Redis with a slight difference (no race conditions due to the atomicity of Redis Lua scripts).

import RedisClient from 'ioredis';
import { RedisCountingSemaphore } from 'redis-sp';

async function main() {
  const client = new RedisClient();

  const semaphore = new RedisCountingSemaphore(
    [client],
    getSharedResourceIdSomehow(),
    getMaxSharedResourceOwnersSomehow(),
  );
  await semaphore.acquire();

  try {
    // critical section of your code
    await maybeFails();
  } finally {
    await semaphore.release();
  }
}

Stay tuned for RW lock in the next major release!

Keywords

FAQs

Package last updated on 29 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc