Add deleteIfValue

This commit is contained in:
Adria Navarro 2024-03-06 00:13:11 +01:00
parent 60f82610f6
commit 355dea5b05
1 changed files with 12 additions and 0 deletions

View File

@ -339,6 +339,18 @@ class RedisWrapper {
} }
return result return result
} }
async deleteIfValue(key: string, value: any) {
const client = this.getClient()
const luaScript = `
if redis.call('GET', KEYS[1]) == ARGV[1] then
redis.call('DEL', KEYS[1])
end
`
await client.eval(luaScript, 1, addDbPrefix(this._db, key), value)
}
} }
export default RedisWrapper export default RedisWrapper