@uber-clone/common 1.0.7 → 1.0.8
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,3 +1,6 @@
|
|
|
1
|
+
import { RedisClientType } from "redis";
|
|
2
|
+
import Redlock from "redlock";
|
|
3
|
+
import { Logger } from "../utils/logger";
|
|
1
4
|
export interface GeoLocation {
|
|
2
5
|
type?: "Point";
|
|
3
6
|
coordinates: [number, number];
|
|
@@ -21,11 +24,13 @@ export interface RedisConfig {
|
|
|
21
24
|
}
|
|
22
25
|
export declare class RedisClient {
|
|
23
26
|
private config;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
protected static instance: RedisClient;
|
|
28
|
+
protected redis: RedisClientType;
|
|
29
|
+
protected redlock: Redlock | null;
|
|
30
|
+
protected logger: Logger;
|
|
31
|
+
protected isConnected: boolean;
|
|
28
32
|
constructor(config?: RedisConfig);
|
|
33
|
+
static getInstance(): RedisClient;
|
|
29
34
|
private initializeRedlock;
|
|
30
35
|
private setupEventListeners;
|
|
31
36
|
connect(): Promise<void>;
|
|
@@ -21,8 +21,8 @@ class RedisClient {
|
|
|
21
21
|
constructor(config = {}) {
|
|
22
22
|
this.config = config;
|
|
23
23
|
this.redlock = null;
|
|
24
|
-
this.isConnected = false;
|
|
25
24
|
this.logger = new logger_1.Logger("RedisClient");
|
|
25
|
+
this.isConnected = false;
|
|
26
26
|
this.redis = (0, redis_1.createClient)({
|
|
27
27
|
url: process.env.REDIS_URL || "redis://redis-cluster:6379",
|
|
28
28
|
socket: {
|
|
@@ -32,13 +32,17 @@ class RedisClient {
|
|
|
32
32
|
},
|
|
33
33
|
connectTimeout: 10000,
|
|
34
34
|
},
|
|
35
|
-
// password: config.password,
|
|
36
|
-
// database: config.db || 0,
|
|
37
35
|
});
|
|
38
36
|
this.initializeRedlock();
|
|
39
37
|
this.setupEventListeners();
|
|
40
38
|
this.connect().catch((err) => this.logger.error("Auto-connect failed:", err));
|
|
41
39
|
}
|
|
40
|
+
static getInstance() {
|
|
41
|
+
if (!this.instance) {
|
|
42
|
+
this.instance = new RedisClient();
|
|
43
|
+
}
|
|
44
|
+
return this.instance;
|
|
45
|
+
}
|
|
42
46
|
initializeRedlock() {
|
|
43
47
|
try {
|
|
44
48
|
this.redlock = new redlock_1.default([this.redis], {
|