Skip to content

Commit 5750e0d

Browse files
Boris Dorofeevnodkz
authored andcommitted
refactor: pipeline for keys del
1 parent 4ff97d7 commit 5750e0d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/helpers/deleteKeys.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ export async function deleteQueue(
2222

2323
const total = await new Promise<number>((resolve, reject) => {
2424
//redis-cli: scan 0 match fullName* count 300
25-
const stream = connection.scanStream({ match: fullName + '*', count: 300 });
25+
const stream = connection.scanStream({ match: fullName + '*', count: 1000 });
2626

2727
let total = 0;
2828

29+
let pipeline = connection.pipeline();
30+
2931
stream.on('data', async (keys) => {
3032
for (let i = 0; i < keys.length; i++) {
31-
const del = await connection.del(keys[i]);
33+
const del = pipeline.del(keys[i]);
3234
if (del) {
3335
total++;
3436
}
3537
}
38+
39+
await pipeline.exec();
40+
pipeline = connection.pipeline();
3641
});
3742

3843
stream.on('end', () => {

0 commit comments

Comments
 (0)