fixes for redis event memory leak

This commit is contained in:
Boki 2025-06-10 15:17:47 -04:00
parent 9825e99540
commit fdb8823df7
2 changed files with 39 additions and 14 deletions

View file

@ -42,7 +42,13 @@ export class RedisCache implements CacheProvider {
singleton: options.shared ?? true, // Default to shared connection for cache
});
this.setupEventHandlers();
// Only setup event handlers for non-shared connections to avoid memory leaks
if (!(options.shared ?? true)) {
this.setupEventHandlers();
} else {
// For shared connections, just monitor the connection status without adding handlers
this.isConnected = this.redis.status === 'ready';
}
}
private setupEventHandlers(): void {
@ -235,6 +241,14 @@ export class RedisCache implements CacheProvider {
}
isReady(): boolean {
return this.redis.status === 'ready';
// Always check the actual Redis connection status
const ready = this.redis.status === 'ready';
// Update local flag if we're not using shared connection
if (this.isConnected !== ready) {
this.isConnected = ready;
}
return ready;
}
}