-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should lua script be reloaded into cache on NOSCRIPT failure? #1438
Comments
In the pipeline code scripts are handled differently. They get loaded once and not retried unless a client side interval expires: https://github.com/luin/ioredis/blob/master/lib/pipeline.ts#L376 How do you call the script exactly? The following workaround will work if const redis = new Redis({
maxScriptsCachingTime: 3600
})
redis.on('reconnecting', () => {
redisClient._addedScriptHashes = {}
log.debug({instance}, `Redis connection reconnecting`)
}) I guess we can just put that logic into the connect function: https://github.com/luin/ioredis/blob/b8177479c348aa4bbd467fa944d61fe9b35aec19/lib/redis/index.ts#L304-L322 // Make sure only one timer is active at a time
clearInterval(this._addedScriptHashesCleanInterval);
+ this._addedScriptHashes = {}; |
Fixed in #1499 |
Some more improvements landed on |
https://github.com/luin/ioredis/blob/62b6a648910eccc3d83a3acd2db873704fd2080a/lib/script.ts#L35-L51
When a Lua script is loaded using defineCommand(), ioredis will load the script into cache memory, and attempt to reference it using the SHA.
If the redis cluster is restarted or otherwise flushes the script cache, calling the custom script will first attempt to do an EVALSHA, then upon receiving a NOSCRIPT error, will call EVAL with the lua code stored in app memory.
Unless the application adds logic to reload the script, each subsequent call will always do 2 operations: a failed EVALSHA followed by an EVAL. This will obviously affect performance.
Instead of doing EVALSHA followed by EVAL each time the missing script is called, could ioredis instead handle NOSCRIPT errors by reloading the lua script into the redis script cache? That way, subsequent calls will be successful when trying the initial EVALSHA
The text was updated successfully, but these errors were encountered: