lesgo 2.1.7 → 2.1.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,3 @@
1
1
  import { ClientOptions } from '../../types/aws';
2
- declare const deleteRedisCache: (keys: string | string[], clientOpts?: ClientOptions) => Promise<number>;
2
+ declare const deleteRedisCache: (keys: string | string[], clientOpts?: ClientOptions) => Promise<void>;
3
3
  export default deleteRedisCache;
@@ -38,14 +38,19 @@ const FILE = 'lesgo.services.ElastiCacheRedis.deleteRedisCache';
38
38
  const deleteRedisCache = (keys, clientOpts) =>
39
39
  __awaiter(void 0, void 0, void 0, function* () {
40
40
  const client = yield getElastiCacheRedisClient(clientOpts);
41
- let resp;
42
41
  if (!Array.isArray(keys)) {
43
42
  keys = [keys];
44
43
  }
45
44
  try {
46
- resp = yield client.del(...keys);
47
- logger.debug(`${FILE}::RECEIVED_RESPONSE`, { resp, keys });
48
- return resp;
45
+ if (keys.length > 0) {
46
+ for (const key of keys) {
47
+ // Keys to be deleted individually due to using Redis Cluster and key may exist across different nodes
48
+ // ioredis handles the routing of the key to the correct node automatically
49
+ const resp = yield client.del(key);
50
+ logger.debug(`${FILE}::CACHE_KEY_DELETED`, { resp, key });
51
+ }
52
+ }
53
+ logger.debug(`${FILE}::ALL_KEYS_DELETED`, { keys });
49
54
  } catch (err) {
50
55
  throw new LesgoException(
51
56
  'Failed to delete redis cache',
@@ -50,22 +50,26 @@ const scanRedisCache = (pattern, clientOpts) =>
50
50
  { key: 'pattern', type: 'string', required: true },
51
51
  ]);
52
52
  const client = yield getElastiCacheRedisClient(clientOpts);
53
- const keys = [];
53
+ const allKeys = [];
54
54
  try {
55
- let cursor = '0'; // Start cursor
56
- do {
57
- // Perform SCAN operation
58
- const [newCursor, matchedKeys] = yield client.scan(
59
- cursor,
60
- 'MATCH',
61
- pattern
62
- );
63
- cursor = newCursor;
64
- if (matchedKeys.length > 0) {
65
- keys.push(...matchedKeys);
66
- }
67
- } while (cursor !== '0'); // Continue until cursor is 0 (scan complete)
68
- logger.debug(`${FILE}::RECEIVED_RESPONSE`, { keys, input });
55
+ const masterNodes = client.nodes('master');
56
+ for (const node of masterNodes) {
57
+ let cursor = '0';
58
+ do {
59
+ const [newCursor, keys] = yield node.scan(
60
+ cursor,
61
+ 'MATCH',
62
+ pattern,
63
+ 'COUNT',
64
+ 100
65
+ );
66
+ cursor = newCursor;
67
+ if (keys.length > 0) {
68
+ allKeys.push(...keys);
69
+ }
70
+ } while (cursor !== '0');
71
+ }
72
+ logger.debug(`${FILE}::RECEIVED_RESPONSE`, { allKeys, input });
69
73
  } catch (err) {
70
74
  throw new LesgoException(
71
75
  'Failed to scan redis cache',
@@ -78,6 +82,6 @@ const scanRedisCache = (pattern, clientOpts) =>
78
82
  }
79
83
  );
80
84
  }
81
- return keys;
85
+ return allKeys;
82
86
  });
83
87
  export default scanRedisCache;
@@ -16,5 +16,5 @@ import { ClientOptions } from '../../../types/aws';
16
16
  *
17
17
  * await deleteCache(keys);
18
18
  */
19
- declare const deleteCache: (keys: string | string[], clientOpts?: ClientOptions) => Promise<number>;
19
+ declare const deleteCache: (keys: string | string[], clientOpts?: ClientOptions) => Promise<void>;
20
20
  export default deleteCache;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lesgo",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "Core framework for lesgo node.js serverless framework.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",