Skip to content

The open alternative to Salesforce, designed for AI.

Gracefully close Redis connection when cacheStorageModule is destroyed (#4812)

Weikof8edb6652e5e
diff --git a/packages/twenty-server/src/engine/integrations/cache-storage/cache-storage.module.ts b/packages/twenty-server/src/engine/integrations/cache-storage/cache-storage.module.ts
index 581919555d9..b2af3906259 100644
--- a/packages/twenty-server/src/engine/integrations/cache-storage/cache-storage.module.ts
+++ b/packages/twenty-server/src/engine/integrations/cache-storage/cache-storage.module.ts
@@ -1,4 +1,4 @@
-import { Module, Global } from '@nestjs/common';
+import { Module, Global, Inject, OnModuleDestroy } from '@nestjs/common';
import { CacheModule, CACHE_MANAGER, Cache } from '@nestjs/cache-manager';
import { ConfigModule } from '@nestjs/config';
@@ -28,4 +28,12 @@ import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/typ
],
exports: [...Object.values(CacheStorageNamespace)],
})
-export class CacheStorageModule {}
+export class CacheStorageModule implements OnModuleDestroy {
+ constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}
+
+ async onModuleDestroy() {
+ if ((this.cacheManager.store as any)?.name === 'redis') {
+ await (this.cacheManager.store as any).client.quit();
+ }
+ }
+}