@nathapp/nestjs-redis 1.3.4 → 2.0.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 +5 -5
- package/dist/lock.service.d.ts +1 -0
- package/dist/lock.service.js +12 -0
- package/dist/redis-client.provider.d.ts +2 -2
- package/dist/redis-client.provider.js +2 -2
- package/dist/redis.module.d.ts +2 -2
- package/package.json +6 -6
- package/.eslintrc.js +0 -129
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
# NOTES
|
|
3
|
-
this is fork from https://github.com/skunight/nestjs-redis and upgrade to nestjs 8/9/10
|
|
3
|
+
this is fork from https://github.com/skunight/nestjs-redis and upgrade to nestjs 8/9/10/11
|
|
4
4
|
|
|
5
5
|
This module has added RedisLockService by using 'redlock' to make use of redis distributed lock
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ Redis component for NestJs.
|
|
|
15
15
|
|
|
16
16
|
**Yarn**
|
|
17
17
|
```bash
|
|
18
|
-
yarn add nestjs-redis
|
|
18
|
+
yarn add @nathapp/nestjs-redis
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**NPM**
|
|
22
22
|
```bash
|
|
23
|
-
npm install nestjs-redis --save
|
|
23
|
+
npm install @nathapp/nestjs-redis --save
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### Getting Started
|
|
@@ -28,7 +28,7 @@ Let's register the RedisModule in `app.module.ts`
|
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
import { Module } from '@nestjs/common'
|
|
31
|
-
import { RedisModule} from 'nestjs-redis'
|
|
31
|
+
import { RedisModule} from '@nathapp/nestjs-redis'
|
|
32
32
|
|
|
33
33
|
@Module({
|
|
34
34
|
imports: [
|
|
@@ -39,7 +39,7 @@ export class AppModule {}
|
|
|
39
39
|
```
|
|
40
40
|
With Async
|
|
41
41
|
```typescript
|
|
42
|
-
import { Module } from '@nestjs
|
|
42
|
+
import { Module } from '@nathapp/nestjs-redis';
|
|
43
43
|
import { RedisModule} from 'nestjs-redis'
|
|
44
44
|
|
|
45
45
|
@Module({
|
package/dist/lock.service.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare class RedisLockService implements OnApplicationShutdown {
|
|
|
11
11
|
onApplicationShutdown(signal?: string): Promise<void>;
|
|
12
12
|
acquireLock(name: string, expiryMs?: number): Promise<void>;
|
|
13
13
|
releaseLock(name: string): Promise<void>;
|
|
14
|
+
withLock<T = any>(name: string, runWithLock: () => Promise<T>, expiryMs?: number): Promise<T>;
|
|
14
15
|
}
|
package/dist/lock.service.js
CHANGED
|
@@ -54,6 +54,18 @@ let RedisLockService = RedisLockService_1 = class RedisLockService {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
async withLock(name, runWithLock, expiryMs = 60000) {
|
|
58
|
+
await this.acquireLock(name, expiryMs);
|
|
59
|
+
try {
|
|
60
|
+
return await runWithLock();
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await this.releaseLock(name);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
57
69
|
};
|
|
58
70
|
RedisLockService = RedisLockService_1 = __decorate([
|
|
59
71
|
(0, common_1.Injectable)(),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
2
|
import { Provider } from '@nestjs/common';
|
|
3
3
|
import { RedisModuleAsyncOptions, RedisModuleOptions } from './redis.interface';
|
|
4
4
|
export declare class RedisClientError extends Error {
|
|
5
5
|
}
|
|
6
6
|
export interface RedisClient {
|
|
7
7
|
defaultKey: string;
|
|
8
|
-
clients: Map<string, Redis
|
|
8
|
+
clients: Map<string, Redis>;
|
|
9
9
|
size: number;
|
|
10
10
|
}
|
|
11
11
|
export declare const createClient: () => Provider;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAsyncClientOptions = exports.createClient = exports.RedisClientError = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ioredis_1 = require("ioredis");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const redis_constants_1 = require("./redis.constants");
|
|
7
7
|
class RedisClientError extends Error {
|
|
@@ -9,7 +9,7 @@ class RedisClientError extends Error {
|
|
|
9
9
|
exports.RedisClientError = RedisClientError;
|
|
10
10
|
async function getClient(options) {
|
|
11
11
|
const { onClientReady, url, ...opt } = options;
|
|
12
|
-
const client = url ? new Redis(url) : new Redis(opt);
|
|
12
|
+
const client = url ? new ioredis_1.Redis(url) : new ioredis_1.Redis(opt);
|
|
13
13
|
if (onClientReady) {
|
|
14
14
|
onClientReady(client);
|
|
15
15
|
}
|
package/dist/redis.module.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { RedisModuleAsyncOptions, RedisModuleOptions } from './redis.interface';
|
|
3
3
|
import { LockSettings } from './lock.interface';
|
|
4
|
-
export
|
|
4
|
+
export type RedisRegisterOptions = {
|
|
5
5
|
redisOptions: RedisModuleOptions | RedisModuleOptions[];
|
|
6
6
|
lockSettings?: LockSettings;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type RedisRegisterAsyncOptions = {
|
|
9
9
|
redisOptions: RedisModuleAsyncOptions;
|
|
10
10
|
lockSettings?: LockSettings;
|
|
11
11
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-redis",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "a NestJS ioRedis module",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "William Khoo",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"lint": "eslint -c .eslintrc.js"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
23
|
+
"node": ">=18"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@nestjs/testing": "^
|
|
26
|
+
"@nestjs/testing": "^11.0.0",
|
|
27
27
|
"@types/node": "*",
|
|
28
28
|
"@types/ioredis": "*",
|
|
29
29
|
"@types/uuid": "*",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"typescript": "^4"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
45
|
-
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
44
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
45
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
46
46
|
"ioredis": "^4 || ^5",
|
|
47
47
|
"redlock": "^5.0.0-beta.2",
|
|
48
48
|
"rxjs": "*",
|
package/.eslintrc.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
parser: '@typescript-eslint/parser',
|
|
3
|
-
plugins: [
|
|
4
|
-
'@typescript-eslint',
|
|
5
|
-
'import',
|
|
6
|
-
],
|
|
7
|
-
extends: [
|
|
8
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
9
|
-
'plugin:@typescript-eslint/recommended',
|
|
10
|
-
'plugin:jest/recommended',
|
|
11
|
-
'prettier/@typescript-eslint',
|
|
12
|
-
'prettier/react',
|
|
13
|
-
'plugin:prettier/recommended',
|
|
14
|
-
],
|
|
15
|
-
settings: {
|
|
16
|
-
'import/resolver': {
|
|
17
|
-
typescript: {
|
|
18
|
-
project: ['tsconfig.json', 'tsconfig.spec.json'],
|
|
19
|
-
},
|
|
20
|
-
node: {
|
|
21
|
-
extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
'import/ignore': ['\\.coffee$', '\\.(scss|less|css)$', '\\.(svg|png|jpe?g|webp|gif)(\\?.*)?$'],
|
|
25
|
-
},
|
|
26
|
-
globals: {
|
|
27
|
-
window: true,
|
|
28
|
-
document: true,
|
|
29
|
-
process: true,
|
|
30
|
-
__DEV__: true,
|
|
31
|
-
__SERVER__: true,
|
|
32
|
-
},
|
|
33
|
-
parserOptions: {
|
|
34
|
-
sourceType: 'module',
|
|
35
|
-
jsx: true,
|
|
36
|
-
useJSXTextNode: true,
|
|
37
|
-
ecmaVersion: 2020,
|
|
38
|
-
ecmaFeatures: {
|
|
39
|
-
jsx: true,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
env: {
|
|
43
|
-
es6: true,
|
|
44
|
-
browser: true,
|
|
45
|
-
node: true,
|
|
46
|
-
jest: true,
|
|
47
|
-
},
|
|
48
|
-
rules: {
|
|
49
|
-
'jest/valid-title': 0,
|
|
50
|
-
'no-confusing-arrow': 0,
|
|
51
|
-
'@typescript-eslint/indent': 0,
|
|
52
|
-
'operator-linebreak': 0,
|
|
53
|
-
'function-paren-newline': 0,
|
|
54
|
-
'no-param-reassign': 0,
|
|
55
|
-
'comma-dangle': 0,
|
|
56
|
-
'object-curly-newline': 0,
|
|
57
|
-
'implicit-arrow-linebreak': 0,
|
|
58
|
-
'import/prefer-default-export': 0,
|
|
59
|
-
'class-methods-use-this': 0,
|
|
60
|
-
'lines-between-class-members': 0,
|
|
61
|
-
'quote-props': 0,
|
|
62
|
-
'indent': 0,
|
|
63
|
-
'no-nested-ternary': 0,
|
|
64
|
-
'spaced-comment': ['error', 'always', { markers: ['#region', '#endregion', '/'] }],
|
|
65
|
-
'max-len': ['error', { code: 140, ignoreUrls: true }],
|
|
66
|
-
'import/no-extraneous-dependencies': 0,
|
|
67
|
-
'no-unused-vars': [
|
|
68
|
-
'warn',
|
|
69
|
-
{
|
|
70
|
-
argsIgnorePattern: '^(_|[A-Z]+)',
|
|
71
|
-
varsIgnorePattern: '^(_|[A-Z]+)',
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
'import/extensions': [
|
|
75
|
-
'error',
|
|
76
|
-
'ignorePackages',
|
|
77
|
-
{
|
|
78
|
-
js: 'never',
|
|
79
|
-
jsx: 'never',
|
|
80
|
-
ts: 'never',
|
|
81
|
-
tsx: 'never',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
'prettier/prettier': [
|
|
85
|
-
'error',
|
|
86
|
-
{
|
|
87
|
-
parser: 'typescript',
|
|
88
|
-
printWidth: 140,
|
|
89
|
-
singleQuote: true,
|
|
90
|
-
useTabs: false,
|
|
91
|
-
tabWidth: 2,
|
|
92
|
-
semi: true,
|
|
93
|
-
bracketSpacing: true,
|
|
94
|
-
trailingComma: 'all',
|
|
95
|
-
arrowParens: 'always',
|
|
96
|
-
insertPragma: true,
|
|
97
|
-
quoteProps: 'consistent',
|
|
98
|
-
jsxSingleQuote: false,
|
|
99
|
-
jsxBracketSameLine: false,
|
|
100
|
-
htmlWhitespaceSensivity: 'css',
|
|
101
|
-
proseWrap: 'never',
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
'no-empty-function': 0,
|
|
105
|
-
'no-shadow': 'off',
|
|
106
|
-
'@typescript-eslint/no-shadow': ['error'],
|
|
107
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
108
|
-
'@typescript-eslint/no-unused-vars': [
|
|
109
|
-
'warn',
|
|
110
|
-
{
|
|
111
|
-
argsIgnorePattern: '^(_|[A-Z]+)',
|
|
112
|
-
varsIgnorePattern: '^(_|[A-Z]+)',
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
'react/require-default-props': 0,
|
|
116
|
-
'react/jsx-curly-newline': 0,
|
|
117
|
-
'no-use-before-define': 0,
|
|
118
|
-
'jsx-a11y/anchor-is-valid': 0,
|
|
119
|
-
'no-useless-constructor': 0,
|
|
120
|
-
'react/jsx-one-expression-per-line': 0,
|
|
121
|
-
'react/jsx-wrap-multilines': 0,
|
|
122
|
-
'react/prop-types': 0,
|
|
123
|
-
'react/static-property-placement': 0,
|
|
124
|
-
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx', '.tsx', '.ts'] }],
|
|
125
|
-
'react/jsx-props-no-spreading': 0,
|
|
126
|
-
// '@typescript-eslint/no-var-requires': 0,
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|