@hastehaul/common 2.0.45 → 2.0.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,13 @@
1
- import IORedis from 'ioredis';
2
1
  export declare class RedisClient {
3
2
  private master;
4
3
  private replicas;
5
- private _redisClient?;
6
4
  private static instance;
7
5
  private constructor();
8
- static getInstance(masterHost: string, replicaHosts: string[]): RedisClient;
9
- executeMasterOperation(command: string, ...args: any[]): Promise<any>;
10
- executeReplicaOperation(command: string, ...args: any[]): Promise<any>;
11
- executeOperation(client: IORedis, command: string, ...args: any[]): Promise<any>;
6
+ get client(): RedisClient;
7
+ static connect(masterHost: string, replicaHosts: string[]): RedisClient;
8
+ private executeMasterOperation;
9
+ private executeReplicaOperation;
10
+ private executeOperation;
12
11
  set(key: string, value: string): Promise<any>;
13
12
  get(key: string): Promise<any>;
14
13
  del(key: string): Promise<any>;
@@ -38,12 +38,19 @@ class RedisClient {
38
38
  constructor(masterHost, replicaHosts) {
39
39
  this.master = new ioredis_1.default({ host: masterHost, port: 6379 });
40
40
  this.replicas = replicaHosts.map(replicaHost => new ioredis_1.default({ host: replicaHost, port: 6379 }));
41
+ this.master.on("connect", () => console.info("Redis Server Connected!"));
42
+ this.master.on("error", (error) => console.error("Error in Redis", error.message));
43
+ this.replicas.forEach((client) => {
44
+ client.on('connect', () => console.log('Replica connected'));
45
+ client.on('error', (error) => console.log('Replica connected', error.message));
46
+ });
47
+ }
48
+ get client() {
49
+ if (!RedisClient.instance)
50
+ throw new Error("Cannot access Redis Client before connecting");
51
+ return RedisClient.instance;
41
52
  }
42
- // get client(): IORedis {
43
- // if(!this._redisClient) throw new Error("Cannot access Redis Client before connecting")
44
- // return this._redisClient;
45
- // }
46
- static getInstance(masterHost, replicaHosts) {
53
+ static connect(masterHost, replicaHosts) {
47
54
  if (!RedisClient.instance) {
48
55
  RedisClient.instance = new RedisClient(masterHost, replicaHosts);
49
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.0.45",
3
+ "version": "2.0.47",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",