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 redis-py, this error is NoScriptError: 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 with SCRIPT LOAD, or run it once with EVAL. Then call EVALSHA again. Most client libraries can do this for you. For example, the script object that redis-py's register_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.

RATE THIS PAGE
Back to top ↑