NOSCRIPT error
EVALSHA asked for a script that isn't in the server's script cache.
Redis returns this error when you run a Lua script with EVALSHA, but the server doesn't have the script in its script cache. EVALSHA runs a script by its SHA1 (Secure Hash Algorithm 1) digest, a short code calculated from the script's source. The server only knows the digest of a script that it has already loaded.
NOSCRIPT No matching script. Please use EVAL.
In client libraries
| Client library | Exception or error type | Message |
|---|---|---|
| redis-py | NoScriptError |
No matching script. Please use EVAL. |
| Jedis | JedisNoScriptException |
NOSCRIPT No matching script. Please use EVAL. |
| node-redis | SimpleErrorTest with err.message.startsWith('NOSCRIPT') |
NOSCRIPT No matching script. Please use EVAL. |
| Lettuce The async API wraps the exception in an ExecutionException (get()) or a CompletionException (join()). |
RedisNoScriptException |
NOSCRIPT No matching script. Please use EVAL. |
| go-redis | redis.ErrorTest with errors.Is(err, redis.ErrNoScript) |
NOSCRIPT No matching script. Please use EVAL. |
| ioredis | ReplyErrorTest with err.message.startsWith('NOSCRIPT') |
NOSCRIPT No matching script. Please use EVAL. |
| StackExchange.Redis NRedisStack uses StackExchange.Redis, so it raises the same exceptions. The sync and async APIs raise the same exceptions. |
RedisServerException |
NOSCRIPT No matching script. Please use EVAL. |
| Predis | Predis\Response\ServerExceptionTest with $e->getErrorType() === 'NOSCRIPT' |
NOSCRIPT No matching script. Please use EVAL. |
| redis-rb | Redis::NoScriptError |
NOSCRIPT No matching script. Please use EVAL. (redis://<host>:<port>) |
| redis-rs The sync and async APIs raise the same errors. |
ErrorKind::Server(ServerErrorKind::NoScript) |
NoScript: No matching script. Please use EVAL. |
Example
> EVALSHA ffffffffffffffffffffffffffffffffffffffff 0
(error) NOSCRIPT No matching script. Please use EVAL.
How to fix it
The script cache isn't saved with your data. It's emptied when the server restarts, when a replica becomes the primary, and when someone runs SCRIPT FLUSH. So your code must expect this error at any time:
- Handle the error in your code. When you get
NOSCRIPT, load the script withSCRIPT LOAD, or run it once withEVAL. Then callEVALSHAagain. Most client libraries can do this for you. For example, the script object that redis-py'sregister_script()returns loads the script again when it gets this error. - Use functions instead. Functions are saved and replicated with your data, so they're still there after a restart or a failover.
See Script cache.