@diia-inhouse/redis 2.19.0 → 2.29.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.
Files changed (35) hide show
  1. package/LICENCE.md +59 -59
  2. package/dist/interfaces/index.js +0 -1
  3. package/dist/interfaces/index.js.map +1 -1
  4. package/dist/interfaces/redis.js +6 -1
  5. package/dist/interfaces/redis.js.map +1 -1
  6. package/dist/services/index.js +0 -1
  7. package/dist/services/index.js.map +1 -1
  8. package/dist/services/mutex.js +4 -4
  9. package/dist/services/mutex.js.map +1 -1
  10. package/dist/services/providers/pubsub.js +4 -3
  11. package/dist/services/providers/pubsub.js.map +1 -1
  12. package/dist/services/pubsub.js.map +1 -1
  13. package/dist/services/redis.js +50 -2
  14. package/dist/services/redis.js.map +1 -1
  15. package/dist/services/store.js +16 -8
  16. package/dist/services/store.js.map +1 -1
  17. package/dist/types/interfaces/deps.d.ts +1 -2
  18. package/dist/types/interfaces/index.d.ts +0 -1
  19. package/dist/types/interfaces/mutex.d.ts +7 -0
  20. package/dist/types/interfaces/redis.d.ts +12 -3
  21. package/dist/types/interfaces/store.d.ts +16 -2
  22. package/dist/types/services/index.d.ts +0 -1
  23. package/dist/types/services/mutex.d.ts +2 -2
  24. package/dist/types/services/redis.d.ts +4 -2
  25. package/dist/types/services/store.d.ts +2 -1
  26. package/package.json +30 -51
  27. package/dist/interfaces/cache.js +0 -3
  28. package/dist/interfaces/cache.js.map +0 -1
  29. package/dist/services/cache.js +0 -75
  30. package/dist/services/cache.js.map +0 -1
  31. package/dist/services/providers/cache.js +0 -58
  32. package/dist/services/providers/cache.js.map +0 -1
  33. package/dist/types/interfaces/cache.d.ts +0 -14
  34. package/dist/types/services/cache.d.ts +0 -24
  35. package/dist/types/services/providers/cache.d.ts +0 -17
package/LICENCE.md CHANGED
@@ -18,40 +18,40 @@ or has expressed by any other means his willingness to license under the EUPL.
18
18
 
19
19
  In this Licence, the following terms have the following meaning:
20
20
 
21
- - ‘The Licence’: this Licence.
21
+ - ‘The Licence’: this Licence.
22
22
 
23
- - ‘The Original Work’: the work or software distributed or communicated by the
24
- Licensor under this Licence, available as Source Code and also as Executable
25
- Code as the case may be.
23
+ - ‘The Original Work’: the work or software distributed or communicated by the
24
+ Licensor under this Licence, available as Source Code and also as Executable
25
+ Code as the case may be.
26
26
 
27
- - ‘Derivative Works’: the works or software that could be created by the
28
- Licensee, based upon the Original Work or modifications thereof. This Licence
29
- does not define the extent of modification or dependence on the Original Work
30
- required in order to classify a work as a Derivative Work; this extent is
31
- determined by copyright law applicable in the country mentioned in Article 15.
27
+ - ‘Derivative Works’: the works or software that could be created by the
28
+ Licensee, based upon the Original Work or modifications thereof. This Licence
29
+ does not define the extent of modification or dependence on the Original Work
30
+ required in order to classify a work as a Derivative Work; this extent is
31
+ determined by copyright law applicable in the country mentioned in Article 15.
32
32
 
33
- - ‘The Work’: the Original Work or its Derivative Works.
33
+ - ‘The Work’: the Original Work or its Derivative Works.
34
34
 
35
- - ‘The Source Code’: the human-readable form of the Work which is the most
36
- convenient for people to study and modify.
35
+ - ‘The Source Code’: the human-readable form of the Work which is the most
36
+ convenient for people to study and modify.
37
37
 
38
- - ‘The Executable Code’: any code which has generally been compiled and which is
39
- meant to be interpreted by a computer as a program.
38
+ - ‘The Executable Code’: any code which has generally been compiled and which is
39
+ meant to be interpreted by a computer as a program.
40
40
 
41
- - ‘The Licensor’: the natural or legal person that distributes or communicates
42
- the Work under the Licence.
41
+ - ‘The Licensor’: the natural or legal person that distributes or communicates
42
+ the Work under the Licence.
43
43
 
44
- - ‘Contributor(s)’: any natural or legal person who modifies the Work under the
45
- Licence, or otherwise contributes to the creation of a Derivative Work.
44
+ - ‘Contributor(s)’: any natural or legal person who modifies the Work under the
45
+ Licence, or otherwise contributes to the creation of a Derivative Work.
46
46
 
47
- - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
48
- the Work under the terms of the Licence.
47
+ - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
48
+ the Work under the terms of the Licence.
49
49
 
50
- - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
51
- renting, distributing, communicating, transmitting, or otherwise making
52
- available, online or offline, copies of the Work or providing access to its
53
- essential functionalities at the disposal of any other natural or legal
54
- person.
50
+ - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
51
+ renting, distributing, communicating, transmitting, or otherwise making
52
+ available, online or offline, copies of the Work or providing access to its
53
+ essential functionalities at the disposal of any other natural or legal
54
+ person.
55
55
 
56
56
  2. Scope of the rights granted by the Licence
57
57
 
@@ -59,15 +59,15 @@ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
59
59
  sublicensable licence to do the following, for the duration of copyright vested
60
60
  in the Original Work:
61
61
 
