Use pipeline instead of eval
This commit is contained in:
parent
edca6f6eca
commit
4baadadaa8
|
@ -291,23 +291,16 @@ class RedisWrapper {
|
||||||
return acc
|
return acc
|
||||||
}, {} as Record<string, any>)
|
}, {} as Record<string, any>)
|
||||||
|
|
||||||
const luaScript = `
|
const pipeline = client.pipeline()
|
||||||
for i, key in ipairs(KEYS) do
|
pipeline.mset(dataToStore)
|
||||||
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)
|
|
||||||
if (expirySeconds !== null) {
|
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) {
|
async getTTL(key: string) {
|
||||||
|
|
Loading…
Reference in New Issue