SCRIPT LOAD and EVALSHA
Load scripts with SCRIPT LOAD and execute by SHA1 for efficiency.
The Problem with EVAL
EVAL sends the full script text on every call. For frequently executed scripts this wastes bandwidth. SCRIPT LOAD + EVALSHA solve this by loading once and calling by SHA1 hash.
SCRIPT LOAD
SCRIPT LOAD script compiles the script, caches it in Redis, and returns its SHA1 hash. The script stays cached until the server restarts or SCRIPT FLUSH is called.
# Redis CLI:
SCRIPT LOAD "return redis.call('GET', KEYS[1])"
# Returns: "abc123...sha1hash..."All lessons in this course
- EVAL and Redis Lua Environment
- Atomic Operations and Transactions
- Rate Limiting with Lua
- SCRIPT LOAD and EVALSHA