feat(providers): locking redis (#9544)

This commit is contained in:
Carlos R. L. Rodrigues
2024-10-15 12:40:24 -03:00
committed by GitHub
parent e77a2ff032
commit 4a03bdbb86
49 changed files with 1764 additions and 483 deletions

View File

@@ -76,14 +76,28 @@ class RedisCacheService implements ICacheService {
* @param key
*/
async invalidate(key: string): Promise<void> {
const keys = await this.redis.keys(this.getCacheKey(key))
const pipeline = this.redis.pipeline()
const pattern = this.getCacheKey(key)
let cursor = "0"
do {
const result = await this.redis.scan(
cursor,
"MATCH",
pattern,
"COUNT",
100
)
cursor = result[0]
const keys = result[1]
keys.forEach(function (key) {
pipeline.del(key)
})
if (keys.length > 0) {
const deletePipeline = this.redis.pipeline()
for (const key of keys) {
deletePipeline.del(key)
}
await pipeline.exec()
await deletePipeline.exec()
}
} while (cursor !== "0")
}
/**