62
- - use the Work in any circumstance and for all usage,
63
- - reproduce the Work,
64
- - modify the Work, and make Derivative Works based upon the Work,
65
- - communicate to the public, including the right to make available or display
66
- the Work or copies thereof to the public and perform publicly, as the case may
67
- be, the Work,
68
- - distribute the Work or copies thereof,
69
- - lend and rent the Work or copies thereof,
70
- - sublicense rights in the Work or copies thereof.
62
+ - use the Work in any circumstance and for all usage,
63
+ - reproduce the Work,
64
+ - modify the Work, and make Derivative Works based upon the Work,
65
+ - communicate to the public, including the right to make available or display
66
+ the Work or copies thereof to the public and perform publicly, as the case may
67
+ be, the Work,
68
+ - distribute the Work or copies thereof,
69
+ - lend and rent the Work or copies thereof,
70
+ - sublicense rights in the Work or copies thereof.
71
71
 
72
72
  Those rights can be exercised on any media, supports and formats, whether now
73
73
  known or later invented, as far as the applicable law permits so.
@@ -240,43 +240,43 @@ their choice.
240
240
 
241
241
  Without prejudice to specific agreement between parties,
242
242
 
243
- - any litigation resulting from the interpretation of this License, arising
244
- between the European Union institutions, bodies, offices or agencies, as a
245
- Licensor, and any Licensee, will be subject to the jurisdiction of the Court
246
- of Justice of the European Union, as laid down in article 272 of the Treaty on
247
- the Functioning of the European Union,
243
+ - any litigation resulting from the interpretation of this License, arising
244
+ between the European Union institutions, bodies, offices or agencies, as a
245
+ Licensor, and any Licensee, will be subject to the jurisdiction of the Court
246
+ of Justice of the European Union, as laid down in article 272 of the Treaty on
247
+ the Functioning of the European Union,
248
248
 
249
- - any litigation arising between other parties and resulting from the
250
- interpretation of this License, will be subject to the exclusive jurisdiction
251
- of the competent court where the Licensor resides or conducts its primary
252
- business.
249
+ - any litigation arising between other parties and resulting from the
250
+ interpretation of this License, will be subject to the exclusive jurisdiction
251
+ of the competent court where the Licensor resides or conducts its primary
252
+ business.
253
253
 
254
254
  15. Applicable Law
255
255
 
256
256
  Without prejudice to specific agreement between parties,
257
257
 
258
- - this Licence shall be governed by the law of the European Union Member State
259
- where the Licensor has his seat, resides or has his registered office,
258
+ - this Licence shall be governed by the law of the European Union Member State
259
+ where the Licensor has his seat, resides or has his registered office,
260
260
 
261
- - this licence shall be governed by Belgian law if the Licensor has no seat,
262
- residence or registered office inside a European Union Member State.
261
+ - this licence shall be governed by Belgian law if the Licensor has no seat,
262
+ residence or registered office inside a European Union Member State.
263
263
 
264
264
  Appendix
265
265
 
266
266
  ‘Compatible Licences’ according to Article 5 EUPL are:
267
267
 
268
- - GNU General Public License (GPL) v. 2, v. 3
269
- - GNU Affero General Public License (AGPL) v. 3
270
- - Open Software License (OSL) v. 2.1, v. 3.0
271
- - Eclipse Public License (EPL) v. 1.0
272
- - CeCILL v. 2.0, v. 2.1
273
- - Mozilla Public Licence (MPL) v. 2
274
- - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
275
- - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
276
- works other than software
277
- - European Union Public Licence (EUPL) v. 1.1, v. 1.2
278
- - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
279
- Reciprocity (LiLiQ-R+).
268
+ - GNU General Public License (GPL) v. 2, v. 3
269
+ - GNU Affero General Public License (AGPL) v. 3
270
+ - Open Software License (OSL) v. 2.1, v. 3.0
271
+ - Eclipse Public License (EPL) v. 1.0
272
+ - CeCILL v. 2.0, v. 2.1
273
+ - Mozilla Public Licence (MPL) v. 2
274
+ - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
275
+ - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
276
+ works other than software
277
+ - European Union Public Licence (EUPL) v. 1.1, v. 1.2
278
+ - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
279
+ Reciprocity (LiLiQ-R+).
280
280
 
281
281
  The European Commission may update this Appendix to later versions of the above
282
282
  licences without producing a new version of the EUPL, as long as they provide
@@ -14,7 +14,6 @@ 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
- __exportStar(require("./cache"), exports);
18
17
  __exportStar(require("./pubsub"), exports);
19
18
  __exportStar(require("./redis"), exports);
