fix(CQ-API-4): Remove Redis event listeners in onModuleDestroy

Add removeAllListeners() call before quit() to prevent memory leaks
from lingering event listeners on the Redis client.

Also update test mock to include removeAllListeners method.

Refs #339

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-05 19:16:37 -06:00
parent e891449e0f
commit 22446acd8a
2 changed files with 7 additions and 1 deletions

View File

@@ -24,6 +24,10 @@ vi.mock("ioredis", () => {
return this;
}
removeAllListeners() {
return this;
}
// String operations
async setex(key: string, ttl: number, value: string) {
store.set(key, value);

View File

@@ -63,8 +63,10 @@ export class ValkeyService implements OnModuleInit, OnModuleDestroy {
}
}
async onModuleDestroy() {
async onModuleDestroy(): Promise<void> {
this.logger.log("Disconnecting from Valkey");
// Remove all event listeners to prevent memory leaks
this.client.removeAllListeners();
await this.client.quit();
}