@trieb.work/nextjs-turbo-redis-cache 1.8.0-beta.4 → 1.8.0-beta.6

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/src/SyncedMap.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  // SyncedMap.ts
2
- import {
3
- Client,
4
- getTimeoutRedisCommandOptions,
5
- redisErrorHandler,
6
- } from './RedisStringsHandler';
2
+ import { Client, redisErrorHandler } from './RedisStringsHandler';
7
3
  import { debugVerbose, debug } from './utils/debug';
8
4
 
9
5
  type CustomizedSync = {
@@ -16,7 +12,6 @@ type SyncedMapOptions = {
16
12
  keyPrefix: string;
17
13
  redisKey: string; // Redis Hash key
18
14
  database: number;
19
- timeoutMs: number;
20
15
  querySize: number;
21
16
  filterKeys: (key: string) => boolean;
22
17
  resyncIntervalMs?: number;
@@ -39,7 +34,6 @@ export class SyncedMap<V> {
39
34
  private syncChannel: string;
40
35
  private redisKey: string;
41
36
  private database: number;
42
- private timeoutMs: number;
43
37
  private querySize: number;
44
38
  private filterKeys: (key: string) => boolean;
45
39
  private resyncIntervalMs?: number;
@@ -54,7 +48,6 @@ export class SyncedMap<V> {
54
48
  this.redisKey = options.redisKey;
55
49
  this.syncChannel = `${options.keyPrefix}${SYNC_CHANNEL_SUFFIX}${options.redisKey}`;
56
50
  this.database = options.database;
57
- this.timeoutMs = options.timeoutMs;
58
51
  this.querySize = options.querySize;
59
52
  this.filterKeys = options.filterKeys;
60
53
  this.resyncIntervalMs = options.resyncIntervalMs;
@@ -89,11 +82,22 @@ export class SyncedMap<V> {
89
82
 
90
83
  try {
91
84
  do {
92
- const remoteItems = await this.client.hScan(
93
- getTimeoutRedisCommandOptions(this.timeoutMs),
94
- this.keyPrefix + this.redisKey,
95
- cursor,
96
- hScanOptions,
85
+ const remoteItems = await redisErrorHandler(
86
+ 'SyncedMap.initialSync(), operation: hScan ' +
87
+ this.syncChannel +
88
+ ' ' +
89
+ this.keyPrefix +
90
+ ' ' +
91
+ this.redisKey +
92
+ ' ' +
93
+ cursor +
94
+ ' ' +
95
+ this.querySize,
96
+ this.client.hScan(
97
+ this.keyPrefix + this.redisKey,
98
+ cursor,
99
+ hScanOptions,
100
+ ),
97
101
  );
98
102
  for (const { field, value } of remoteItems.tuples) {
99
103
  if (this.filterKeys(field)) {
@@ -118,10 +122,10 @@ export class SyncedMap<V> {
118
122
  let remoteKeys: string[] = [];
119
123
  try {
120
124
  do {
121
- const remoteKeysPortion = await this.client.scan(
122
- getTimeoutRedisCommandOptions(this.timeoutMs),
123
- cursor,
124
- scanOptions,
125
+ const remoteKeysPortion = await redisErrorHandler(
126
+ 'SyncedMap.cleanupKeysNotInRedis(), operation: scan ' +
127
+ this.keyPrefix,
128
+ this.client.scan(cursor, scanOptions),
125
129
  );
126
130
  remoteKeys = remoteKeys.concat(remoteKeysPortion.keys);
127
131
  cursor = remoteKeysPortion.cursor;
@@ -306,20 +310,15 @@ export class SyncedMap<V> {
306
310
  return;
307
311
  }
308
312
  if (!this.customizedSync?.withoutRedisHashmap) {
309
- const options = getTimeoutRedisCommandOptions(this.timeoutMs);
310
313
  operations.push(
311
314
  redisErrorHandler(
312
315
  'SyncedMap.set(), operation: hSet ' +
313
316
  this.syncChannel +
314
317
  ' ' +
315
- this.timeoutMs +
316
- 'ms' +
317
- ' ' +
318
318
  this.keyPrefix +
319
319
  ' ' +
320
320
  key,
321
321
  this.client.hSet(
322
- options,
323
322
  this.keyPrefix + this.redisKey,
324
323
  key as unknown as string,
325
324
  JSON.stringify(value),
@@ -338,9 +337,6 @@ export class SyncedMap<V> {
338
337
  'SyncedMap.set(), operation: publish ' +
339
338
  this.syncChannel +
340
339
  ' ' +
341
- this.timeoutMs +
342
- 'ms' +
343
- ' ' +
344
340
  this.keyPrefix +
345
341
  ' ' +
346
342
  key,
@@ -369,21 +365,17 @@ export class SyncedMap<V> {
369
365
  }
370
366
 
371
367
  if (!this.customizedSync?.withoutRedisHashmap) {
372
- const options = getTimeoutRedisCommandOptions(this.timeoutMs * 10);
373
368
  operations.push(
374
369
  redisErrorHandler(
375
370
  'SyncedMap.delete(), operation: hDel ' +
376
371
  this.syncChannel +
377
372
  ' ' +
378
- this.timeoutMs +
379
- 'ms' +
380
- ' ' +
381
373
  this.keyPrefix +
382
374
  ' ' +
383
375
  this.redisKey +
384
376
  ' ' +
385
377
  keysArray,
386
- this.client.hDel(options, this.keyPrefix + this.redisKey, keysArray),
378
+ this.client.hDel(this.keyPrefix + this.redisKey, keysArray),
387
379
  ),
388
380
  );
389
381
  }
@@ -398,9 +390,6 @@ export class SyncedMap<V> {
398
390
  'SyncedMap.delete(), operation: publish ' +
399
391
  this.syncChannel +
400
392
  ' ' +
401
- this.timeoutMs +
402
- 'ms' +
403
- ' ' +
404
393
  this.keyPrefix +
405
394
  ' ' +
406
395
  keysArray,