node-redis
node-redis copied to clipboard
Scripts execution always uses EVAL with multi.
The implementation of the multi script execution seems to check a local map https://github.com/redis/node-redis/blob/b97d18b61071b2d615c4606ee6b5930854b9e4e4/packages/client/lib/multi-command.ts#L16 for whether to use the EVAL or EVALSHA for script execution. However, multi is always re-initiated for every transaction or pipeline execution, thus this means the script executed in the multi always end up with a EVAL with the full script uploaded over and over again. In v3, I used to run "SCRIPT LOAD" for all scripts and then all subsequent commands would use evalsha. And if evalsha fails with NOSCRIPT, then the script is reloaded to redis again. I think redis v4 can implement similar approach and only need to handle the corner case of NOSCRIPT when it arises.
Node.js Version: v16.14.2 Redis Server Version: 6.2.5 Node Redis Version: [email protected] Platform: Debian bullseye
In ioredis I've solved this by caching script load information using a weakmap against the socket: https://github.com/redis/ioredis/blob/ec42c82ceab1957db00c5175dfe37348f1856a93/lib/Script.ts#L29-L36
Whenever a custom script command gets execute, it uses either eval
or evalsha
.