@edirect/redis 11.0.60 → 11.0.61

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/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/redis",
3
- "version": "11.0.60",
4
- "packageScope": "@edirect",
3
+ "version": "11.0.61",
5
4
  "main": "./dist/src/index.js",
6
5
  "types": "./dist/src/index.d.ts",
7
6
  "exports": {
@@ -17,27 +16,11 @@
17
16
  "dist"
18
17
  ],
19
18
  "dependencies": {
19
+ "@edirect/config": "^11.0.61",
20
+ "@edirect/logger": "^11.0.61",
20
21
  "@nestjs/common": "^11.1.19",
21
22
  "redis": "^5.12.1",
22
- "tslib": "^2.8.1",
23
- "@edirect/config": "11.0.60",
24
- "@edirect/logger": "11.0.60"
23
+ "tslib": "^2.8.1"
25
24
  },
26
- "nx": {
27
- "name": "@edirect/redis",
28
- "targets": {
29
- "build": {
30
- "executor": "@nx/js:tsc",
31
- "options": {
32
- "main": "{workspaceRoot}/packages/edirect-redis/src/index.ts",
33
- "tsConfig": "{workspaceRoot}/packages/edirect-redis/tsconfig.lib.json",
34
- "outputPath": "{workspaceRoot}/packages/edirect-redis/dist",
35
- "assets": [
36
- "{workspaceRoot}/packages/edirect-redis/package.json",
37
- "{workspaceRoot}/packages/edirect-redis/README.md"
38
- ]
39
- }
40
- }
41
- }
42
- }
43
- }
25
+ "type": "commonjs"
26
+ }
package/dist/README.md DELETED
@@ -1,123 +0,0 @@
1
- # @edirect/redis
2
-
3
- Redis client module for eDirect NestJS applications. Wraps the `redis` Node.js client and exposes a `RedisService` with high-level methods for key-value, hash, and set operations — all with automatic JSON serialization and centralized error logging.
4
-
5
- ## Features
6
-
7
- - Global module — register once, inject `RedisService` anywhere
8
- - Automatic JSON serialization/deserialization for stored values
9
- - TTL support with configurable expiry types (`EX`, `PX`, `EXAT`, `PXAT`)
10
- - Hash operations (`hget`, `hgetall`)
11
- - Conditional set (`setnx`) for atomic operations
12
- - Integrated error logging via `@edirect/logger`
13
- - Health check via `asyncPing()`
14
-
15
- ## Installation
16
-
17
- ```sh
18
- pnpm add @edirect/redis
19
- # or
20
- npm install @edirect/redis
21
- ```
22
-
23
- ## Usage
24
-
25
- ### Register in your AppModule
26
-
27
- ```ts
28
- import { Module } from '@nestjs/common';
29
- import { ConfigModule } from '@edirect/config';
30
- import { LoggerModule } from '@edirect/logger';
31
- import { RedisModule } from '@edirect/redis';
32
-
33
- @Module({
34
- imports: [
35
- ConfigModule,
36
- LoggerModule.register({ output: 'console' }),
37
- RedisModule,
38
- ],
39
- })
40
- export class AppModule {}
41
- ```
42
-
43
- Because `RedisModule` is decorated with `@Global()`, you only need to import it once at the root module.
44
-
45
- ### Inject and use RedisService
46
-
47
- ```ts
48
- import { Injectable } from '@nestjs/common';
49
- import { RedisService } from '@edirect/redis';
50
-
51
- @Injectable()
52
- export class CacheService {
53
- constructor(private readonly redis: RedisService) {}
54
-
55
- async cachePolicy(policyId: string, data: object): Promise<void> {
56
- // Store with 5-minute TTL
57
- await this.redis.set(`policy:${policyId}`, data, 300);
58
- }
59
-
60
- async getPolicy(policyId: string): Promise<object | null> {
61
- return this.redis.get(`policy:${policyId}`) as Promise<object | null>;
62
- }
63
-
64
- async isAlive(): Promise<boolean> {
65
- return this.redis.asyncPing();
66
- }
67
- }
68
- ```
69
-
70
- ## Environment Variables
71
-
72
- | Variable | Description | Required |
73
- | ----------- | ----------------------------------------------------------------------- | -------- |
74
- | `REDIS_URL` | Redis connection URL (e.g., `redis://localhost:6379`) | Yes |
75
- | `REDIS_TTL` | Default TTL in seconds when `ttl` param is omitted (use `0` for no TTL) | No |
76
-
77
- ## API
78
-
79
- ### `RedisService`
80
-
81
- | Method | Signature | Description |
82
- | ----------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
83
- | `get` | `(key: string): Promise<string \| object \| null>` | Get and JSON-parse a value by key |
84
- | `mget` | `(keys: string[]): Promise<string[] \| object[]>` | Get and JSON-parse multiple keys |
85
- | `set` | `(key: string, data: object \| string, ttl?: number, ttlType?: 'EX' \| 'PX' \| 'EXAT' \| 'PXAT'): Promise<void>` | Set a value with optional TTL. Falls back to `REDIS_TTL` env. |
86
- | `del` | `(key: string): Promise<void>` | Delete a key |
87
- | `setnx` | `(key: string, data: object \| string): Promise<boolean>` | Set only if the key does not exist. Returns `true` if set. |
88
- | `hget` | `(hash: string, field: string): Promise<string \| null>` | Get a single field from a hash |
89
- | `hgetall` | `(hash: string): Promise<{ [key: string]: string }>` | Get all fields from a hash |
90
- | `keys` | `(pattern: string): Promise<string \| string[]>` | Find keys matching a pattern |
91
- | `asyncPing` | `(): Promise<boolean>` | Returns `true` if Redis responds to PING |
92
-
93
- ### TTL Types
94
-
95
- | `ttlType` | Description |
96
- | -------------- | ------------------------------ |
97
- | `EX` (default) | Seconds from now |
98
- | `PX` | Milliseconds from now |
99
- | `EXAT` | Unix timestamp in seconds |
100
- | `PXAT` | Unix timestamp in milliseconds |
101
-
102
- ## Examples
103
-
104
- ```ts
105
- // Store a string with 1-hour TTL
106
- await redis.set('session:abc', 'user-data', 3600);
107
-
108
- // Store an object (auto-serialized to JSON)
109
- await redis.set('user:123', { name: 'John', role: 'admin' }, 600);
110
-
111
- // Read back (auto-deserialized from JSON)
112
- const user = await redis.get('user:123'); // → { name: 'John', role: 'admin' }
113
-
114
- // Atomic set (only if key doesn't exist)
115
- const wasSet = await redis.setnx('lock:job-1', 'worker-1');
116
-
117
- // Hash operations
118
- await redis.hget('config:th-broker', 'maxPolicies');
119
- const allConfig = await redis.hgetall('config:th-broker');
120
-
121
- // Wildcard key lookup
122
- const sessionKeys = await redis.keys('session:*');
123
- ```
package/dist/package.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "name": "@edirect/redis",
3
- "version": "11.0.59",
4
- "main": "./dist/src/index.js",
5
- "types": "./dist/src/index.d.ts",
6
- "exports": {
7
- "./package.json": "./package.json",
8
- ".": {
9
- "import": "./dist/src/index.js",
10
- "default": "./dist/src/index.js",
11
- "types": "./dist/src/index.d.ts",
12
- "require": "./dist/src/index.js"
13
- }
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "dependencies": {
19
- "@edirect/config": "^11.0.59",
20
- "@edirect/logger": "^11.0.59",
21
- "@nestjs/common": "^11.1.19",
22
- "redis": "^5.12.1",
23
- "tslib": "^2.8.1"
24
- },
25
- "type": "commonjs"
26
- }
@@ -1,3 +0,0 @@
1
- export declare const REDIS_CLIENT_KEY = "REDIS_CLIENT";
2
- export declare const REDIS_SERVICE_KEY = "REDIS_SERVICE";
3
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,kBAAkB,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REDIS_SERVICE_KEY = exports.REDIS_CLIENT_KEY = void 0;
4
- exports.REDIS_CLIENT_KEY = 'REDIS_CLIENT';
5
- exports.REDIS_SERVICE_KEY = 'REDIS_SERVICE';
@@ -1,8 +0,0 @@
1
- export { REDIS_CLIENT_KEY, REDIS_SERVICE_KEY } from './constants';
2
- export { RedisClientModule } from './redis.client.module';
3
- export type { RedisServiceInterface } from './redis.interface';
4
- export { RedisModule } from './redis.module';
5
- export { createRedisClientProvider, RedisClientProvider, RedisProviders, } from './redis.providers';
6
- export { RedisService } from './redis.service';
7
- export type { createClient, RedisClientType as RedisClient, RedisClientType, RedisClientOptions as ClientOpts, RedisClientOptions, } from 'redis';
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,YAAY,EACZ,eAAe,IAAI,WAAW,EAC9B,eAAe,EACf,kBAAkB,IAAI,UAAU,EAChC,kBAAkB,GACnB,MAAM,OAAO,CAAC"}
package/dist/src/index.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisService = exports.RedisProviders = exports.RedisClientProvider = exports.createRedisClientProvider = exports.RedisModule = exports.RedisClientModule = exports.REDIS_SERVICE_KEY = exports.REDIS_CLIENT_KEY = void 0;
4
- var constants_1 = require("./constants");
5
- Object.defineProperty(exports, "REDIS_CLIENT_KEY", { enumerable: true, get: function () { return constants_1.REDIS_CLIENT_KEY; } });
6
- Object.defineProperty(exports, "REDIS_SERVICE_KEY", { enumerable: true, get: function () { return constants_1.REDIS_SERVICE_KEY; } });
7
- var redis_client_module_1 = require("./redis.client.module");
8
- Object.defineProperty(exports, "RedisClientModule", { enumerable: true, get: function () { return redis_client_module_1.RedisClientModule; } });
9
- var redis_module_1 = require("./redis.module");
10
- Object.defineProperty(exports, "RedisModule", { enumerable: true, get: function () { return redis_module_1.RedisModule; } });
11
- var redis_providers_1 = require("./redis.providers");
12
- Object.defineProperty(exports, "createRedisClientProvider", { enumerable: true, get: function () { return redis_providers_1.createRedisClientProvider; } });
13
- Object.defineProperty(exports, "RedisClientProvider", { enumerable: true, get: function () { return redis_providers_1.RedisClientProvider; } });
14
- Object.defineProperty(exports, "RedisProviders", { enumerable: true, get: function () { return redis_providers_1.RedisProviders; } });
15
- var redis_service_1 = require("./redis.service");
16
- Object.defineProperty(exports, "RedisService", { enumerable: true, get: function () { return redis_service_1.RedisService; } });
@@ -1,6 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { RedisClientOptions } from 'redis';
3
- export declare class RedisClientModule {
4
- static forRoot(options?: RedisClientOptions, provide?: string): DynamicModule;
5
- }
6
- //# sourceMappingURL=redis.client.module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.client.module.d.ts","sourceRoot":"","sources":["../../src/redis.client.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAI3C,qBAEa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CACZ,OAAO,CAAC,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,aAAa;CASjB"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var RedisClientModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RedisClientModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const redis_providers_1 = require("./redis.providers");
8
- let RedisClientModule = RedisClientModule_1 = class RedisClientModule {
9
- static forRoot(options, provide) {
10
- const redisProviders = (0, redis_providers_1.RedisProviders)(provide);
11
- return {
12
- module: RedisClientModule_1,
13
- providers: [(0, redis_providers_1.createRedisClientProvider)(options), ...redisProviders],
14
- exports: [...redisProviders],
15
- };
16
- }
17
- };
18
- exports.RedisClientModule = RedisClientModule;
19
- exports.RedisClientModule = RedisClientModule = RedisClientModule_1 = tslib_1.__decorate([
20
- (0, common_1.Global)(),
21
- (0, common_1.Module)({})
22
- ], RedisClientModule);
@@ -1,14 +0,0 @@
1
- export interface RedisServiceInterface {
2
- get(key: string): Promise<string | object | null>;
3
- mget(key: string[]): Promise<string[] | object[]>;
4
- hget(hash: string, field: string): Promise<string | null>;
5
- hgetall(hash: string): Promise<{
6
- [key: string]: string | null;
7
- }>;
8
- set(key: string, data: object | string, ttl?: number): Promise<void>;
9
- del(key: string): Promise<void>;
10
- setnx(key: string, data: object | string): Promise<boolean>;
11
- asyncPing(): Promise<boolean>;
12
- keys(key: string): Promise<string | string[]>;
13
- }
14
- //# sourceMappingURL=redis.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.interface.d.ts","sourceRoot":"","sources":["../../src/redis.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IAElD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAElD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE1D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAEjE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5D,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/C"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export declare class RedisModule {
2
- }
3
- //# sourceMappingURL=redis.module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.module.d.ts","sourceRoot":"","sources":["../../src/redis.module.ts"],"names":[],"mappings":"AAMA,qBAKa,WAAW;CAAG"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const redis_providers_1 = require("./redis.providers");
7
- const providers = (0, redis_providers_1.RedisProviders)();
8
- let RedisModule = class RedisModule {
9
- };
10
- exports.RedisModule = RedisModule;
11
- exports.RedisModule = RedisModule = tslib_1.__decorate([
12
- (0, common_1.Global)(),
13
- (0, common_1.Module)({
14
- providers: [redis_providers_1.RedisClientProvider, ...providers],
15
- exports: [...providers],
16
- })
17
- ], RedisModule);
@@ -1,6 +0,0 @@
1
- import { Provider } from '@nestjs/common';
2
- import { RedisClientOptions } from 'redis';
3
- export declare const createRedisClientProvider: (options?: RedisClientOptions) => Provider;
4
- export declare const RedisClientProvider: Provider;
5
- export declare const RedisProviders: (provide?: string) => Provider[];
6
- //# sourceMappingURL=redis.providers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.providers.d.ts","sourceRoot":"","sources":["../../src/redis.providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAgB,kBAAkB,EAAmB,MAAM,OAAO,CAAC;AAmC1E,eAAO,MAAM,yBAAyB,EAAE,CACtC,OAAO,CAAC,EAAE,kBAAkB,KACzB,QAcH,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,QAajC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,QAAQ,EAgB1D,CAAC"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisProviders = exports.RedisClientProvider = exports.createRedisClientProvider = void 0;
4
- const config_1 = require("@edirect/config");
5
- const redis_1 = require("redis");
6
- const constants_1 = require("./constants");
7
- const redis_service_1 = require("./redis.service");
8
- const logger_1 = require("@edirect/logger");
9
- const defaultOptions = (configService, loggerService) => ({
10
- url: `redis://${configService.get('REDIS_HOST')}:${configService.get('REDIS_PORT')}`,
11
- ...((configService.get('REDIS_PASS') ||
12
- configService.get('REDIS_PASSWORD')) && {
13
- password: configService.get('REDIS_PASS') || configService.get('REDIS_PASSWORD'),
14
- }),
15
- pingInterval: 1000,
16
- socket: {
17
- connectTimeout: 10000,
18
- keepAlive: true,
19
- noDelay: true,
20
- reconnectStrategy(retries, cause) {
21
- if (cause) {
22
- loggerService.error('Error connecting to redis', JSON.stringify(cause));
23
- }
24
- return Math.min(retries * 50, 500);
25
- },
26
- },
27
- });
28
- const createRedisClientProvider = (options) => ({
29
- provide: constants_1.REDIS_CLIENT_KEY,
30
- useFactory: async (configService, loggerService) => {
31
- const redisClient = (0, redis_1.createClient)({
32
- ...defaultOptions(configService, loggerService),
33
- ...options,
34
- });
35
- await redisClient.connect();
36
- return redisClient;
37
- },
38
- inject: [config_1.ConfigService, logger_1.LoggerService],
39
- });
40
- exports.createRedisClientProvider = createRedisClientProvider;
41
- exports.RedisClientProvider = {
42
- provide: constants_1.REDIS_CLIENT_KEY,
43
- useFactory: async (configService, loggerService) => {
44
- const redisClient = (0, redis_1.createClient)(defaultOptions(configService, loggerService));
45
- await redisClient.connect();
46
- return redisClient;
47
- },
48
- inject: [config_1.ConfigService, logger_1.LoggerService],
49
- };
50
- const RedisProviders = (provide) => [
51
- {
52
- provide: provide || constants_1.REDIS_SERVICE_KEY,
53
- useFactory: (redisClient, configService, loggerService) => new redis_service_1.RedisService(redisClient, configService, loggerService),
54
- inject: [constants_1.REDIS_CLIENT_KEY, config_1.ConfigService, logger_1.LoggerService],
55
- },
56
- {
57
- provide: redis_service_1.RedisService,
58
- useExisting: provide || constants_1.REDIS_SERVICE_KEY,
59
- },
60
- ];
61
- exports.RedisProviders = RedisProviders;
@@ -1,22 +0,0 @@
1
- import { ConfigService } from '@edirect/config';
2
- import { LoggerService } from '@edirect/logger';
3
- import { RedisServiceInterface } from './redis.interface';
4
- import type { RedisClientType } from 'redis';
5
- export declare class RedisService implements RedisServiceInterface {
6
- private readonly redisClient;
7
- private readonly configService;
8
- private readonly loggerService;
9
- constructor(redisClient: RedisClientType, configService: ConfigService, loggerService: LoggerService);
10
- get(key: string): Promise<string | object | null>;
11
- mget(keys: string[]): Promise<string[] | object[]>;
12
- hget(hash: string, field: string): Promise<string | null>;
13
- hgetall(hash: string): Promise<{
14
- [key: string]: string;
15
- }>;
16
- set(key: string, data: object | string, ttl?: number, ttlType?: 'EX' | 'PX' | 'EXAT' | 'PXAT'): Promise<void>;
17
- del(key: string): Promise<void>;
18
- setnx(key: string, data: object | string): Promise<boolean>;
19
- asyncPing(): Promise<boolean>;
20
- keys(key: string): Promise<string | string[]>;
21
- }
22
- //# sourceMappingURL=redis.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/redis.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAE7C,qBACa,YAAa,YAAW,qBAAqB;IAGtD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAE5B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAE9B,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAJb,WAAW,EAAE,eAAe,EAE5B,aAAa,EAAE,aAAa,EAE5B,aAAa,EAAE,aAAa;IAGlC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAajD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAalD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAazD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAiBzD,GAAG,CACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAa,GAC5C,OAAO,CAAC,IAAI,CAAC;IA2BH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa3D,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAI7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAe3D"}
@@ -1,130 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisService = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const config_1 = require("@edirect/config");
7
- const logger_1 = require("@edirect/logger");
8
- const constants_1 = require("./constants");
9
- let RedisService = class RedisService {
10
- redisClient;
11
- configService;
12
- loggerService;
13
- constructor(redisClient, configService, loggerService) {
14
- this.redisClient = redisClient;
15
- this.configService = configService;
16
- this.loggerService = loggerService;
17
- }
18
- async get(key) {
19
- try {
20
- const ret = await this.redisClient.get(key);
21
- return ret ? JSON.parse(ret) : null;
22
- }
23
- catch (error) {
24
- this.loggerService.error('Error when executing GET command in redis', JSON.stringify(error));
25
- throw error;
26
- }
27
- }
28
- async mget(keys) {
29
- try {
30
- const ret = await this.redisClient.mGet(keys);
31
- return ret ? ret.map(item => (item ? JSON.parse(item) : null)) : [];
32
- }
33
- catch (error) {
34
- this.loggerService.error('Error when executing MGET command in redis', JSON.stringify(error));
35
- throw error;
36
- }
37
- }
38
- async hget(hash, field) {
39
- try {
40
- const ret = await this.redisClient.hGet(hash, field);
41
- return ret ? JSON.parse(ret) : null;
42
- }
43
- catch (error) {
44
- this.loggerService.error('Error when executing HGET command in redis', JSON.stringify(error));
45
- throw error;
46
- }
47
- }
48
- async hgetall(hash) {
49
- try {
50
- const ret = await this.redisClient.hGetAll(hash);
51
- const result = {};
52
- for (const [key, value] of Object.entries(ret)) {
53
- result[key] = value ? JSON.parse(value) : null;
54
- }
55
- return result;
56
- }
57
- catch (error) {
58
- this.loggerService.error('Error when executing HGETALL command in redis', JSON.stringify(error));
59
- throw error;
60
- }
61
- }
62
- async set(key, data, ttl, ttlType = 'EX') {
63
- try {
64
- if (!ttl)
65
- ttl = parseInt(this.configService.get('REDIS_TTL') || '0', 10);
66
- if (data instanceof Object)
67
- data = JSON.stringify(data);
68
- if (ttl > 0) {
69
- await this.redisClient.set(key, data, {
70
- expiration: {
71
- type: ttlType,
72
- value: ttl,
73
- },
74
- });
75
- }
76
- else {
77
- await this.redisClient.set(key, data);
78
- }
79
- }
80
- catch (error) {
81
- this.loggerService.error(`Error when executing SET${ttlType === 'EX' ? '' : ttlType} command in redis`, JSON.stringify(error));
82
- throw error;
83
- }
84
- }
85
- async del(key) {
86
- try {
87
- await this.redisClient.del(key);
88
- }
89
- catch (error) {
90
- this.loggerService.error('Error when executing DEL command in redis', JSON.stringify(error));
91
- throw error;
92
- }
93
- }
94
- async setnx(key, data) {
95
- try {
96
- if (data instanceof Object)
97
- data = JSON.stringify(data);
98
- return (await this.redisClient.setNX(key, data)) === 1;
99
- }
100
- catch (error) {
101
- this.loggerService.error('Error when executing SETNX command in redis', JSON.stringify(error));
102
- throw error;
103
- }
104
- }
105
- async asyncPing() {
106
- return (await this.redisClient.ping()) === 'PONG';
107
- }
108
- async keys(key) {
109
- try {
110
- const ret = await this.redisClient.keys(key);
111
- if (Array.isArray(ret)) {
112
- return ret.map(item => (item ? JSON.parse(item) : null));
113
- }
114
- return ret ? JSON.parse(ret) : [];
115
- }
116
- catch (error) {
117
- this.loggerService.error('Error when executing KEYS command in redis', JSON.stringify(error));
118
- throw error;
119
- }
120
- }
121
- };
122
- exports.RedisService = RedisService;
123
- exports.RedisService = RedisService = tslib_1.__decorate([
124
- (0, common_1.Injectable)(),
125
- tslib_1.__param(0, (0, common_1.Inject)(constants_1.REDIS_CLIENT_KEY)),
126
- tslib_1.__param(1, (0, common_1.Inject)(config_1.ConfigService)),
127
- tslib_1.__param(2, (0, common_1.Inject)(logger_1.LoggerService)),
128
- tslib_1.__metadata("design:paramtypes", [Object, config_1.ConfigService,
129
- logger_1.LoggerService])
130
- ], RedisService);
@@ -1 +0,0 @@
1
- {"version":"5.9.3"}