@seidor-cloud-produtos/orbit-backend-lib 1.101.16 → 1.101.18

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.
@@ -1,6 +1,11 @@
1
1
  import { RedisOptions as LibRedisOptions } from 'ioredis';
2
2
  import { CacheClient, CacheClientOptions } from '../../../application/cache/client';
3
+ export type ListenersType = {
4
+ error?: (error: Error) => void;
5
+ } | undefined;
3
6
  export interface RedisOptions extends LibRedisOptions, CacheClientOptions {
7
+ throwOnError?: boolean;
8
+ listeners: ListenersType;
4
9
  }
5
10
  export declare class Redis extends CacheClient {
6
11
  protected connection: RedisOptions;
@@ -16,11 +16,23 @@ class Redis extends client_1.CacheClient {
16
16
  if (this.connection.timeout) {
17
17
  timeout = this.connection.timeout * 1000;
18
18
  }
19
- await new Promise(resolve => setTimeout(resolve, this.connection.timeout || 2500));
19
+ await new Promise(resolve => setTimeout(resolve, timeout || 2500));
20
20
  return null;
21
21
  }
22
22
  async start() {
23
- this.client = new ioredis_1.default(this.connection);
23
+ const { throwOnError, listeners, ...options } = this.connection;
24
+ this.client = new ioredis_1.default(options);
25
+ for (const key in listeners) {
26
+ this.client.on(key, listeners[key]);
27
+ }
28
+ if (throwOnError === false) {
29
+ this.client.on('error', error => {
30
+ console.error('error on redis client', error);
31
+ if (listeners?.error) {
32
+ return listeners.error(error);
33
+ }
34
+ });
35
+ }
24
36
  }
25
37
  async get(key) {
26
38
  const get = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "1.101.16",
3
+ "version": "1.101.18",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",