Use pipeline to count event stream (#17450)

As title. So we only send one TCP call per batch
This commit is contained in:
Thomas Trompette
2026-01-26 19:03:59 +01:00
committed by GitHub
parent ae1151cf5d
commit 570f83ea76
@@ -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);