1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Use pipeline instead of eval

This commit is contained in:
Adria Navarro 2024-03-06 12:22:20 +01:00
parent edca6f6eca
commit 4baadadaa8

View file

@ -291,23 +291,16 @@ class RedisWrapper {
return acc
}, {} as Record<string, any>)
const luaScript = `
for i, key in ipairs(KEYS) do
redis.call('MSET', key, ARGV[i])
${
expirySeconds !== null
? `redis.call('EXPIRE', key, ARGV[#ARGV])`
: ""
}
end
`
const keys = Object.keys(dataToStore)
const values = Object.values(dataToStore)
const pipeline = client.pipeline()
pipeline.mset(dataToStore)
if (expirySeconds !== null) {
values.push(expirySeconds)
for (const key of Object.keys(dataToStore)) {
pipeline.expire(key, expirySeconds)
}
}
await client.eval(luaScript, keys.length, ...keys, ...values)
await pipeline.exec()
}
async getTTL(key: string) {