feat(providers): locking redis (#9544)
This commit is contained in:
committed by
GitHub
parent
e77a2ff032
commit
4a03bdbb86
@@ -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")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user