Skip to content

Commit

Permalink
perf(redis): clear while scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 28, 2024
1 parent b1e246d commit 62bd15d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/redis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ class KeyvRedis {
async clear (namespace) {
const match = namespace ? `${namespace}:*` : '*'
const stream = this.redis.scanStream({ match })
const keys = []
const collectKeys = new Transform({
const unlinkKeys = new Transform({
objectMode: true,
transform (chunk, _, next) {
keys.push.apply(keys, chunk)
next()
}
transform: (chunk, _, next) => this.redis.unlink(chunk).then(next)
})
await pipeline(stream, collectKeys)
if (keys.length > 0) await this.redis.unlink(keys)
await promisify(pipeline)(stream, unlinkKeys)
}

async * iterator (namespace) {
Expand Down

0 comments on commit 62bd15d

Please sign in to comment.