@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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
}
|