shuttlepro-shared 1.3.67 → 1.3.68
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.
- package/config/redis.js +11 -2
- package/package.json +1 -1
package/config/redis.js
CHANGED
|
@@ -41,6 +41,15 @@ const connectRedis = async () => {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
// ✅ Ensure Redis is connected once during app startup
|
|
45
|
+
const connectRedisClient = async () => {
|
|
46
|
+
try {
|
|
47
|
+
if (!client.isOpen) await client.connect();
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("❌ Failed to connect to Redis:", err);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
44
53
|
// ✅ Publish Data to a Channel
|
|
45
54
|
const publishToChannel = async (channel, message) => {
|
|
46
55
|
try {
|
|
@@ -70,7 +79,7 @@ const setRedisData = async (
|
|
|
70
79
|
expiryInSeconds = 3600
|
|
71
80
|
) => {
|
|
72
81
|
try {
|
|
73
|
-
await
|
|
82
|
+
await connectRedisClient();
|
|
74
83
|
const stringifiedValue = JSON.stringify(value);
|
|
75
84
|
let result;
|
|
76
85
|
|
|
@@ -94,7 +103,7 @@ const setRedisData = async (
|
|
|
94
103
|
// ✅ Get Data from Redis (Supports String & Hash)
|
|
95
104
|
const getRedisData = async (key, field = null) => {
|
|
96
105
|
try {
|
|
97
|
-
await
|
|
106
|
+
await connectRedisClient();
|
|
98
107
|
const result = field
|
|
99
108
|
? await client.hGet(key, field)
|
|
100
109
|
: await client.get(key);
|