@saihu/common 1.1.48 → 1.1.50
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/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +17 -0
- package/dist/decorators/saihu-subscribe.decorator.d.ts +12 -0
- package/dist/decorators/saihu-subscribe.decorator.d.ts.map +1 -0
- package/dist/decorators/saihu-subscribe.decorator.js +73 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/services/base.service.d.ts +7 -0
- package/dist/services/base.service.d.ts.map +1 -0
- package/dist/services/base.service.js +11 -0
- package/dist/services/rabbitmq.service.d.ts +3 -3
- package/dist/services/rabbitmq.service.d.ts.map +1 -1
- package/dist/services/rabbitmq.service.js +8 -8
- package/dist/services/redis.service.d.ts +3 -3
- package/dist/services/redis.service.d.ts.map +1 -1
- package/dist/services/redis.service.js +9 -10
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./saihu-subscribe.decorator"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MessageHandlerOptions } from '@golevelup/nestjs-rabbitmq';
|
|
2
|
+
type SaihuSubscribeProps = Omit<MessageHandlerOptions, 'connection' | 'queue' | 'routingKey'> & {
|
|
3
|
+
/** Defaults to 'core' */
|
|
4
|
+
connection?: string;
|
|
5
|
+
/** Your service slug, e.g. 'im-accounting' */
|
|
6
|
+
service: string;
|
|
7
|
+
/** Single routing key string (recommended). If you pass an array, we’ll use the first to name the queue. */
|
|
8
|
+
routingKey: string | string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function SaihuSubscribe(props: SaihuSubscribeProps): MethodDecorator;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=saihu-subscribe.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saihu-subscribe.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/saihu-subscribe.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,KAAK,mBAAmB,GAAG,IAAI,CAC7B,qBAAqB,EACrB,YAAY,GAAG,OAAO,GAAG,YAAY,CACtC,GAAG;IACF,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,4GAA4G;IAC5G,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC/B,CAAC;AAuCF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,eAAe,CA2C1E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaihuSubscribe = SaihuSubscribe;
|
|
4
|
+
// libs/common/src/rabbit/saihu-subscribe.decorator.ts
|
|
5
|
+
const nestjs_rabbitmq_1 = require("@golevelup/nestjs-rabbitmq");
|
|
6
|
+
const topology_1 = require("../messaging/topology");
|
|
7
|
+
// --- helpers ---
|
|
8
|
+
function enumKeyFromValue(enm, val) {
|
|
9
|
+
return Object.keys(enm).find((k) => enm[k] === val);
|
|
10
|
+
}
|
|
11
|
+
function deriveDlxExchange(exchangeValue) {
|
|
12
|
+
const key = enumKeyFromValue(topology_1.Exchanges, exchangeValue);
|
|
13
|
+
if (!key)
|
|
14
|
+
return undefined;
|
|
15
|
+
return topology_1.Exchanges[`${key}_DLX`];
|
|
16
|
+
}
|
|
17
|
+
function deriveDlxRoutingKey(exchangeValue, routingKey) {
|
|
18
|
+
try {
|
|
19
|
+
const group = topology_1.RoutingKeys[exchangeValue];
|
|
20
|
+
const entry = Object.entries(group || {}).find(([, v]) => v === routingKey);
|
|
21
|
+
const logicalKey = entry === null || entry === void 0 ? void 0 : entry[0];
|
|
22
|
+
if (!logicalKey)
|
|
23
|
+
return routingKey;
|
|
24
|
+
const dlxExchange = deriveDlxExchange(exchangeValue);
|
|
25
|
+
if (!dlxExchange)
|
|
26
|
+
return routingKey;
|
|
27
|
+
const dlxGroup = topology_1.RoutingKeys[dlxExchange];
|
|
28
|
+
return (dlxGroup === null || dlxGroup === void 0 ? void 0 : dlxGroup[logicalKey]) || routingKey;
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
return routingKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// --- main decorator ---
|
|
35
|
+
function SaihuSubscribe(props) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const defaults = {
|
|
38
|
+
connection: 'core',
|
|
39
|
+
queueOptions: { durable: true },
|
|
40
|
+
errorHandler: (ch, msg) => ch.nack(msg, false, false),
|
|
41
|
+
};
|
|
42
|
+
// choose one routing key for queue naming if an array is provided
|
|
43
|
+
const rk = Array.isArray(props.routingKey)
|
|
44
|
+
? props.routingKey[0]
|
|
45
|
+
: props.routingKey;
|
|
46
|
+
const merged = {
|
|
47
|
+
...defaults,
|
|
48
|
+
...props,
|
|
49
|
+
routingKey: props.routingKey, // keep original (string or string[])
|
|
50
|
+
queue: (0, topology_1.q)(props.service, rk),
|
|
51
|
+
queueOptions: {
|
|
52
|
+
...(defaults.queueOptions || {}),
|
|
53
|
+
...(props.queueOptions || {}),
|
|
54
|
+
arguments: {
|
|
55
|
+
...(((_a = defaults.queueOptions) === null || _a === void 0 ? void 0 : _a.arguments) || {}),
|
|
56
|
+
...(((_b = props.queueOptions) === null || _b === void 0 ? void 0 : _b.arguments) || {}),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
// Auto-DLX (respect explicit overrides)
|
|
61
|
+
const args = merged.queueOptions.arguments || {};
|
|
62
|
+
const hasExplicitDLX = 'x-dead-letter-exchange' in args || 'x-dead-letter-routing-key' in args;
|
|
63
|
+
if (!hasExplicitDLX && merged.exchange && rk) {
|
|
64
|
+
const dlxExchange = deriveDlxExchange(merged.exchange);
|
|
65
|
+
const dlxRoutingKey = deriveDlxRoutingKey(merged.exchange, rk);
|
|
66
|
+
if (dlxExchange) {
|
|
67
|
+
args['x-dead-letter-exchange'] = dlxExchange;
|
|
68
|
+
args['x-dead-letter-routing-key'] = dlxRoutingKey;
|
|
69
|
+
}
|
|
70
|
+
merged.queueOptions.arguments = args;
|
|
71
|
+
}
|
|
72
|
+
return (0, nestjs_rabbitmq_1.RabbitSubscribe)(merged);
|
|
73
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export * from './auth';
|
|
|
6
6
|
export * from './util';
|
|
7
7
|
export * from './logger';
|
|
8
8
|
export * from './messaging';
|
|
9
|
+
export * from './decorators';
|
|
9
10
|
export { SaihuCommonModule } from './saihu-common.module';
|
|
11
|
+
export { BaseService } from './services/base.service';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SaihuCommonModule = void 0;
|
|
17
|
+
exports.BaseService = exports.SaihuCommonModule = void 0;
|
|
18
18
|
__exportStar(require("./dto"), exports);
|
|
19
19
|
__exportStar(require("./consts"), exports);
|
|
20
20
|
__exportStar(require("./interceptors"), exports);
|
|
@@ -23,5 +23,8 @@ __exportStar(require("./auth"), exports);
|
|
|
23
23
|
__exportStar(require("./util"), exports);
|
|
24
24
|
__exportStar(require("./logger"), exports);
|
|
25
25
|
__exportStar(require("./messaging"), exports);
|
|
26
|
+
__exportStar(require("./decorators"), exports);
|
|
26
27
|
var saihu_common_module_1 = require("./saihu-common.module");
|
|
27
28
|
Object.defineProperty(exports, "SaihuCommonModule", { enumerable: true, get: function () { return saihu_common_module_1.SaihuCommonModule; } });
|
|
29
|
+
var base_service_1 = require("./services/base.service");
|
|
30
|
+
Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return base_service_1.BaseService; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.service.d.ts","sourceRoot":"","sources":["../../src/services/base.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,8BAAsB,WAAW;IAC/B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAEvC,SAAS,aAAa,WAAW,EAAE,MAAM;CAI1C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseService = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class BaseService {
|
|
6
|
+
constructor(serviceName) {
|
|
7
|
+
this.logger = new common_1.Logger(serviceName);
|
|
8
|
+
this.loggerError = new common_1.Logger(`SH-ERROR: ${serviceName}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BaseService = BaseService;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OnModuleInit, OnModuleDestroy } from
|
|
2
|
-
import { CommonModuleOptions } from
|
|
3
|
-
import { RabbitmqService } from
|
|
1
|
+
import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { CommonModuleOptions } from '../interfaces/options.interface';
|
|
3
|
+
import { RabbitmqService } from '../interfaces/service.interface';
|
|
4
4
|
export declare class RabbitmqServiceImpl implements RabbitmqService, OnModuleInit, OnModuleDestroy {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAMtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAkBrD"}
|
|
@@ -74,21 +74,21 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
|
74
74
|
}
|
|
75
75
|
try {
|
|
76
76
|
if (!this.options.rabbitmq) {
|
|
77
|
-
this.logger.error(
|
|
78
|
-
throw new Error(
|
|
77
|
+
this.logger.error('common RabbitMQ options not configured');
|
|
78
|
+
throw new Error('common RabbitMQ options not configured');
|
|
79
79
|
}
|
|
80
80
|
if (!this.options.rabbitmq.url) {
|
|
81
|
-
this.logger.error(
|
|
82
|
-
throw new Error(
|
|
81
|
+
this.logger.error('common RabbitMQ url not configured');
|
|
82
|
+
throw new Error('common RabbitMQ url not configured');
|
|
83
83
|
}
|
|
84
84
|
const connectionString = this.options.rabbitmq.url;
|
|
85
85
|
this.connection = await amqp.connect(connectionString);
|
|
86
86
|
this.channel = await this.connection.createChannel();
|
|
87
87
|
this.isInitialized = true;
|
|
88
|
-
this.logger.log("common RabbitMQ connected successfully");
|
|
88
|
+
// this.logger.log("common RabbitMQ connected successfully");
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|
|
91
|
-
this.logger.error(
|
|
91
|
+
this.logger.error('commonFailed to connect to RabbitMQ:', error);
|
|
92
92
|
throw error;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -105,7 +105,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
|
105
105
|
}
|
|
106
106
|
async publishMessage(message) {
|
|
107
107
|
if (!this.channel) {
|
|
108
|
-
this.logger.error(
|
|
108
|
+
this.logger.error('RabbitMQ channel not initialized');
|
|
109
109
|
return false;
|
|
110
110
|
}
|
|
111
111
|
try {
|
|
@@ -113,7 +113,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
|
113
113
|
return this.channel.publish(common_consts_1.OPER_LOG_EXCHANGE, common_consts_1.OPER_LOG_QUEUE, messageBuffer);
|
|
114
114
|
}
|
|
115
115
|
catch (error) {
|
|
116
|
-
this.logger.error(
|
|
116
|
+
this.logger.error('Failed to publish message to RabbitMQ:', error);
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OnModuleInit, OnModuleDestroy } from
|
|
2
|
-
import { CommonModuleOptions } from
|
|
3
|
-
import { RedisService } from
|
|
1
|
+
import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { CommonModuleOptions } from '../interfaces/options.interface';
|
|
3
|
+
import { RedisService } from '../interfaces/service.interface';
|
|
4
4
|
export declare class RedisServiceImpl implements RedisService, OnModuleInit, OnModuleDestroy {
|
|
5
5
|
private readonly commonOptions;
|
|
6
6
|
private readonly logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAK/C,YAAY;IAIZ,UAAU;
|
|
1
|
+
{"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAK/C,YAAY;IAIZ,UAAU;IAkCV,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,eAAe;CAMhB"}
|
|
@@ -40,28 +40,27 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
|
|
|
40
40
|
}
|
|
41
41
|
try {
|
|
42
42
|
if (!this.commonOptions.redis) {
|
|
43
|
-
this.logger.error(
|
|
44
|
-
throw new Error(
|
|
43
|
+
this.logger.error('common Redis options not found');
|
|
44
|
+
throw new Error('common Redis options not found');
|
|
45
45
|
}
|
|
46
46
|
if (!this.commonOptions.redis.url) {
|
|
47
|
-
this.logger.error(
|
|
48
|
-
throw new Error(
|
|
47
|
+
this.logger.error('common Redis url not found');
|
|
48
|
+
throw new Error('common Redis url not found');
|
|
49
49
|
}
|
|
50
50
|
if (!this.commonOptions.redis.password) {
|
|
51
|
-
this.logger.error(
|
|
52
|
-
throw new Error(
|
|
51
|
+
this.logger.error('common Redis password not found');
|
|
52
|
+
throw new Error('common Redis password not found');
|
|
53
53
|
}
|
|
54
54
|
const url = this.commonOptions.redis.url;
|
|
55
|
-
this.logger.log(`common Redis url: ${url}`);
|
|
56
55
|
const password = this.commonOptions.redis.password;
|
|
57
56
|
this.redisClient = new ioredis_1.default(url, {
|
|
58
57
|
password,
|
|
59
58
|
db: common_consts_1.REDIS_AUTH_DB,
|
|
60
59
|
});
|
|
61
|
-
this.logger.log(
|
|
60
|
+
// this.logger.log('common Redis connected successfully');
|
|
62
61
|
}
|
|
63
62
|
catch (error) {
|
|
64
|
-
this.logger.error(
|
|
63
|
+
this.logger.error('common Failed to connect to Redis:', error);
|
|
65
64
|
throw error;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
@@ -78,7 +77,7 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
|
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
async set(key, value, ttl) {
|
|
81
|
-
const serializedValue = typeof value ===
|
|
80
|
+
const serializedValue = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
82
81
|
if (ttl) {
|
|
83
82
|
await this.redisClient.setex(key, ttl, serializedValue);
|
|
84
83
|
}
|