ERR Lua script attempted to access nonexistent global variable: Lua script attempted to access a nonexistent global variable (Lua 스크립트가 존재하지 않는 전역 변수에 접근)
Redis의미
EVAL/EVALSHA로 실행한 Lua 스크립트가 정의되지 않은 전역 변수에 접근하려 했다. 스크립트 환경을 보호하기 위해 Redis는 전역 변수 생성/읽기를 제한하고 이런 접근을 오류로 반환한다.
원인
스크립트에서 실수로 지역 변수 대신 전역 변수를 사용했거나(local 키워드 누락), 오타로 정의되지 않은 이름에 접근했거나, 전역 변수에 상태를 유지하려 한 경우다. 샌드박스화된 Redis Lua 환경은 이를 허용하지 않는다.
해결 방법
스크립트의 모든 변수를 local로 선언한다: local x = ... 오타를 수정하고 모든 변수가 사용 전에 정의되었는지 확인한다. 스크립트는 상태가 없어야 하며, 영구 상태는 전역 Lua 변수가 아니라 Redis 키(KEYS/redis.call)를 사용한다. 스크립트를 짧고 결정적으로 유지한다.
같은 데이터베이스의 다른 항목
- NOPROTO unsupported protocol versionUnsupported RESP protocol version
- ERR Unknown option or number of arguments for CONFIG SETUnknown option or number of arguments for CONFIG SET (older versions: Unsupported CONFIG parameter) (CONFIG SET의 알 수 없는 옵션 또는 인수 개수 오류)
- ERR MULTI calls can not be nestedMULTI calls can not be nested
- ERR unknown commandUnknown command
- TRYAGAIN Multiple keys request during rehashing of slotMultiple keys request during rehashing of slot (cluster) (slot rehashing 중 다중 키 요청)
- ERR DISCARD without MULTIDISCARD without MULTI
- BUSYGROUP Consumer Group name already existsConsumer group already exists