eh-commons 0.0.1-testing.80 → 0.0.1-testing.82
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/modules/cache/services/redis.service.d.ts +3 -0
- package/dist/modules/cache/services/redis.service.js +35 -6
- package/dist/modules/cache/services/redis.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modules/cache/services/redis.service.ts +46 -7
|
@@ -3,9 +3,12 @@ import * as IORedis from 'ioredis';
|
|
|
3
3
|
export declare class RedisService {
|
|
4
4
|
private configService;
|
|
5
5
|
private client;
|
|
6
|
+
private clusterClient;
|
|
7
|
+
private _isCluster;
|
|
6
8
|
constructor(configService: ConfigService);
|
|
7
9
|
set(key: string, value: string, ttl?: number): Promise<string>;
|
|
8
10
|
get(key: string): Promise<string>;
|
|
9
11
|
del(key: string): Promise<number>;
|
|
10
12
|
getRedisClient(): IORedis.Redis;
|
|
13
|
+
private _parseRedisClusterUrl;
|
|
11
14
|
}
|
|
@@ -13,30 +13,59 @@ exports.RedisService = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const config_1 = require("@nestjs/config");
|
|
15
15
|
const IORedis = require("ioredis");
|
|
16
|
+
const rest_wrapper_class_1 = require("../../../models/wrappers/rest-wrapper.class");
|
|
16
17
|
let RedisService = class RedisService {
|
|
17
18
|
constructor(configService) {
|
|
18
19
|
this.configService = configService;
|
|
20
|
+
this._isCluster = this.configService.get('REDIS__CLUSTER', true);
|
|
19
21
|
const redisConnectionString = this.configService.get('REDIS__CS');
|
|
20
|
-
this.
|
|
22
|
+
if (this._isCluster) {
|
|
23
|
+
const nodes = this._parseRedisClusterUrl(redisConnectionString);
|
|
24
|
+
this.clusterClient = new IORedis.Cluster(nodes);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.client = new IORedis.Redis(redisConnectionString);
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
async set(key, value, ttl) {
|
|
23
31
|
let result;
|
|
24
32
|
if (ttl) {
|
|
25
|
-
result = await this.
|
|
33
|
+
result = await this.getRedisClient().set(key, value, 'EX', ttl);
|
|
26
34
|
}
|
|
27
35
|
else {
|
|
28
|
-
result = await this.
|
|
36
|
+
result = await this.getRedisClient().set(key, value);
|
|
29
37
|
}
|
|
30
38
|
return result;
|
|
31
39
|
}
|
|
32
40
|
async get(key) {
|
|
33
|
-
return await this.
|
|
41
|
+
return await this.getRedisClient().get(key);
|
|
34
42
|
}
|
|
35
43
|
async del(key) {
|
|
36
|
-
return await this.
|
|
44
|
+
return await this.getRedisClient().del(key);
|
|
37
45
|
}
|
|
38
46
|
getRedisClient() {
|
|
39
|
-
|
|
47
|
+
if (!this._isCluster) {
|
|
48
|
+
return this.client;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.clusterClient;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_parseRedisClusterUrl(connectionString) {
|
|
55
|
+
if (!connectionString.startsWith('redis://')) {
|
|
56
|
+
throw new rest_wrapper_class_1.RESTError('invalid_connection_string', 'Invalid connection string format');
|
|
57
|
+
}
|
|
58
|
+
return connectionString
|
|
59
|
+
.replace('redis://', '')
|
|
60
|
+
.split(',')
|
|
61
|
+
.map((entry) => {
|
|
62
|
+
const [host, portStr] = entry.trim().split(':');
|
|
63
|
+
const port = parseInt(portStr, 10);
|
|
64
|
+
if (!host || isNaN(port)) {
|
|
65
|
+
throw new rest_wrapper_class_1.RESTError('invalid_redis_host_port', `Invalid host:port entry: ${entry}`);
|
|
66
|
+
}
|
|
67
|
+
return { host, port };
|
|
68
|
+
});
|
|
40
69
|
}
|
|
41
70
|
};
|
|
42
71
|
exports.RedisService = RedisService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../../../../src/modules/cache/services/redis.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,mCAAmC;
|
|
1
|
+
{"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../../../../src/modules/cache/services/redis.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,mCAAmC;AACnC,oFAAwE;AAGjE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAKvB,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAFxC,eAAU,GAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAAU,gBAAgB,EAAE,IAAI,CAAC,CAAC;QAGpF,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAElE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;YAChE,IAAI,CAAC,aAAa,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;QAChD,IAAI,MAAoC,CAAC;QACzC,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,MAA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