Use pipeline to count event stream (#17450)
As title. So we only send one TCP call per batch
This commit is contained in:
+13
-4
@@ -227,11 +227,20 @@ export class CacheStorageService {
|
||||
const keys = result.keys;
|
||||
|
||||
if (keys.length > 0) {
|
||||
const counts = await Promise.all(
|
||||
keys.map((key) => redisClient.sCard(key)),
|
||||
);
|
||||
const pipeline = redisClient.multi();
|
||||
|
||||
totalCount += counts.reduce((sum, count) => sum + count, 0);
|
||||
for (const key of keys) {
|
||||
pipeline.sCard(key);
|
||||
}
|
||||
|
||||
const results = await pipeline.exec();
|
||||
|
||||
for (const result of results) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
totalCount += result as number;
|
||||
}
|
||||
}
|
||||
} while (cursor !== 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user