ERR Lua script attempted to access nonexistent global variable: Lua script attempted to access a nonexistent global variable
RedisWhat does it mean?
A Lua script run with EVAL/EVALSHA tried to access an undefined global variable. To protect the scripting environment, Redis restricts creating/reading global variables and returns such access as an error.
Why does it happen?
Accidentally using a global instead of a local variable in the script (forgetting the local keyword); accessing an undefined name because of a typo; or trying to keep state in a global variable. The sandboxed Redis Lua environment does not allow these.
How to fix it
Declare all variables in the script with local: local x = ... Fix typos; make sure every variable is defined before use. Scripts should be stateless; for persistent state use Redis keys (KEYS/redis.call), not global Lua variables. Keep the script short and deterministic.
More from this engine
- 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)
- 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)
- ERR DISCARD without MULTIDISCARD without MULTI
- BUSYGROUP Consumer Group name already existsConsumer group already exists