소스 검색

fix(job-queue-plugin): Use SCAN instead of KEYS to clean indexed sets (#3743)

Colin Pieper 4 달 전
부모
커밋
1c9b00b105
1개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 15 1
      packages/job-queue-plugin/src/bullmq/job-list-index.service.ts

+ 15 - 1
packages/job-queue-plugin/src/bullmq/job-list-index.service.ts

@@ -240,7 +240,21 @@ export class JobListIndexService {
 
         // Get all queue names from our indexed sets
         const allStateKeys = this.createSortedSetKey('*');
-        const keys = await this.redis.keys(allStateKeys);
+        const keys: string[] = [];
+        let scanCursor = '0';
+
+        do {
+            const [nextCursor, foundKeys] = await this.redis.scan(
+                scanCursor,
+                'MATCH',
+                allStateKeys,
+                'COUNT',
+                this.BATCH_SIZE,
+            );
+            scanCursor = nextCursor;
+            keys.push(...foundKeys);
+        } while (scanCursor !== '0');
+
         const result: Array<{ queueName: string; jobsRemoved: number }> = [];
         const startTime = Date.now();
         Logger.verbose(`Cleaning up ${keys.length} indexed sets`, loggerCtx);