# EVALSHA

> Run a cached Lua script by its SHA1 digest.

URL: https://docs.hotkv.com/commands/evalsha/

```
EVALSHA sha1 numkeys [key [key ...]] [arg [arg ...]]
```

- Group: Scripting and functions
- Complexity: Depends on the script
- 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](https://docs.hotkv.com/commands/eval/index.md) and behaves the same
way, but saves sending the script body each time. Scripts enter the cache
through [EVAL](https://docs.hotkv.com/commands/eval/index.md) or [SCRIPT LOAD](https://docs.hotkv.com/commands/script-load/index.md).

The cache is not persistent: it is empty after a restart and after
[SCRIPT FLUSH](https://docs.hotkv.com/commands/script-flush/index.md), 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

The script's return value, converted as described for
[EVAL](https://docs.hotkv.com/commands/eval/index.md).

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The digest is not cached | Error `NOSCRIPT No matching script. Please use EVAL.` | Error |

## Examples

```
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.
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[EVAL](https://docs.hotkv.com/commands/eval/index.md), [EVALSHA_RO](https://docs.hotkv.com/commands/evalsha_ro/index.md),
[SCRIPT LOAD](https://docs.hotkv.com/commands/script-load/index.md),
[SCRIPT EXISTS](https://docs.hotkv.com/commands/script-exists/index.md)