NOSCRIPT: Script SHA1 is not cached
EVALSHA named a script digest the server has not cached since its last restart or SCRIPT FLUSH, so the script must be sent again with EVAL.
- Error prefix
NOSCRIPT
의미
Lua scripts are usually run through EVALSHA <sha1>, which saves sending the whole script on every call. The sha1 is a key into a server-side cache: if the server has never seen the script, or has lost it through a restart, a SCRIPT FLUSH or a failover to a replica that was never sent it, the server refuses with NOSCRIPT instead of guessing. The digest is matched case-insensitively, so one wrong character lands here too.
The standard client pattern is the fallback: try EVALSHA, catch NOSCRIPT, send the full script once with EVAL, then return to EVALSHA. Drivers that support Lua do this transparently; hand-rolled RESP clients have to implement it themselves.
일반적인 원인
- The server restarted or failed over after the script was loaded, clearing the in-memory script cache.
- SCRIPT FLUSH ran, often from an admin script or a test harness sharing the instance.
- The digest passed to EVALSHA was computed over different text than the script that was loaded.
- A fresh node in a cluster received the EVALSHA before it was ever sent the EVAL.
Find the cause
SCRIPT EXISTS <sha1> # 0: not loaded on this server right now INFO server | grep uptime_in_seconds # A recent restart clears the cache; there is no command to list cached scripts, # so test specific digests with SCRIPT EXISTS
해결 방법
-
Send the script once with EVAL, or load it and keep the digest it returns:
SCRIPT LOAD "return redis.call('GET', KEYS[1])" # Returns the sha1 hex string to pass to EVALSHA -
Check whether a digest is actually cached before calling it:
SCRIPT EXISTS <sha1-from-your-logs> # 1 means cached; 0 means expect NOSCRIPT
-
Implement the EVALSHA to NOSCRIPT to EVAL fallback in the client, or use a driver that does it for you.
Other ways to handle it
Redis Functions (Redis 7+) register server-side libraries by name and survive failover in cluster mode, removing most EVALSHA misses; call them with FCALL. For hot paths, load scripts at startup and after every reconnect instead of lazily on first use.
안전하게 재현하세요
redis-cli EVALSHA 0123456789012345678901234567890123456789 1 mykey # (error) NOSCRIPT No matching script. Please use EVAL. redis-cli SCRIPT LOAD "return 1" # a sha1 hex string comes back redis-cli EVALSHA <that-sha1> 0 # (integer) 1
질문
Does SCRIPT LOAD survive forever?
No. The cache lives in memory: restarts, SCRIPT FLUSH and failover clear it. Clients must be ready to re-send the script.
Why does Redis not just return an empty result?
Refusing loudly stops a client from treating a missing script as an empty result, which would look like silent data loss.
관련 오류
BUSYServer is blocked by a long scriptEXECABORTTransaction discarded after an error1305MySQL: 함수 또는 프로시저가 존재하지 않음
More data types and commands errors
WRONGTYPEThe key holds a different data typeERR unknown commandRedis does not know this commandERR wrong number of argumentsArgument count is wrongERR invalid expire timeExpire value is out of range
코드와 메시지 텍스트의 출처는 다음과 같습니다 Redis documentation and source code. 전체 목록은 Redis error list 또는 모든 데이터베이스 오류 검색.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
이 페이지의 텍스트와 데이터: CC BY 4.0, 출처: SQLly (sqlly.app). 코드와 SQL 스니펫: MIT. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.