@sesamecare-oss/redlock
Advanced tools
Comparing version 1.0.1 to 1.1.0
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { Redis as IORedisClient, Cluster as IORedisCluster } from 'ioredis'; | ||
import type { Redis as IORedisClient, Cluster as IORedisCluster } from 'ioredis'; | ||
type Client = IORedisClient | IORedisCluster; | ||
@@ -5,0 +5,0 @@ export type ClientExecutionResult = { |
@@ -6,5 +6,2 @@ "use strict"; | ||
const events_1 = require("events"); | ||
// AbortController became available as a global in node version 16. Once version | ||
// 14 reaches its end-of-life, this can be removed. | ||
const node_abort_controller_1 = require("node-abort-controller"); | ||
const scripts_1 = require("./scripts"); | ||
@@ -196,4 +193,3 @@ // Define default settings. | ||
const drift = Math.round((settings?.driftFactor ?? this.settings.driftFactor) * duration) + 2; | ||
const replacement = new Lock(this, existing.resources, existing.value, attempts, start + duration - drift); | ||
return replacement; | ||
return new Lock(this, existing.resources, existing.value, attempts, start + duration - drift); | ||
} | ||
@@ -341,5 +337,3 @@ /** | ||
// of an abort, the error object will be made available at `signal.error`. | ||
const controller = typeof AbortController === 'undefined' | ||
? new node_abort_controller_1.AbortController() | ||
: new AbortController(); | ||
const controller = new AbortController(); | ||
const signal = controller.signal; | ||
@@ -346,0 +340,0 @@ function queue() { |
{ | ||
"name": "@sesamecare-oss/redlock", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A modern node.js redlock implementation for distributed redis locks", | ||
@@ -9,3 +9,3 @@ "main": "build/index.js", | ||
"license": "UNLICENSED", | ||
"packageManager": "yarn@4.0.1", | ||
"packageManager": "yarn@3.6.0", | ||
"scripts": { | ||
@@ -22,2 +22,5 @@ "build": "tsc -p tsconfig.build.json", | ||
], | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"repository": { | ||
@@ -54,5 +57,5 @@ "type": "git", | ||
"@semantic-release/github": "^9.2.1", | ||
"@types/node": "^20.8.9", | ||
"@typescript-eslint/eslint-plugin": "^6.9.0", | ||
"@typescript-eslint/parser": "^6.9.0", | ||
"@types/node": "^16.18.60", | ||
"@typescript-eslint/eslint-plugin": "^6.9.1", | ||
"@typescript-eslint/parser": "^6.9.1", | ||
"coconfig": "^1.0.0", | ||
@@ -63,9 +66,9 @@ "eslint": "^8.52.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"ioredis": "^5.3.2", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"dependencies": { | ||
"ioredis": "^5.3.2", | ||
"node-abort-controller": "^3.1.1" | ||
"peerDependencies": { | ||
"ioredis": ">=5" | ||
} | ||
} |
@@ -7,3 +7,3 @@ [![Node build, test and publish](https://github.com/sesamecare/redlock/actions/workflows/nodejs.yml/badge.svg)](https://github.com/sesamecare/redlock/actions/workflows/nodejs.yml) | ||
This is a node.js implementation of the [redlock](http://redis.io/topics/distlock) algorithm for distributed redis locks. It provides strong guarantees in both single-redis and multi-redis environments, and provides fault tolerance through use of multiple independent redis instances or clusters. | ||
This is a Node.js implementation of the [redlock](http://redis.io/topics/distlock) algorithm for distributed redis locks. It provides strong guarantees in both single-redis and multi-redis environments, and provides fault tolerance through use of multiple independent redis instances or clusters. | ||
@@ -22,5 +22,11 @@ > Note! | ||
```bash | ||
npm install --save redlock | ||
npm install --save @sesamecare-oss/redlock | ||
``` | ||
For Node.js v14 you should also install `node-abort-controller` | ||
```bash | ||
npm install --save node-abort-controller | ||
``` | ||
## Configuration | ||
@@ -34,3 +40,3 @@ | ||
import Client from "ioredis"; | ||
import Redlock from "redlock"; | ||
import Redlock from "@sesamecare-oss/redlock"; | ||
@@ -117,3 +123,3 @@ const redisA = new Client({ host: "a.redis.example.com" }); | ||
```ts | ||
const { default: Redlock } = require("redlock"); | ||
const { default: Redlock } = require("@sesamecare-oss/redlock"); | ||
``` | ||
@@ -180,2 +186,2 @@ | ||
Note that with `retryCount=-1` there will be unlimited retries until the lock is aquired. | ||
Note that with `retryCount=-1` there will be unlimited retries until the lock is aquired. |
import { randomBytes, createHash } from 'crypto'; | ||
import { EventEmitter } from 'events'; | ||
// AbortController became available as a global in node version 16. Once version | ||
// 14 reaches its end-of-life, this can be removed. | ||
import { AbortController as PolyfillAbortController } from 'node-abort-controller'; | ||
import { Redis as IORedisClient, Cluster as IORedisCluster } from 'ioredis'; | ||
import type { Redis as IORedisClient, Cluster as IORedisCluster } from 'ioredis'; | ||
@@ -285,11 +282,9 @@ import { ensureCommands } from './scripts'; | ||
const replacement = new Lock( | ||
this, | ||
existing.resources, | ||
existing.value, | ||
attempts, | ||
start + duration - drift, | ||
return new Lock( | ||
this, | ||
existing.resources, | ||
existing.value, | ||
attempts, | ||
start + duration - drift, | ||
); | ||
return replacement; | ||
} | ||
@@ -550,6 +545,3 @@ | ||
// of an abort, the error object will be made available at `signal.error`. | ||
const controller = | ||
typeof AbortController === 'undefined' | ||
? new PolyfillAbortController() | ||
: new AbortController(); | ||
const controller= new AbortController(); | ||
@@ -556,0 +548,0 @@ const signal = controller.signal as RedlockAbortSignal; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1
183
113768
14
1271
- Removedioredis@^5.3.2
- Removednode-abort-controller@^3.1.1
- Removednode-abort-controller@3.1.1(transitive)