Overview - EVALSHA for cached scripts
What is it?
EVALSHA is a Redis command that runs a Lua script already stored in Redis by referencing its unique SHA1 hash. Instead of sending the whole script every time, you send just the hash, which makes execution faster. This helps Redis reuse scripts efficiently without resending the script code repeatedly. It is mainly used to improve performance when running the same script multiple times.
Why it matters
Without EVALSHA, every time you want to run a Lua script in Redis, you must send the entire script text, which wastes network bandwidth and slows down execution. EVALSHA solves this by caching the script on the server and running it by its hash, making repeated script calls much faster and reducing network load. This is crucial for high-performance applications that rely on Redis scripting for atomic operations.
Where it fits
Before learning EVALSHA, you should understand basic Redis commands and how Lua scripting works with Redis using the EVAL command. After mastering EVALSHA, you can explore advanced Redis scripting patterns, script caching strategies, and error handling for missing scripts.