@diia-inhouse/redis 3.1.77 → 3.2.1
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.
|
@@ -11,6 +11,11 @@ type LockOptions = {
|
|
|
11
11
|
* @defaultValue 500
|
|
12
12
|
*/
|
|
13
13
|
retryInterval?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum time in milliseconds to keep trying to acquire a locked resource before giving up
|
|
16
|
+
* @defaultValue ttl * 2
|
|
17
|
+
*/
|
|
18
|
+
acquireTimeout?: number;
|
|
14
19
|
};
|
|
15
20
|
//#endregion
|
|
16
21
|
export { Lock, LockOptions, MutexStatusResult, RedlockMutex$1 as RedlockMutex };
|
package/dist/services/mutex.d.ts
CHANGED
|
@@ -11,9 +11,12 @@ declare class RedlockService implements OnHealthCheck, OnDestroy {
|
|
|
11
11
|
constructor(storeConfig: RedisConfig, logger: Logger);
|
|
12
12
|
onHealthCheck(): Promise<HealthCheckResult<MutexStatusResult>>;
|
|
13
13
|
onDestroy(): Promise<void>;
|
|
14
|
-
lock(resource: string, ttl?: number,
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
lock(resource: string, ttl?: number, options?: LockOptions): Promise<RedlockMutex>;
|
|
15
|
+
/**
|
|
16
|
+
* Same as `lock`, but resolves with `null` instead of throwing when the resource is not acquired within `acquireTimeout`
|
|
17
|
+
*/
|
|
18
|
+
tryLock(resource: string, ttl?: number, options?: LockOptions): Promise<RedlockMutex | null>;
|
|
19
|
+
private createMutex;
|
|
17
20
|
}
|
|
18
21
|
//#endregion
|
|
19
22
|
export { RedlockService };
|
package/dist/services/mutex.js
CHANGED
|
@@ -37,15 +37,25 @@ var RedlockService = class {
|
|
|
37
37
|
async onDestroy() {
|
|
38
38
|
await this.clientRW.quit();
|
|
39
39
|
}
|
|
40
|
-
async lock(resource, ttl = 6e4,
|
|
40
|
+
async lock(resource, ttl = 6e4, options = {}) {
|
|
41
|
+
const mutex = this.createMutex(resource, ttl, options);
|
|
42
|
+
await mutex.acquire();
|
|
43
|
+
return mutex;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Same as `lock`, but resolves with `null` instead of throwing when the resource is not acquired within `acquireTimeout`
|
|
47
|
+
*/
|
|
48
|
+
async tryLock(resource, ttl = 6e4, options = {}) {
|
|
49
|
+
const mutex = this.createMutex(resource, ttl, options);
|
|
50
|
+
return await mutex.tryAcquire() ? mutex : null;
|
|
51
|
+
}
|
|
52
|
+
createMutex(resource, ttl, { retryInterval = 500, acquireTimeout = ttl * 2 }) {
|
|
41
53
|
this.logger.info(`Start LOCK resource [${resource}] for ttl [${ttl}]ms`);
|
|
42
|
-
|
|
54
|
+
return new RedlockMutex([this.clientRW], resource, {
|
|
43
55
|
lockTimeout: ttl,
|
|
44
|
-
acquireTimeout
|
|
56
|
+
acquireTimeout,
|
|
45
57
|
retryInterval
|
|
46
58
|
});
|
|
47
|
-
await mutex.acquire();
|
|
48
|
-
return mutex;
|
|
49
59
|
}
|
|
50
60
|
};
|
|
51
61
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diia-inhouse/redis",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Redis services - redlock, pubsub, cache and store",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@diia-inhouse/configs": "7.2.1",
|
|
51
|
-
"@diia-inhouse/diia-logger": "4.4.
|
|
52
|
-
"@diia-inhouse/env": "3.3.
|
|
53
|
-
"@diia-inhouse/errors": "2.
|
|
54
|
-
"@diia-inhouse/oxc-config": "2.1.
|
|
55
|
-
"@diia-inhouse/test": "8.3.
|
|
56
|
-
"@diia-inhouse/types": "14.2.
|
|
57
|
-
"@diia-inhouse/validators": "2.2.
|
|
51
|
+
"@diia-inhouse/diia-logger": "4.4.79",
|
|
52
|
+
"@diia-inhouse/env": "3.3.66",
|
|
53
|
+
"@diia-inhouse/errors": "2.3.6",
|
|
54
|
+
"@diia-inhouse/oxc-config": "2.1.7",
|
|
55
|
+
"@diia-inhouse/test": "8.3.23",
|
|
56
|
+
"@diia-inhouse/types": "14.2.13",
|
|
57
|
+
"@diia-inhouse/validators": "2.2.87",
|
|
58
58
|
"@types/node": "25.6.2",
|
|
59
59
|
"@vitest/coverage-v8": "4.1.5",
|
|
60
60
|
"@vitest/ui": "4.1.5",
|