@hastehaul/common 2.0.46 → 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>;
@@ -45,11 +45,12 @@ class RedisClient {
45
45
  client.on('error', (error) => console.log('Replica connected', error.message));
46
46
  });
47
47
  }
48
- // get client(): IORedis {
49
- // if(!this._redisClient) throw new Error("Cannot access Redis Client before connecting")
50
- // return this._redisClient;
51
- // }
52
- static getInstance(masterHost, replicaHosts) {
48
+ get client() {
49
+ if (!RedisClient.instance)
50
+ throw new Error("Cannot access Redis Client before connecting");
51
+ return RedisClient.instance;
52
+ }
53
+ static connect(masterHost, replicaHosts) {
53
54
  if (!RedisClient.instance) {
54
55
  RedisClient.instance = new RedisClient(masterHost, replicaHosts);
55
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.0.46",
3
+ "version": "2.0.47",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",