From 367dd01cf14a99766bdccab98114504ce85812ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A0=95=ED=98=84?= Date: Tue, 4 Nov 2025 10:58:20 +0900 Subject: [PATCH] refac: clear method --- src/RedisCacheAdapter.ts | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/RedisCacheAdapter.ts b/src/RedisCacheAdapter.ts index b7b8850..a72a304 100644 --- a/src/RedisCacheAdapter.ts +++ b/src/RedisCacheAdapter.ts @@ -152,29 +152,22 @@ export class RedisCacheAdapter implements CacheAdapter { async clear(): Promise { this.logDebugMessage("Clearing cache..."); - return new Promise((resolve, reject) => { - const stream = this.client.scanStream({ - match: `${this.keyPrefix}:*`, - }); - const pipeline = this.client.pipeline(); - stream.on("data", (keys: string[]) => { - if (keys.length) { - keys.forEach(function (key) { - pipeline.del(key); - }); - } - }); - stream.on("end", () => { - pipeline.exec((err) => { - if (err) { - this.logDebugMessage("Error clearing cache"); - return reject(err); - } - this.logDebugMessage("Cleared cache"); - resolve(); - }); - }); + + const stream = this.client.scanStream({ + match: `${this.keyPrefix}:*`, + count: 100, }); + + for await (const keys of stream as AsyncIterable) { + if (!keys?.length) continue; + + const pipeline = this.client.pipeline(); + for (const key of keys) { + pipeline.del(key); + } + + await pipeline.exec(); + } } async close() {