Skip to content

Commit 92508b6

Browse files
committed
fix: improve logs
1 parent 5a9c2c4 commit 92508b6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/RedisStringsHandler.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,32 @@ export function redisErrorHandler<T extends Promise<unknown>>(
1717
debugInfo: string,
1818
redisCommandResult: T,
1919
): T {
20+
const beforeTimestamp = performance.now();
2021
return redisCommandResult.catch((error) => {
21-
console.error('Redis command error', debugInfo, error);
22+
console.error(
23+
'Redis command error',
24+
(performance.now() - beforeTimestamp).toFixed(2),
25+
'ms',
26+
debugInfo,
27+
error,
28+
);
2229
throw error;
2330
}) as T;
2431
}
2532

33+
// This is a test to check if the event loop is lagging. Increase CPU
34+
setInterval(() => {
35+
const start = performance.now();
36+
setImmediate(() => {
37+
const duration = performance.now() - start;
38+
if (duration > 100) {
39+
console.warn(
40+
`RedisStringsHandler detected an event loop lag of: ${duration.toFixed(2)}ms`,
41+
);
42+
}
43+
});
44+
}, 1000);
45+
2646
export type CreateRedisStringsHandlerOptions = {
2747
/** Redis redisUrl to use.
2848
* @default process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST

src/SyncedMap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export class SyncedMap<V> {
369369
}
370370

371371
if (!this.customizedSync?.withoutRedisHashmap) {
372-
const options = getTimeoutRedisCommandOptions(this.timeoutMs);
372+
const options = getTimeoutRedisCommandOptions(this.timeoutMs * 10);
373373
operations.push(
374374
redisErrorHandler(
375375
'SyncedMap.delete(), operation: hDel ' +
@@ -380,6 +380,8 @@ export class SyncedMap<V> {
380380
' ' +
381381
this.keyPrefix +
382382
' ' +
383+
this.redisKey +
384+
' ' +
383385
keysArray,
384386
this.client.hDel(options, this.keyPrefix + this.redisKey, keysArray),
385387
),

0 commit comments

Comments
 (0)