20
19
  __exportStar(require("./mutex"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,2CAAwB;AAExB,0CAAuB;AAEvB,0CAAuB;AAEvB,0CAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AAExB,0CAAuB;AAEvB,0CAAuB;AAEvB,0CAAuB"}
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisStatusValue = void 0;
3
+ exports.RedisStatusValue = exports.RedisMode = void 0;
4
+ var RedisMode;
5
+ (function (RedisMode) {
6
+ RedisMode["ReadWrite"] = "READ-WRITE";
7
+ RedisMode["ReadOnly"] = "READ-ONLY";
8
+ })(RedisMode || (exports.RedisMode = RedisMode = {}));
4
9
  var RedisStatusValue;
5
10
  (function (RedisStatusValue) {
6
11
  RedisStatusValue["Ready"] = "ready";
@@ -1 +1 @@
1
- {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/interfaces/redis.ts"],"names":[],"mappings":";;;AAIA,IAAY,gBAEX;AAFD,WAAY,gBAAgB;IACxB,mCAAe,CAAA;AACnB,CAAC,EAFW,gBAAgB,gCAAhB,gBAAgB,QAE3B"}
1
+ {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/interfaces/redis.ts"],"names":[],"mappings":";;;AAEA,IAAY,SAGX;AAHD,WAAY,SAAS;IACjB,qCAAwB,CAAA;IACxB,mCAAsB,CAAA;AAC1B,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AASD,IAAY,gBAEX;AAFD,WAAY,gBAAgB;IACxB,mCAAe,CAAA;AACnB,CAAC,EAFW,gBAAgB,gCAAhB,gBAAgB,QAE3B"}
@@ -14,7 +14,6 @@ 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
- __exportStar(require("./cache"), exports);
18
17
  __exportStar(require("./pubsub"), exports);
19
18
  __exportStar(require("./redis"), exports);
20
19
  __exportStar(require("./store"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,2CAAwB;AAExB,0CAAuB;AAEvB,0CAAuB;AAEvB,0CAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AAExB,0CAAuB;AAEvB,0CAAuB;AAEvB,0CAAuB"}
@@ -13,7 +13,7 @@ class RedlockService {
13
13
  this.storeConfig = storeConfig;
14
14
  this.logger = logger;
15
15
  const { readWrite } = this.storeConfig;
16
- this.clientRW = redis_2.RedisService.createClient(readWrite);
16
+ this.clientRW = redis_2.RedisService.createClient({ ...readWrite, redisMode: redis_1.RedisMode.ReadWrite }, this.logger);
17
17
  this.clientRW.on('connect', () => {
18
18
  const { host, port, sentinels } = readWrite;
19
19
  this.logger.info('Redis REDLOCK READ-WRITE connection open', { host, port, sentinels });
@@ -33,9 +33,9 @@ class RedlockService {
33
33
  async onDestroy() {
34
34
  await this.clientRW.quit();
35
35
  }
36
- async lock(resource, ttl = 60000) {
37
- this.logger.info(`Start LOCK resource [${resource}] for ttl [${ttl}]`);
38
- const mutex = new redis_semaphore_1.RedlockMutex([this.clientRW], resource, { lockTimeout: ttl, acquireTimeout: ttl * 2 });
36
+ async lock(resource, ttl = 60000, { retryInterval = 500 } = {}) {
37
+ this.logger.info(`Start LOCK resource [${resource}] for ttl [${ttl}]ms`);
38
+ const mutex = new redis_semaphore_1.RedlockMutex([this.clientRW], resource, { lockTimeout: ttl, acquireTimeout: ttl * 2, retryInterval });
39
39
  await mutex.acquire();
40
40
  return mutex;
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mutex.js","sourceRoot":"","sources":["../../src/services/mutex.ts"],"names":[],"mappings":";;;AACA,qDAA8C;AAE9C,+CAAyG;AAGzG,+CAAmE;AAEnE,mCAAsC;AAEtC,MAAa,cAAc;IAIF;IAEA;IALb,QAAQ,CAAO;IAEvB,YACqB,WAAwB,EAExB,MAAc;QAFd,gBAAW,GAAX,WAAW,CAAa;QAExB,WAAM,GAAN,MAAM,CAAQ;QAE/B,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,WAAW,CAAA;QAEtC,IAAI,CAAC,QAAQ,GAAG,oBAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QAEpD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,E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EAAE;SAClC,CAAA;IACL,CAAC;IAED,KAAK,CAAC,SAAS;QACX,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgB,EAAE,GAAG,GAAG,KAAK,EAAE,EAAE,aAAa,GAAG,GAAG,KAAkB,EAAE;QAC/E,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,QAAQ,cAAc,GAAG,KAAK,CAAC,CAAA;QACxE,MAAM,KAAK,GAAG,IAAI,8BAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC,EAAE,aAAa,EAAE,CAAC,CAAA;QAEvH,MAAM,KAAK,CAAC,OAAO,EAAE,CAAA;QAErB,OAAO,KAAK,CAAA;IAChB,CAAC;CACJ;AA7CD,wCA6CC"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PubSubProvider = void 0;
4
- const redis_1 = require("../redis");
4
+ const redis_1 = require("../../interfaces/redis");
5
+ const redis_2 = require("../redis");
5
6
  class PubSubProvider {
6
7
  logger;
7
8
  pub;
@@ -10,8 +11,8 @@ class PubSubProvider {
10
11
  handlerByChannel = {};
11
12
  constructor({ readWrite, readOnly }, logger) {
12
13
  this.logger = logger;
13
- this.pub = redis_1.RedisService.createClient(readWrite);
14
- this.sub = redis_1.RedisService.createClient({ ...readOnly, autoResubscribe: true });
14
+ this.pub = redis_2.RedisService.createClient({ ...readWrite, redisMode: redis_1.RedisMode.ReadWrite }, this.logger);
15
+ this.sub = redis_2.RedisService.createClient({ ...readOnly, redisMode: redis_1.RedisMode.ReadOnly, autoResubscribe: true }, this.logger);
15
16
  this.pub.on('connect', () => {
16
17
  const { host, port, sentinels } = readWrite;
17
18
  this.logger.info('Redis READ-WRITE pub connection open', { host, port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});
6
6
  exports.RedisService = void 0;
7
7
  const ioredis_1 = __importDefault(require("ioredis"));
8
+ const types_1 = require("@diia-inhouse/types");
8
9
  exports.RedisService = {
9
- createClient(options) {
10
+ createClient(extendedRedisOptions, logger) {
11
+ const { maxRetryAttempts = 10, initialRetryDelay = types_1.DurationMs.Second, maxRetryDelay = types_1.DurationMs.Second * 10, ...options } = extendedRedisOptions;
12
+ const { host, port, redisMode } = options;
10
13
  const redisOptions = {
14
+ keepAlive: types_1.DurationMs.Second * 10,
11
15
  enableAutoPipelining: true,
16
+ reconnectOnError: (err) => {
17
+ logger.error('Redis error detected due:', { err, host, port, redisMode });
18
+ const targetError = 'READONLY';
19
+ if (err.message.includes(targetError)) {
20
+ // Force reconnect and resend the failed command after reconnection
21
+ // https://github.com/redis/ioredis?tab=readme-ov-file#reconnect-on-error
22
+ logger.warn('Redis encountered READONLY error, forcing reconnect', { host, port, redisMode });
23
+ return 2;
24
+ }
25
+ return false;
26
+ },
27
+ retryStrategy: (attempts) => {
28
+ if (attempts > maxRetryAttempts) {
29
+ logger.error(`Redis connection failed after ${maxRetryAttempts} attempts. Shutting down connection attempts.`, {
30
+ host,
31
+ port,
32
+ redisMode,
33
+ });
34
+ return null; // Stop retrying (null instead of false)
35
+ }
36
+ const delay = Math.min(initialRetryDelay * Math.pow(2, attempts - 1), maxRetryDelay);
37
+ logger.debug(`Redis connection attempt ${attempts} failed. Retrying in ${delay}ms...`, {
38
+ host,
39
+ port,
40
+ redisMode,
41
+ });
42
+ return delay;
43
+ },
12
44
  ...options,
13
45
  };
14
- return new ioredis_1.default(redisOptions);
46
+ const client = new ioredis_1.default(redisOptions);
47
+ client.on('ready', () => {
48
+ logger.debug('Redis client is ready to accept commands', { host, port, redisMode });
49
+ });
50
+ client.on('close', () => {
51
+ logger.debug('Redis connection closed', { host, port, redisMode });
52
+ });
53
+ client.on('reconnecting', (timeToReconnect) => {
54
+ logger.debug(`Redis client is reconnecting in ${timeToReconnect}ms`, { host, port, redisMode });
55
+ });
56
+ client.on('end', () => {
57
+ logger.debug('Redis connection ended, no more reconnection attempts will be made', { host, port, redisMode });
58
+ });
59
+ client.on('wait', () => {
60
+ logger.debug('Redis client is waiting to reconnect', { host, port, redisMode });
61
+ });
62
+ return client;
15
63
  },
16
64
  };
17
65
  //# sourceMappingURL=redis.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/services/redis.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6C;AAEhC,QAAA,YAAY,GAAG;IACxB,YAAY,CAAC,OAAqB;QAC9B,MAAM,YAAY,GAAiB;YAC/B,oBAAoB,EAAE,IAAI;YAC1B,GAAG,OAAO;SACb,CAAA;QAED,OAAO,IAAI,iBAAK,CAAC,YAAY,CAAC,CAAA;IAClC,CAAC;CACJ,CAAA"}
1
+ {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/services/redis.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA+D;AAG/D,+CAAwD;AAE3C,QAAA,YAAY,GAAG;IACxB,YAAY,CAAC,oBAAkC,EAAE,MAAc;QAC3D,MAAM,EACF,gBAAgB,GAAG,EAAE,EACrB,iBAAiB,GAAG,kBAAU,CAAC,MAAM,EACrC,aAAa,GAAG,kBAAU,CAAC,MAAM,GAAG,EAAE,EACtC,GAAG,OAAO,EACb,GAAG,oBAAoB,CAAA;QAExB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;QAEzC,MAAM,YAAY,GAAmB;YACjC,SAAS,EAAE,kBAAU,CAAC,MAAM,GAAG,EAAE;YACjC,oBAAoB,EAAE,IAAI;YAC1B,gBAAgB,EAAE,CAAC,GAAG,EAAE,EAAE;gBACtB,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;gBAEzE,MAAM,WAAW,GAAG,UAAU,CAAA;gBAC9B,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AI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACtE,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,eAAuB,EAAE,EAAE;YAClD,MAAM,CAAC,KAAK,CAAC,mCAAmC,eAAe,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACnG,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAClB,MAAM,CAAC,KAAK,CAAC,oEAAoE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACjH,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACnB,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACnF,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ,CAAA"}
@@ -15,21 +15,19 @@ class StoreService {
15
15
  this.storeConfig = storeConfig;
16
16
  this.logger = logger;
17
17
  const { readWrite, readOnly } = this.storeConfig;
18
- this.clientRW = redis_2.RedisService.createClient(readWrite);
19
- this.clientRO = redis_2.RedisService.createClient(readOnly);
18
+ this.clientRW = redis_2.RedisService.createClient({ ...readWrite, redisMode: redis_1.RedisMode.ReadWrite }, this.logger);
19
+ this.clientRO = redis_2.RedisService.createClient({ ...readOnly, redisMode: redis_1.RedisMode.ReadOnly }, this.logger);
20
20
  this.clientRW.on('connect', () => {
21
- this.logger.info(`Store READ-WRITE connection open to ${JSON.stringify(readWrite.sentinels)}`);
21
+ this.logger.info('Store READ-WRITE connection open');
22
22
  });
23
23
  this.clientRW.on('error', (err) => {
24
- this.logger.info('Store READ-WRITE connection error ', { err });
25
- this.logger.info(`Store Path ${JSON.stringify(readWrite.sentinels)}`);
24
+ this.logger.error('Store READ-WRITE connection error ', { err });
26
25
  });
27
26
  this.clientRO.on('connect', () => {
28
- this.logger.info(`Store READ-ONLY connection open to ${JSON.stringify(readOnly.sentinels)}`);
27
+ this.logger.info('Store READ-ONLY connection open');
29
28
  });
30
29
  this.clientRO.on('error', (err) => {
31
- this.logger.info('Store READ-ONLY connection error ', { err });
32
- this.logger.info(`Store Path ${JSON.stringify(readOnly.sentinels)}`);
30
+ this.logger.error('Store READ-ONLY connection error ', { err });
33
31
  });
34
32
  }
35
33
  async onHealthCheck() {
@@ -149,6 +147,16 @@ class StoreService {
149
147
  }
150
148
  return await this.clientRW.set(this.tagsKey, JSON.stringify(tagsConfig));
151
149
  }
150
+ async throttle(key, maxBurst, rate, periodSec, quantity = 1) {
151
+ const result = (await this.clientRW.call('CL.THROTTLE', key, maxBurst, rate, periodSec, quantity));
152
+ return {
153
+ limited: result[0] === 1,
154
+ totalLimit: result[1],
155
+ remaining: result[2],
156
+ retryAfterSec: result[3],
157
+ resetAfterSec: result[4],
158
+ };
159
+ }
152
160
  async flushDb() {
153
161
  return await this.clientRW.flushdb();
154
162
  }
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/services/store.ts"],"names":[],"mappings":";;;AAEA,iDAA8D;AAC9D,+CAAyG;AAEzG,+CAAgF;AAGhF,mCAAsC;AAEtC,MAAa,YAAY;IAQA;IAEA;IATb,QAAQ,CAAO;IAEf,QAAQ,CAAO;IAEf,OAAO,GAAG,OAAO,CAAA;IAEzB,YACqB,WAAwB,EAExB,MAAc;QAFd,gBAAW,GAAX,WAAW,CAAa;QAExB,WAAM,GAAN,MAAM,CAAQ;QAE/B,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,WAAW,CAAA;QAEhD,IAAI,CAAC,QAAQ,GAAG,oBAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QACpD,IAAI,CAAC,QAAQ,GAAG,oBAAY,CAAC,YAA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CAAC,CAAA;QAE5C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,IAAI,YAAY,IAAI,SAAS,CAAC,CAAA;IAC3F,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAAC,IAAY,EAAE,IAAc;QAC5D,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACvD,MAAM,UAAU,GAAe,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAErE,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;aAC3C,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC;YACxC,oEAAoE;aACnE,MAAM,CAAC,CAAC,YAAY,EAA0B,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;QAE5E,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAE3E,MAAM,YAAY,GAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;QAEhE,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IACvC,CAAC;CACJ;AApOD,oCAoOC"}
@@ -1,6 +1,5 @@
1
- import { CacheService, PubSubService, RedlockService, StoreService } from '../services';
1
+ import { PubSubService, RedlockService, StoreService } from '../services';
2
2
  export type RedisDeps = {
3
- cache?: CacheService;
4
3
  pubsub?: PubSubService;
5
4
  redlock?: RedlockService;
6
5
  store?: StoreService;
@@ -1,4 +1,3 @@
1
- export * from './cache';
2
1
  export * from './pubsub';
3
2
  export * from './redis';
4
3
  export * from './mutex';
@@ -4,3 +4,10 @@ export type Lock = RedlockMutex;
4
4
  export type MutexStatusResult = {
5
5
  mutex: string;
6
6
  };
7
+ export type LockOptions = {
8
+ /**
9
+ * Time in milliseconds between acquire attempts if resource locked
10
+ * @defaultValue 500
11
+ */
12
+ retryInterval?: number;
13
+ };
@@ -1,5 +1,14 @@
1
- import { RedisOptions } from 'ioredis';
2
- export { RedisOptions } from 'ioredis';
1
+ import { RedisOptions as IoRedisOptions } from 'ioredis';
2
+ export declare enum RedisMode {
3
+ ReadWrite = "READ-WRITE",
4
+ ReadOnly = "READ-ONLY"
5
+ }
6
+ export interface RedisOptions extends IoRedisOptions {
7
+ maxRetryAttempts?: number;
8
+ initialRetryDelay?: number;
9
+ maxRetryDelay?: number;
10
+ redisMode?: RedisMode;
11
+ }
3
12
  export declare enum RedisStatusValue {
4
13
  Ready = "ready"
5
14
  }
@@ -9,7 +18,7 @@ export interface RedisConfig {
9
18
  readOnly: RedisOptions;
10
19
  enablePubsub?: boolean;
11
20
  }
12
- export interface CacheStatus {
21
+ export interface StoreStatus {
13
22
  readWrite: RedisStatus;
14
23
  readOnly: RedisStatus;
15
24
  }
@@ -1,4 +1,4 @@
1
- import { CacheStatus } from './redis';
1
+ import { StoreStatus } from './redis';
2
2
  export type TagsConfig = {
3
3
  [tag in string]?: number;
4
4
  };
@@ -8,9 +8,23 @@ export interface TaggedStoreValue {
8
8
  tags: string[];
9
9
  }
10
10
  export interface SetValueOptions {
11
+ /**
12
+ * Time to live in milliseconds.
13
+ * If not set, the key will be permanent.
14
+ */
11
15
  ttl?: number;
16
+ /**
17
+ * Tags associated with the value.
18
+ */
12
19
  tags?: string[];
13
20
  }
21
+ export interface ThrottleResult {
22
+ limited: boolean;
23
+ totalLimit: number;
24
+ remaining: number;
25
+ retryAfterSec: number;
26
+ resetAfterSec: number;
27
+ }
14
28
  export type StoreStatusResult = {
15
- store: CacheStatus;
29
+ store: StoreStatus;
16
30
  };
@@ -1,4 +1,3 @@
1
- export * from './cache';
2
1
  export * from './pubsub';
3
2
  export * from './redis';
4
3
  export * from './store';
@@ -1,6 +1,6 @@
1
1
  import { RedlockMutex } from 'redis-semaphore';
2
2
  import { HealthCheckResult, Logger, OnDestroy, OnHealthCheck } from '@diia-inhouse/types';
3
- import { MutexStatusResult } from '../interfaces';
3
+ import { LockOptions, MutexStatusResult } from '../interfaces';
4
4
  import { RedisConfig } from '../interfaces/redis';
5
5
  export declare class RedlockService implements OnHealthCheck, OnDestroy {
6
6
  private readonly storeConfig;
@@ -9,5 +9,5 @@ export declare class RedlockService implements OnHealthCheck, OnDestroy {
9
9
  constructor(storeConfig: RedisConfig, logger: Logger);
10
10
  onHealthCheck(): Promise<HealthCheckResult<MutexStatusResult>>;
11
11
  onDestroy(): Promise<void>;
12
- lock(resource: string, ttl?: number): Promise<RedlockMutex>;
12
+ lock(resource: string, ttl?: number, { retryInterval }?: LockOptions): Promise<RedlockMutex>;
13
13
  }
@@ -1,4 +1,6 @@
1
- import Redis, { RedisOptions } from 'ioredis';
1
+ import Redis from 'ioredis';
2
+ import { RedisOptions } from 'src/interfaces';
3
+ import { Logger } from '@diia-inhouse/types';
2
4
  export declare const RedisService: {
3
- createClient(options: RedisOptions): Redis;
5
+ createClient(extendedRedisOptions: RedisOptions, logger: Logger): Redis;
4
6
  };
@@ -1,6 +1,6 @@
1
1
  import { HealthCheckResult, Logger, OnDestroy, OnHealthCheck } from '@diia-inhouse/types';
2
2
  import { RedisConfig } from '../interfaces/redis';
3
- import { SetValueOptions, StoreStatusResult } from '../interfaces/store';
3
+ import { SetValueOptions, StoreStatusResult, ThrottleResult } from '../interfaces/store';
4
4
  export declare class StoreService implements OnHealthCheck, OnDestroy {
5
5
  private readonly storeConfig;
6
6
  private readonly logger;
@@ -36,6 +36,7 @@ export declare class StoreService implements OnHealthCheck, OnDestroy {
36
36
  hdel(key: string, ...fields: string[]): Promise<number>;
37
37
  expire(key: string, seconds: number): Promise<number>;
38
38
  bumpTags(tags: string[]): Promise<'OK' | null>;
39
+ throttle(key: string, maxBurst: number, rate: number, periodSec: number, quantity?: number): Promise<ThrottleResult>;
39
40
  flushDb(): Promise<'OK'>;
40
41
  private validate;
41
42
  private wrapValueWithMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/redis",
3
- "version": "2.19.0",
3
+ "version": "2.29.0",
4
4
  "description": "Redis services - redlock, pubsub, cache and store",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -11,29 +11,27 @@
11
11
  "dist"
12
12
  ],
13
13
  "engines": {
14
- "node": ">=20"
14
+ "node": ">=22"
15
15
  },
16
16
  "scripts": {
17
17
  "prebuild": "rimraf dist",
18
18
  "build": "tsc",
19
19
  "semantic-release": "semantic-release",
20
20
  "start": "npm run build && node dist/index.js",
21
- "lint": "eslint --ext .ts . && prettier --check .",
22
- "lint-fix": "eslint '*/**/*.{js,ts}' --fix && prettier --write .",
21
+ "lint": "eslint . && prettier --check .",
22
+ "lint-fix": "eslint . --fix && prettier --write .",
23
23
  "lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
24
24
  "prepare": "npm run build",
25
- "test": "jest",
26
- "test:coverage": "jest --coverage",
27
- "test:unit": "npm run test --selectProjects unit --",
28
- "test:integration": "npm run test --selectProjects integration --",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest watch",
29
27
  "find-circulars": "madge --circular --extensions ts ./"
30
28
  },
31
29
  "resolutions": {
32
- "@babel/traverse": "7.23.2"
30
+ "@babel/traverse": "7.25.9"
33
31
  },
34
32
  "dependencies": {
35
- "ioredis": "5.4.1",
36
- "redis-semaphore": "5.6.0"
33
+ "ioredis": "5.6.1",
34
+ "redis-semaphore": "5.6.2"
37
35
  },
38
36
  "peerDependencies": {
39
37
  "@diia-inhouse/env": ">=1.2.0",
@@ -42,53 +40,34 @@
42
40
  "@diia-inhouse/validators": ">=1.6.1"
43
41
  },
44
42
  "devDependencies": {
45
- "@diia-inhouse/configs": "2.2.0",
46
- "@diia-inhouse/diia-logger": "3.3.0",
47
- "@diia-inhouse/env": "1.16.0",
48
- "@diia-inhouse/errors": "1.10.0",
49
- "@diia-inhouse/eslint-config": "5.1.0",
50
- "@diia-inhouse/test": "6.4.0",
51
- "@diia-inhouse/types": "6.50.0",
52
- "@diia-inhouse/validators": "1.17.0",
53
- "@types/node": "22.1.0",
54
- "eslint": "8.57.0",
55
- "eslint-plugin-prettier": "5.1.3",
56
- "lockfile-lint": "4.14.0",
43
+ "@diia-inhouse/configs": "6.1.1",
44
+ "@diia-inhouse/diia-logger": "3.16.0",
45
+ "@diia-inhouse/env": "2.8.0",
46
+ "@diia-inhouse/errors": "1.17.0",
47
+ "@diia-inhouse/eslint-config": "8.2.4",
48
+ "@diia-inhouse/test": "7.2.0",
49
+ "@diia-inhouse/types": "11.3.0",
50
+ "@diia-inhouse/validators": "1.28.0",
51
+ "@types/node": "25.3.3",
52
+ "@vitest/coverage-v8": "4.0.18",
53
+ "@vitest/ui": "4.0.18",
54
+ "eslint": "9.39.3",
55
+ "eslint-plugin-prettier": "5.5.5",
56
+ "lockfile-lint": "4.14.1",
57
57
  "madge": "8.0.0",
58
- "prettier": "3.3.3",
59
- "protobufjs": "7.2.5",
60
- "rimraf": "6.0.1",
61
- "semantic-release": "24.0.0",
62
- "typescript": "5.4.5"
58
+ "prettier": "3.8.1",
59
+ "rimraf": "6.1.3",
60
+ "semantic-release": "24.2.9",
61
+ "typescript": "5.9.3",
62
+ "vitest": "4.0.18",
63
+ "vitest-mock-extended": "3.1.0"
63
64
  },
64
65
  "release": {
65
- "extends": "@diia-inhouse/configs/dist/semantic-release/package",
66
- "branches": [
67
- "main"
68
- ]
66
+ "extends": "@diia-inhouse/configs/dist/semantic-release/package"
69
67
  },
70
68
  "commitlint": {
71
69
  "extends": "@diia-inhouse/configs/dist/commitlint"
72
70
  },
73
- "eslintConfig": {
74
- "extends": "@diia-inhouse/eslint-config",
75
- "overrides": [
76
- {
77
- "files": [
78
- "*.ts"
79
- ],
80
- "parserOptions": {
81
- "project": [
82
- "./tsconfig.json",
83
- "./tests/tsconfig.json"
84
- ]
85
- }
86
- }
87
- ]
88
- },
89
- "jest": {
90
- "preset": "@diia-inhouse/configs/dist/jest"
91
- },
92
71
  "prettier": "@diia-inhouse/eslint-config/prettier",
93
72
  "madge": {
94
73
  "tsConfig": "./tsconfig.json"
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=cache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/interfaces/cache.ts"],"names":[],"mappings":""}
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheService = void 0;
4
- const types_1 = require("@diia-inhouse/types");
5
- const redis_1 = require("../interfaces/redis");
6
- const cache_1 = require("./providers/cache");
7
- /**
8
- * @deprecated StoreService class should be used instead of this one
9
- */
10
- class CacheService {
11
- redisConfig;
12
- envService;
13
- logger;
14
- defaultExpiration = 60 * 60 * 3; // 3 hours
15
- provider;
16
- constructor(redisConfig, envService, logger) {
17
- this.redisConfig = redisConfig;
18
- this.envService = envService;
19
- this.logger = logger;
20
- this.provider = new cache_1.RedisCacheProvider(this.redisConfig, logger);
21
- }
22
- async onHealthCheck() {
23
- const cacheStatus = this.provider.getStatus();
24
- const status = Object.values(cacheStatus).some((s) => s !== redis_1.RedisStatusValue.Ready)
25
- ? types_1.HttpStatusCode.SERVICE_UNAVAILABLE
26
- : types_1.HttpStatusCode.OK;
27
- return {
28
- status,
29
- details: { cache: cacheStatus },
30
- };
31
- }
32
- async onDestroy() {
33
- await this.provider.quit();
34
- }
35
- async get(key) {
36
- const mappedKey = this.addPrefix(key);
37
- try {
38
- const result = await this.provider.get(mappedKey);
39
- return result;
40
- }
41
- catch (err) {
42
- this.logger.error('Failed to get cached value from a provider', { err });
43
- throw err;
44
- }
45
- }
46
- async set(key, data, expiration = this.defaultExpiration) {
47
- const mappedKey = this.addPrefix(key);
48
- const result = await this.provider.set(mappedKey, data, expiration);
49
- return result;
50
- }
51
- async getKeysByPattern(pattern) {
52
- return await this.provider.getKeysByPattern(this.addPrefix(pattern));
53
- }
54
- async getByKeys(keys) {
55
- try {
56
- return await this.provider.getByKeys(keys);
57
- }
58
- catch (err) {
59
- this.logger.error('Failed to get cached value from a provider by keys', { err });
60
- throw err;
61
- }
62
- }
63
- async remove(key) {
64
- const result = await this.provider.remove(this.addPrefix(key));
65
- return result;
66
- }
67
- addPrefix(key) {
68
- if (this.envService.isTest()) {
69
- return `test.${key}`;
70
- }
71
- return key.toString();
72
- }
73
- }
74
- exports.CacheService = CacheService;
75
- //# sourceMappingURL=cache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/services/cache.ts"],"names":[],"mappings":";;;AAGA,+CAAyG;AAGzG,+CAAmE;AAEnE,6CAAsD;AAEtD;;GAEG;AACH,MAAa,YAAY;IAMA;IAEA;IACA;IARJ,iBAAiB,GAAW,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA,CAAC,UAAU;IAElD,QAAQ,CAAe;IAExC,YACqB,WAAwB,EAExB,UAAsB,EACtB,MAAc;QAHd,gBAAW,GAAX,WAAW,CAAa;QAExB,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAQ;QAE/B,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAkB,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,aAAa;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAE7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,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AAC,SAAS,CAAC,IAAc;QAC1B,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;YAEhF,MAAM,GAAG,CAAA;QACb,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;QAE9D,OAAO,MAAM,CAAA;IACjB,CAAC;IAEO,SAAS,CAAC,GAAa;QAC3B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3B,OAAO,QAAQ,GAAG,EAAE,CAAA;QACxB,CAAC;QAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;CACJ;AA/ED,oCA+EC"}
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisCacheProvider = void 0;
4
- const redis_1 = require("../redis");
5
- class RedisCacheProvider {
6
- logger;
7
- clientRW;
8
- clientRO;
9
- constructor({ readWrite, readOnly }, logger) {
10
- this.logger = logger;
11
- this.clientRW = redis_1.RedisService.createClient(readWrite);
12
- this.clientRO = redis_1.RedisService.createClient(readOnly);
13
- this.clientRW.on('connect', () => {
14
- const { host, port, sentinels } = readWrite;
15
- this.logger.info('Redis READ-WRITE connection open', { host, port, sentinels });
16
- });
17
- this.clientRW.on('error', (err) => {
18
- this.logger.error('Redis READ-WRITE connection error ', { err });
19
- });
20
- this.clientRO.on('connect', () => {
21
- const { host, port, sentinels } = readOnly;
22
- this.logger.info('Redis READ-ONLY connection open', { host, port, sentinels });
23
- });
24
- this.clientRO.on('error', (err) => {
25
- this.logger.error('Redis READ-ONLY connection error ', { err });
26
- });
27
- }
28
- async get(key) {
29
- return await this.clientRO.get(key);
30
- }
31
- async set(key, data, expiration) {
32
- const result = await this.clientRW.set(key, data);
33
- if (expiration !== -1) {
34
- await this.clientRW.expire(key, expiration);
35
- }
36
- return result;
37
- }
38
- async getKeysByPattern(pattern) {
39
- return await this.clientRO.keys(pattern);
40
- }
41
- async getByKeys(keys) {
42
- return await this.clientRO.mget(keys);
43
- }
44
- async remove(...key) {
45
- return await this.clientRW.del(...key);
46
- }
47
- async quit() {
48
- await Promise.all([this.clientRW.quit(), this.clientRO.quit()]);
49
- }
50
- getStatus() {
51
- return {
52
- readWrite: this.clientRW.status,
53
- readOnly: this.clientRO.status,
54
- };
55
- }
56
- }
57
- exports.RedisCacheProvider = RedisCacheProvider;
58
- //# sourceMappingURL=cache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/services/providers/cache.ts"],"names":[],"mappings":";;;AAMA,oCAAuC;AAEvC,MAAa,kBAAkB;IAQN;IAPb,QAAQ,CAAO;IAEf,QAAQ,CAAO;IAEvB,YACI,EAAE,SAAS,EAAE,QAAQ,EAAe,EAEnB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAE/B,IAAI,CAAC,QAAQ,GAAG,oBAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QACpD,IAAI,CAAC,QAAQ,GAAG,oBAAY,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAEnD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;YAE3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACnF,CAAC,CAAC,CAAA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AA;IAC5C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAc;QAC1B,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAG,GAAa;QACzB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,SAAS;QACL,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;SACjC,CAAA;IACL,CAAC;CACJ;AArED,gDAqEC"}
@@ -1,14 +0,0 @@
1
- import { RedisKey, RedisValue } from 'ioredis';
2
- import { CacheStatus } from './redis';
3
- export interface CacheProvider {
4
- get(key: RedisKey): Promise<string | null>;
5
- set(key: RedisKey, data: RedisValue, expiration: number): Promise<string>;
6
- getKeysByPattern(pattern: string): Promise<string[]>;
7
- getByKeys(keys: string[]): Promise<(null | string)[]>;
8
- remove(...key: string[]): Promise<number>;
9
- getStatus(): CacheStatus;
10
- quit(): Promise<void>;
11
- }
12
- export type CacheStatusResult = {
13
- cache: CacheStatus;
14
- };
@@ -1,24 +0,0 @@
1
- import { RedisKey, RedisValue } from 'ioredis';
2
- import { EnvService } from '@diia-inhouse/env';
3
- import { HealthCheckResult, Logger, OnDestroy, OnHealthCheck } from '@diia-inhouse/types';
4
- import { CacheStatusResult } from '../interfaces/cache';
5
- import { RedisConfig } from '../interfaces/redis';
6
- /**
7
- * @deprecated StoreService class should be used instead of this one
8
- */
9
- export declare class CacheService implements OnHealthCheck, OnDestroy {
10
- private readonly redisConfig;
11
- private readonly envService;
12
- private readonly logger;
13
- private readonly defaultExpiration;
14
- private readonly provider;
15
- constructor(redisConfig: RedisConfig, envService: EnvService, logger: Logger);
16
- onHealthCheck(): Promise<HealthCheckResult<CacheStatusResult>>;
17
- onDestroy(): Promise<void>;
18
- get(key: RedisKey): Promise<string | null>;
19
- set(key: RedisKey, data: RedisValue, expiration?: number): Promise<string>;
20
- getKeysByPattern(pattern: string): Promise<string[]>;
21
- getByKeys(keys: string[]): Promise<(string | null)[]>;
22
- remove(key: string): Promise<number>;
23
- private addPrefix;
24
- }
@@ -1,17 +0,0 @@
1
- import { RedisKey, RedisValue } from 'ioredis';
2
- import { Logger } from '@diia-inhouse/types';
3
- import { CacheProvider } from '../../interfaces/cache';
4
- import { CacheStatus, RedisConfig } from '../../interfaces/redis';
5
- export declare class RedisCacheProvider implements CacheProvider {
6
- private readonly logger;
7
- private clientRW;
8
- private clientRO;
9
- constructor({ readWrite, readOnly }: RedisConfig, logger: Logger);
10
- get(key: string): Promise<string | null>;
11
- set(key: RedisKey, data: RedisValue, expiration: number): Promise<string>;
12
- getKeysByPattern(pattern: string): Promise<string[]>;
13
- getByKeys(keys: string[]): Promise<(string | null)[]>;
14
- remove(...key: string[]): Promise<number>;
15
- quit(): Promise<void>;
16
- getStatus(): CacheStatus;
17
- }