🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

redis-semaphore

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-semaphore - npm Package Compare versions

Comparing version

to
1.0.4

.snyk

6

lib/fair-semaphore/acquire.js

@@ -1,2 +0,2 @@

const debug = require('debug')('redis-semaphore:semaphore:acquire')
const debug = require('debug')('redis-semaphore:fair-semaphore:acquire')
const delay = require('../utils/delay')

@@ -22,3 +22,3 @@ const createEval = require('../utils/createEval')

async function acquireSemaphore(
async function acquireFairSemaphore(
client,

@@ -56,2 +56,2 @@ key,

module.exports = acquireSemaphore
module.exports = acquireFairSemaphore

@@ -1,2 +0,2 @@

const debug = require('debug')('redis-semaphore:semaphore:refresh')
const debug = require('debug')('redis-semaphore:fair-semaphore:refresh')
const createEval = require('../utils/createEval')

@@ -17,10 +17,10 @@

async function refreshSemaphore(client, key, identifier) {
async function refreshFairSemaphore(client, key, identifier) {
const now = Date.now()
debug(key, identifier, now)
const result = await refreshLua(client, [
key,
`${key}:owner`,
identifier,
now
key,
`${key}:owner`,
identifier,
now
])

@@ -31,2 +31,2 @@ debug('result', typeof result, result)

module.exports = refreshSemaphore
module.exports = refreshFairSemaphore

@@ -1,2 +0,2 @@

const debug = require('debug')('redis-semaphore:semaphore:release')
const debug = require('debug')('redis-semaphore:fair-semaphore:release')
const createEval = require('../utils/createEval')

@@ -13,9 +13,5 @@

async function releaseSemaphore(client, key, identifier) {
async function releaseFairSemaphore(client, key, identifier) {
debug(key, identifier)
const result = await releaseLua(client, [
key,
`${key}:owner`,
identifier
])
const result = await releaseLua(client, [key, `${key}:owner`, identifier])
debug('result', typeof result, result)

@@ -25,2 +21,2 @@ return result === 1

module.exports = releaseSemaphore
module.exports = releaseFairSemaphore
const RedisMutex = require('./RedisMutex')
const debug = require('debug')('redis-semaphore:fair-semaphore:instance')
const LostLockError = require('./errors/LostLockError')
const semaphore = require('./fair-semaphore')
const fairSemaphore = require('./fair-semaphore')

@@ -34,5 +34,7 @@ class RedisFairSemaphore extends RedisMutex {

debug(
`refresh semaphore (key: ${this._key}, identifier: ${this._identifier})`
`refresh fair-semaphore (key: ${this._key}, identifier: ${
this._identifier
})`
)
const refreshed = await semaphore.refresh(
const refreshed = await fairSemaphore.refresh(
this._client,

@@ -44,3 +46,3 @@ this._key,

this._stopRefresh()
throw new LostLockError(`Lost semaphore for key ${this._key}`)
throw new LostLockError(`Lost fairSemaphore for key ${this._key}`)
}

@@ -50,4 +52,4 @@ }

async acquire() {
debug(`acquire semaphore (key: ${this._key})`)
this._identifier = await semaphore.acquire(
debug(`acquire fair-semaphore (key: ${this._key})`)
this._identifier = await fairSemaphore.acquire(
this._client,

@@ -66,6 +68,8 @@ this._key,

debug(
`release semaphore (key: ${this._key}, identifier: ${this._identifier})`
`release fair-semaphore (key: ${this._key}, identifier: ${
this._identifier
})`
)
this._stopRefresh()
const released = await semaphore.release(
const released = await fairSemaphore.release(
this._client,

@@ -72,0 +76,0 @@ this._key,

@@ -34,5 +34,3 @@ const RedisMutex = require('./RedisMutex')

debug(
`refresh fairsemaphore (key: ${this._key}, identifier: ${
this._identifier
})`
`refresh semaphore (key: ${this._key}, identifier: ${this._identifier})`
)

@@ -51,3 +49,3 @@ const refreshed = await semaphore.refresh(

async acquire() {
debug(`acquire fairsemaphore (key: ${this._key})`)
debug(`acquire semaphore (key: ${this._key})`)
this._identifier = await semaphore.acquire(

@@ -67,5 +65,3 @@ this._client,

debug(
`release fairsemaphore (key: ${this._key}, identifier: ${
this._identifier
})`
`release semaphore (key: ${this._key}, identifier: ${this._identifier})`
)

@@ -72,0 +68,0 @@ this._stopRefresh()

{
"name": "redis-semaphore",
"version": "1.0.3",
"version": "1.0.4",
"description": "Distributed mutex and semaphore based on Redis",

@@ -37,3 +37,3 @@ "main": "index.js",

"sinon-chai": "3.3.0",
"snyk": "1.110.2"
"snyk": "1.114.0"
},

@@ -40,0 +40,0 @@ "engines": {

Sorry, the diff of this file is not supported yet