Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

EVALSHA

Last updated
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.

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
127.0.0.1:6379> SCRIPT LOAD "return redis.call('GET', KEYS[1])"
"d3c21d0c2b9ca22f82737626a27bcaf5d288f99f"
127.0.0.1:6379> SET greeting "hello"
OK
127.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.

Same as Redis 7 and Valkey 8.

EVAL, EVALSHA_RO, SCRIPT LOAD, SCRIPT EXISTS