You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

do-with-redis-lock

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

do-with-redis-lock

Promisified behavior locking with Redis

3.1.0
latest
Source
npm
Version published
Weekly downloads
181
28.37%
Maintainers
0
Weekly downloads
 
Created
Source

do-with-redis-lock

usage

redisConn = {
  port: 9000,
  host: "...",
  auth: "...",
  db: 1 #optional
}
doWithLock = require("do-with-redis-lock")(redisConn)

action = ->
  request.getAsync(...) # something that returns a Promise

doWithLock(action, key).then (result) ->
  # continue...

If a concurrency problem appears, the Promise is rejected with:

{
  statusCode: 503,
  body: {
    code: "concurrency_conflict",
    message: "Somebody is doing this at the same time at you"
  }
}

migration

1.x users

  • In 2.x, the Promise's rejection reason isn't "concurrency_conflict" anymore. See above.

2.x users

  • In 3.x, the connection credentials are no longer environment variables. They are passed by parameters instead. See above.

FAQs

Package last updated on 30 Jan 2025

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