@duvdu-v1/duvdu 1.1.273 → 1.1.275

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.
@@ -22,27 +22,19 @@ let connectionPool = [];
22
22
  let currentConnectionIndex = 0;
23
23
  let totalConnectionsRequested = 0;
24
24
  let activeConnections = 0;
25
+ // Cache the RedisStore instance
26
+ let redisStoreInstance = null;
25
27
  // Parse Redis connection details
26
28
  const getRedisConfig = () => {
27
- var _a;
28
- let host = process.env.REDIS_HOST;
29
- let port = 6379;
30
- // Handle URL format (redis://hostname:port)
31
- if (host === null || host === void 0 ? void 0 : host.includes('://')) {
32
- const urlParts = host.split('://');
33
- if ((_a = urlParts[1]) === null || _a === void 0 ? void 0 : _a.includes(':')) {
34
- const hostParts = urlParts[1].split(':');
35
- host = hostParts[0];
36
- port = parseInt(hostParts[1], 10) || 6379;
37
- }
38
- else if (urlParts[1]) {
39
- host = urlParts[1];
40
- }
41
- }
29
+ // Get Redis configuration from environment variables
30
+ const host = process.env.REDIS_HOST || 'redis-11177.c9.us-east-1-2.ec2.redns.redis-cloud.com';
31
+ const port = parseInt(process.env.REDIS_PORT || '11177', 10);
32
+ const password = process.env.REDIS_PASS || 'xgThFOa24hvwyVtsiNhIJiAxfhvJCLBU';
33
+ console.log(`[REDIS] Connecting to Redis at ${host}:${port}`);
42
34
  return {
43
35
  host,
44
36
  port,
45
- password: process.env.REDIS_PASS,
37
+ password,
46
38
  maxRetriesPerRequest: null,
47
39
  enableReadyCheck: false,
48
40
  retryStrategy: (times) => {
@@ -124,20 +116,25 @@ exports.getRedisClient = getRedisClient;
124
116
  const redisConnection = () => __awaiter(void 0, void 0, void 0, function* () {
125
117
  try {
126
118
  const client = (0, exports.getRedisClient)();
127
- const config = getRedisConfig();
128
- console.log(`[REDIS] Connection provided from pool to ${config.host}:${config.port}`);
119
+ console.log('[REDIS] Connection provided from pool');
129
120
  return client;
130
121
  }
131
122
  catch (error) {
132
- console.error(`[REDIS] Cannot connect to Redis: ${process.env.REDIS_HOST}`, error);
133
- throw new data_base_connections_1.DatabaseConnectionError(`Cannot connect to Redis: ${process.env.REDIS_HOST}`);
123
+ const config = getRedisConfig();
124
+ console.error(`[REDIS] Cannot connect to Redis: ${config.host}:${config.port}`, error);
125
+ throw new data_base_connections_1.DatabaseConnectionError(`Cannot connect to Redis: ${config.host}:${config.port}`);
134
126
  }
135
127
  });
136
128
  exports.redisConnection = redisConnection;
137
129
  const sessionStore = () => __awaiter(void 0, void 0, void 0, function* () {
130
+ // Return cached instance if available
131
+ if (redisStoreInstance) {
132
+ return redisStoreInstance;
133
+ }
138
134
  const client = (0, exports.getRedisClient)();
139
135
  console.log('[REDIS] Created session store with pooled connection');
140
- return new connect_redis_1.default({ client });
136
+ redisStoreInstance = new connect_redis_1.default({ client });
137
+ return redisStoreInstance;
141
138
  });
142
139
  exports.sessionStore = sessionStore;
143
140
  const cleanupRedis = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -151,6 +148,8 @@ const cleanupRedis = () => __awaiter(void 0, void 0, void 0, function* () {
151
148
  connectionPool = [];
152
149
  currentConnectionIndex = 0;
153
150
  activeConnections = 0;
151
+ // Reset the store instance
152
+ redisStoreInstance = null;
154
153
  console.log('[REDIS] Connection pool cleared');
155
154
  }
156
155
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.273",
3
+ "version": "1.1.275",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [