murlock 4.4.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -166,6 +166,8 @@ async anotherFunction(user: User): Promise<void> {
166
166
 
167
167
  When using `@MurLock` with other decorators (such as `@Transactional` from typeorm-transactional), you may encounter issues with parameter name extraction if the other decorator wraps the method before `@MurLock` is applied.
168
168
 
169
+ > **Note on minification / transpilation:** MurLock derives parameter names by parsing the method signature at runtime. Aggressive minifiers/bundlers (terser, esbuild, swc) may rename or strip parameter names, in which case **name-based** key params (e.g. `'userId'`, `'user.id'`) cannot be resolved and the decorator throws `Parameter ... not found`. If you minify your server build, either use **numeric index** key params (e.g. `'0'`, `'0.id'`) — which are always stable — or declare names explicitly with `@SetParamNames` (below).
170
+
169
171
  ### Problem
170
172
 
171
173
  TypeScript decorators execute in bottom-up order. If another decorator wraps the method before `@MurLock`, the parameter names cannot be extracted from the wrapped function:
@@ -295,13 +297,45 @@ When blocking mode is enabled:
295
297
  - Each retry will wait for the specified `wait` time
296
298
  - Redis errors will be logged but won't stop the retry process
297
299
 
300
+ ## Auto-Extend (Watchdog)
301
+
302
+ A lock is created with a fixed TTL (`releaseTime`). If your operation runs **longer** than `releaseTime`, the lock would normally expire while the work is still in progress — at which point another instance could acquire the same lock and break mutual exclusion (and the original holder would then fail to release it).
303
+
304
+ Enable `autoExtend` to start a watchdog that periodically extends the lock's TTL (only while *this* instance still owns it) for as long as the wrapped operation runs:
305
+
306
+ ```typescript
307
+ @Module({
308
+ imports: [
309
+ MurLockModule.forRoot({
310
+ redisOptions: { url: 'redis://localhost:6379' },
311
+ wait: 1000,
312
+ maxAttempts: 3,
313
+ logLevel: 'log',
314
+ autoExtend: true, // keep the lock alive while the operation runs
315
+ extendInterval: 1000, // optional; defaults to releaseTime / 3
316
+ }),
317
+ ],
318
+ })
319
+ export class AppModule {}
320
+ ```
321
+
322
+ Behavior:
323
+
324
+ - The TTL is refreshed every `extendInterval` ms (default: `Math.floor(releaseTime / 3)`).
325
+ - Extension is ownership-checked: if the lock is lost (e.g. it expired before the first refresh, or was taken over), the watchdog stops and logs a warning.
326
+ - The watchdog timer is `unref`'d, so it never keeps your process alive on its own.
327
+ - Defaults to `false`, so existing behavior is unchanged.
328
+
329
+ > **Tip:** This is especially valuable together with `blocking: true`. Blocking mode makes callers queue until the lock frees, but if the current holder runs longer than `releaseTime` the lock still expires underneath it. `autoExtend` keeps the holder's lock valid for the full duration of its work, so "wait for the previous execution to finish" actually holds even for long-running operations.
330
+
298
331
  ## Redis Connection Handling
299
332
 
300
333
  MurLock includes robust Redis connection handling:
301
334
 
302
335
  - **Automatic Reconnection**: Implements a reconnection strategy with exponential backoff
303
336
  - **Connection Events**: Logs connection status changes (ready, reconnecting, end)
304
- - **Fail-Fast Option**: Can be configured to exit the application on Redis connection failures
337
+ - **Fail-Fast Option**: Can be configured to throw during startup if the **initial** Redis connection fails
338
+ - **Custom Error Handling**: Provide an `onRedisError` callback to react to runtime Redis errors (alerting, custom fail-fast, etc.)
305
339
 
306
340
  ```typescript
307
341
  @Module({
@@ -317,13 +351,19 @@ MurLock includes robust Redis connection handling:
317
351
  },
318
352
  },
319
353
  },
320
- failFastOnRedisError: true, // Exit application on Redis connection failure
354
+ failFastOnRedisError: true, // Throw on startup if the initial connection fails
355
+ onRedisError: (err) => {
356
+ // Optional: custom handling for runtime Redis errors
357
+ console.error('Redis error:', err.message);
358
+ },
321
359
  }),
322
360
  ],
323
361
  })
324
362
  export class AppModule {}
325
363
  ```
326
364
 
365
+ > **Note (v5 behavior change):** Runtime Redis `error` events no longer terminate the process. Previously, with `failFastOnRedisError: true`, *any* runtime Redis error (including transient network blips) would call `process.exit(1)`, taking the whole application down mid-request. Now `failFastOnRedisError` applies only to the initial connection attempt; runtime errors are logged, recovery is handled by the reconnect strategy, and you can opt into custom handling via `onRedisError`.
366
+
327
367
  ## Using Custom Lock Key
328
368
 
329
369
  By default, murlock use class and method name prefix for example Userservice:createUser:{userId}. By setting lockKeyPrefix as 'custom' you can define by yourself manually.
@@ -476,8 +516,14 @@ Here are the customizable options for `MurLockModule`, allowing you to tailor it
476
516
  - **lockKeyPrefix (optional)**: Specifies how lock keys are prefixed, allowing for greater flexibility:
477
517
  - **Default**: Uses class and method names as prefixes, e.g., `Userservice:createUser:{userId}`.
478
518
  - **Custom**: Set this to 'custom' to define lock keys manually in your service methods, allowing for specific lock key constructions beyond the standard naming.
479
- - **failFastOnRedisError (optional)**: When set to `true`, the application will exit with code 1 if a Redis connection error occurs. Defaults to `false`.
519
+ - **failFastOnRedisError (optional)**: When set to `true`, the application will throw during startup (`onModuleInit`) if the **initial** Redis connection fails. Defaults to `false`. **Note (behavior change):** this option no longer terminates the process on *runtime* Redis errors (e.g. transient network blips). Runtime errors are logged and recovery is handled by the reconnect strategy. Use `onRedisError` for custom runtime handling.
480
520
  - **blocking (optional)**: When set to `true`, the lock acquisition will retry indefinitely until successful. Defaults to `false`.
521
+ - **autoExtend (optional)**: When set to `true`, MurLock keeps the lock alive while the wrapped operation is still running by periodically extending its TTL (a "watchdog"). This prevents the lock from expiring mid-execution when an operation runs longer than `releaseTime`, which would otherwise let another instance acquire the same lock and break mutual exclusion. Defaults to `false`.
522
+ - **extendInterval (optional)**: Interval in milliseconds between watchdog TTL extensions. Only used when `autoExtend` is `true`. Defaults to one third of the lock's `releaseTime` (`Math.floor(releaseTime / 3)`), guaranteeing at least two refresh attempts before the TTL would expire.
523
+ - **onRedisError (optional)**: Callback `(error: Error) => void` invoked when the Redis client emits a runtime `error` event. Use it to plug in custom alerting or fail-fast behavior.
524
+ - **reentrant (optional)**: When set to `true`, locks become reentrant within the same async context: a method that locks a key and (directly or transitively) calls another method locking the **same** key reuses the existing lock instead of deadlocking. The underlying Redis lock is acquired once (outermost entry) and released when the outermost call completes. Defaults to `false`.
525
+ - **encodeKeyParts (optional)**: When set to `true`, each lock-key part derived from method arguments is URL-encoded so values containing the `:` separator cannot collide (e.g. `a:b` + `c` vs `a` + `b:c`). Changes the generated key format, so it is opt-in to avoid breaking existing keys across a rolling deploy. Defaults to `false`.
526
+ - **jitter (optional)**: When set to `true`, retry back-off delays use equal jitter (`delay/2 + random*delay/2`) to avoid a thundering herd when many workers wait on the same lock. Applies to both attempt-based and blocking modes. Defaults to `false`.
481
527
 
482
528
  ### MurLockService
483
529
 
@@ -1,21 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
- export declare class AsyncStorageManager<T> implements Map<string, T> {
3
+ export declare class AsyncStorageManager<T> {
4
4
  private readonly asyncLocalStorage;
5
- constructor(asyncLocalStorage?: AsyncLocalStorage<Map<string, T>>);
6
- private getStore;
7
- register(): void;
8
- runWithNewContext<R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs): R;
9
- set(key: string, value: T): this;
10
- get(key: string): T | undefined;
11
- clear(): void;
12
- delete(key: string): boolean;
13
- forEach(callbackfn: (value: T, key: string, map: Map<string, T>) => void, thisArg?: any): void;
14
- has(key: string): boolean;
15
- get size(): number;
16
- entries(): IterableIterator<[string, T]>;
17
- keys(): IterableIterator<string>;
18
- values(): IterableIterator<T>;
19
- [Symbol.iterator](): IterableIterator<[string, T]>;
20
- [Symbol.toStringTag]: string;
5
+ constructor(asyncLocalStorage?: AsyncLocalStorage<T>);
6
+ run<R>(store: T, fn: () => R): R;
7
+ getStore(): T | undefined;
21
8
  }
@@ -8,67 +8,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
- var _a;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.AsyncStorageManager = void 0;
14
13
  const common_1 = require("@nestjs/common");
15
14
  const async_hooks_1 = require("async_hooks");
16
- const exceptions_1 = require("../exceptions");
17
15
  let AsyncStorageManager = class AsyncStorageManager {
18
16
  constructor(asyncLocalStorage = new async_hooks_1.AsyncLocalStorage()) {
19
17
  this.asyncLocalStorage = asyncLocalStorage;
20
- this[_a] = '[object AsyncContext]';
21
18
  }
22
- getStore() {
23
- const store = this.asyncLocalStorage.getStore();
24
- if (!store) {
25
- throw new exceptions_1.AsyncStorageManagerException('No active store found');
26
- }
27
- return store;
28
- }
29
- register() {
30
- this.asyncLocalStorage.enterWith(new Map());
31
- }
32
- runWithNewContext(fn, ...args) {
33
- return this.asyncLocalStorage.run(new Map(), fn, ...args);
34
- }
35
- set(key, value) {
36
- this.getStore().set(key, value);
37
- return this;
38
- }
39
- get(key) {
40
- return this.getStore().get(key);
41
- }
42
- clear() {
43
- return this.getStore().clear();
44
- }
45
- delete(key) {
46
- return this.getStore().delete(key);
19
+ run(store, fn) {
20
+ return this.asyncLocalStorage.run(store, fn);
47
21
  }
48
- forEach(callbackfn, thisArg) {
49
- return this.getStore().forEach(callbackfn, thisArg);
50
- }
51
- has(key) {
52
- return this.getStore().has(key);
53
- }
54
- get size() {
55
- return this.getStore().size;
56
- }
57
- entries() {
58
- return this.getStore().entries();
59
- }
60
- keys() {
61
- return this.getStore().keys();
62
- }
63
- values() {
64
- return this.getStore().values();
65
- }
66
- [Symbol.iterator]() {
67
- return this.getStore()[Symbol.iterator]();
22
+ getStore() {
23
+ return this.asyncLocalStorage.getStore();
68
24
  }
69
25
  };
70
26
  exports.AsyncStorageManager = AsyncStorageManager;
71
- _a = Symbol.toStringTag;
72
27
  exports.AsyncStorageManager = AsyncStorageManager = __decorate([
73
28
  (0, common_1.Injectable)(),
74
29
  __metadata("design:paramtypes", [Object])
@@ -1 +1 @@
1
- {"version":3,"file":"als-manager.js","sourceRoot":"","sources":["../../lib/als/als-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAgD;AAChD,8CAA6D;AAGtD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAA6B,oBAAoB,IAA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agerModule = __decorate([
20
20
  providers: [
21
21
  {
22
22
  provide: als_manager_1.AsyncStorageManager,
23
- useFactory: () => {
24
- return new als_manager_1.AsyncStorageManager(new async_hooks_1.AsyncLocalStorage());
25
- },
23
+ useFactory: () => new als_manager_1.AsyncStorageManager(new async_hooks_1.AsyncLocalStorage()),
26
24
  },
27
25
  als_service_1.AsyncStorageService,
28
26
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"als.module.js","sourceRoot":"","sources":["../../lib/als/als.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,+CAAoD;AACpD,+CAAoD;AACpD,6CAAgD;AAezC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;CAAG,CAAA;AAA5B,8DAAyB;oCAAzB,yBAAyB;IAbrC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,iCAAmB;gBAC5B,UAAU,EAAE,GAAG,EAAE;oBACf,OAAO,IAAI,iCAAmB,CAAS,IAAI,+BAAiB,EAAuB,CAAC,CAAC;gBACvF,CAAC;aACF;YACD,iCAAmB;SACpB;QACD,OAAO,EAAE,CAAC,iCAAmB,CAAC;KAC/B,CAAC;GACW,yBAAyB,CAAG"}
1
+ {"version":3,"file":"als.module.js","sourceRoot":"","sources":["../../lib/als/als.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,+CAAoD;AACpD,+CAAoE;AACpE,6CAAgD;AAgBzC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;CAAG,CAAA;AAA5B,8DAAyB;oCAAzB,yBAAyB;IAdrC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,iCAAmB;gBAC5B,UAAU,EAAE,GAAG,EAAE,CACf,IAAI,iCAAmB,CACrB,IAAI,+BAAiB,EAAkB,CACxC;aACJ;YACD,iCAAmB;SACpB;QACD,OAAO,EAAE,CAAC,iCAAmB,CAAC;KAC/B,CAAC;GACW,yBAAyB,CAAG"}
@@ -1,9 +1,11 @@
1
1
  import { AsyncStorageManager } from './als-manager';
2
+ export interface MurLockContext {
3
+ clientId: string;
4
+ holds: Map<string, number>;
5
+ }
2
6
  export declare class AsyncStorageService {
3
7
  private readonly asyncStorageManager;
4
- constructor(asyncStorageManager: AsyncStorageManager<string>);
5
- runWithNewContext<R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs): R;
6
- registerContext(): void;
7
- get(key: string): string;
8
- setClientID(key: string, value: string): void;
8
+ constructor(asyncStorageManager: AsyncStorageManager<MurLockContext>);
9
+ run<R>(store: MurLockContext, fn: () => R): R;
10
+ getContext(): MurLockContext | undefined;
9
11
  }
@@ -16,17 +16,11 @@ let AsyncStorageService = class AsyncStorageService {
16
16
  constructor(asyncStorageManager) {
17
17
  this.asyncStorageManager = asyncStorageManager;
18
18
  }
19
- runWithNewContext(fn, ...args) {
20
- return this.asyncStorageManager.runWithNewContext(fn, ...args);
19
+ run(store, fn) {
20
+ return this.asyncStorageManager.run(store, fn);
21
21
  }
22
- registerContext() {
23
- this.asyncStorageManager.register();
24
- }
25
- get(key) {
26
- return this.asyncStorageManager.get(key);
27
- }
28
- setClientID(key, value) {
29
- this.asyncStorageManager.set(key, value);
22
+ getContext() {
23
+ return this.asyncStorageManager.getStore();
30
24
  }
31
25
  };
32
26
  exports.AsyncStorageService = AsyncStorageService;
@@ -1 +1 @@
1
- {"version":3,"file":"als.service.js","sourceRoot":"","sources":["../../lib/als/als.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAoD;AAG7C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAA6B,mBAAgD;QAAhD,wBAAmB,GAAnB,mBAAmB,CAA6B;IAAG,CAAC;IAEjF,iBAAiB,CAAyB,EAAyB,EAAE,GAAG,IAAW;QACjF,OAAO,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACjE,CAAC;IAED,eAAe;QACb,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,WAAW,CAAC,GAAW,EAAE,KAAa;QACpC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAlBY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAEuC,iCAAmB;GAD1D,mBAAmB,CAkB/B"}
1
+ {"version":3,"file":"als.service.js","sourceRoot":"","sources":["../../lib/als/als.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAoD;AAa7C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YACmB,mBAAwD;QAAxD,wBAAmB,GAAnB,mBAAmB,CAAqC;IACxE,CAAC;IAGJ,GAAG,CAAI,KAAqB,EAAE,EAAW;QACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IAGD,UAAU;QACR,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAC7C,CAAC;CACF,CAAA;AAdY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAG6B,iCAAmB;GAFhD,mBAAmB,CAc/B"}
@@ -121,7 +121,8 @@ function MurLock(releaseTime, waitOrKeyParam, ...keyParams) {
121
121
  }
122
122
  return methodParameterNames.indexOf(source);
123
123
  }
124
- function constructLockKey(args, lockKeyPrefix = 'default') {
124
+ function constructLockKey(args, lockKeyPrefix = 'default', encodeKeyParts = false) {
125
+ const encodePart = (value) => encodeKeyParts ? encodeURIComponent(String(value)) : value;
125
126
  const lockKeyElements = [];
126
127
  if (lockKeyPrefix != 'custom') {
127
128
  lockKeyElements.push(target.constructor.name);
@@ -145,11 +146,11 @@ function MurLock(releaseTime, waitOrKeyParam, ...keyParams) {
145
146
  typeof parameterValue === 'object' &&
146
147
  parameterValue !== null &&
147
148
  path in parameterValue) {
148
- return parameterValue[path];
149
+ return encodePart(parameterValue[path]);
149
150
  }
150
- return parameterValue instanceof Object
151
+ return encodePart(parameterValue instanceof Object
151
152
  ? parameterValue.toString()
152
- : parameterValue;
153
+ : parameterValue);
153
154
  }
154
155
  if (lockKeyPrefix == 'custom') {
155
156
  return source;
@@ -161,7 +162,7 @@ function MurLock(releaseTime, waitOrKeyParam, ...keyParams) {
161
162
  const wrapped = function (...args) {
162
163
  return __awaiter(this, void 0, void 0, function* () {
163
164
  const murLockService = this.murlockServiceDecorator;
164
- const lockKey = constructLockKey(args, murLockService.options.lockKeyPrefix);
165
+ const lockKey = constructLockKey(args, murLockService.options.lockKeyPrefix, murLockService.options.encodeKeyParts);
165
166
  if (!murLockService) {
166
167
  throw new exceptions_1.MurLockException('MurLockService is not available.');
167
168
  }
@@ -1 +1 @@
1
- {"version":3,"file":"murlock.decorator.js","sourceRoot":"","sources":["../../lib/decorators/murlock.decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwC;AACxC,4BAA0B;AAC1B,8CAAiD;AACjD,wDAAoD;AAMvC,QAAA,eAAe,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAMhD,QAAA,mBAAmB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AA8CrE,SAAgB,aAAa,CAC3B,mBAA2C,EAC3C,GAAG,cAAwB;IAE3B,OAAO,UACL,MAAW,EACX,WAAmB,EACnB,UAA8B;QAE9B,IAAI,OAAO,mBAAmB,KAAK,QAAQ,EAAE;YAE3C,OAAO,CAAC,cAAc,CACpB,2BAAmB,EACnB,mBAAmB,EACnB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1B,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,YAAY,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,kBAAkB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE;IAChE,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;KAC3B;IACD,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE;QAClD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;KACxB;IACD,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC;AAC9B,CAAC"}
@@ -1,3 +1,4 @@
1
- export declare class MurLockRedisException extends Error {
1
+ import { MurLockException } from './murlock.exception';
2
+ export declare class MurLockRedisException extends MurLockException {
2
3
  constructor(message: string);
3
4
  }
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MurLockRedisException = void 0;
4
- class MurLockRedisException extends Error {
4
+ const murlock_exception_1 = require("./murlock.exception");
5
+ class MurLockRedisException extends murlock_exception_1.MurLockException {
5
6
  constructor(message) {
6
7
  super(message);
7
8
  this.name = "MurLockRedisException";
@@ -1 +1 @@
1
- {"version":3,"file":"murlock-redis.exception.js","sourceRoot":"","sources":["../../lib/exceptions/murlock-redis.exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC"}
1
+ {"version":3,"file":"murlock-redis.exception.js","sourceRoot":"","sources":["../../lib/exceptions/murlock-redis.exception.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAQvD,MAAa,qBAAsB,SAAQ,oCAAgB;IACzD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC"}
@@ -8,6 +8,12 @@ export interface MurLockModuleOptions {
8
8
  lockKeyPrefix?: 'default' | 'custom';
9
9
  failFastOnRedisError?: boolean;
10
10
  blocking?: boolean;
11
+ autoExtend?: boolean;
12
+ extendInterval?: number;
13
+ onRedisError?: (error: Error) => void;
14
+ reentrant?: boolean;
15
+ encodeKeyParts?: boolean;
16
+ jitter?: boolean;
11
17
  }
12
18
  export interface MurLockModuleAsyncOptions {
13
19
  imports?: any[];
@@ -0,0 +1,9 @@
1
+ local key = KEYS[1]
2
+ local clientId = ARGV[1]
3
+ local releaseTime = ARGV[2]
4
+
5
+ if redis.call("get", key) == clientId then
6
+ return redis.call("pexpire", key, releaseTime)
7
+ else
8
+ return 0
9
+ end
@@ -8,17 +8,26 @@ export declare class MurLockService implements OnModuleInit, OnApplicationShutdo
8
8
  private redisClient;
9
9
  private lockScript;
10
10
  private unlockScript;
11
+ private extendScript;
12
+ private readonly scriptShas;
11
13
  constructor(options: MurLockModuleOptions, asyncStorageService: AsyncStorageService);
12
14
  onModuleInit(): Promise<void>;
13
15
  onApplicationShutdown(signal?: string): Promise<void>;
16
+ private validateOptions;
14
17
  private sleep;
18
+ private withJitter;
15
19
  private log;
20
+ private loadScripts;
21
+ private evalScript;
16
22
  private lock;
17
23
  private unlock;
24
+ private extendLock;
25
+ private startWatchdog;
18
26
  private acquireLock;
19
27
  private releaseLock;
20
28
  runWithLock<R>(lockKey: string, releaseTime: number, fn: () => Promise<R>): Promise<R>;
21
29
  runWithLock<R>(lockKey: string, releaseTime: number, wait: number | ((retries: number) => number), fn: () => Promise<R>): Promise<R>;
30
+ private runReentrant;
22
31
  private registerRedisErrorHandlers;
23
32
  private blockingLock;
24
33
  }