EVALSHA
EVALSHA sha1 numkeys [key [key ...]] [arg [arg ...]]
- Group
- Scripting and functions
- Complexity
- Depends on the script
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- slow, write
- HotKV Cloud
- All plans
- On-Premise
- no license needed
EVALSHA runs a script that is already in the server’s script cache, named
by the SHA1 digest of its text (in hexadecimal, any case). It takes the same
numkeys, keys and arguments as EVAL and behaves the same
way, but saves sending the script body each time. Scripts enter the cache
through EVAL or SCRIPT LOAD.
The cache is not persistent: it is empty after a restart and after
SCRIPT FLUSH, and scripts added by EVAL can be
dropped when many different scripts are used. Clients usually call EVALSHA
first and fall back to EVAL when they get a NOSCRIPT error.
Return value
Section titled “Return value”The script’s return value, converted as described for EVAL.
| Case | RESP2 | RESP3 |
|---|---|---|
| The digest is not cached | Error NOSCRIPT No matching script. Please use EVAL. |
Error |
Examples
Section titled “Examples”127.0.0.1:6379> SCRIPT LOAD "return redis.call('GET', KEYS[1])""d3c21d0c2b9ca22f82737626a27bcaf5d288f99f"127.0.0.1:6379> SET greeting "hello"OK127.0.0.1:6379> EVALSHA d3c21d0c2b9ca22f82737626a27bcaf5d288f99f 1 greeting"hello"127.0.0.1:6379> EVALSHA 0000000000000000000000000000000000000000 0(error) NOSCRIPT No matching script. Please use EVAL.Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.