DBAtlas · Database operations atlas

ERR Lua script attempted to access nonexistent global variable: Lua script attempted to access a nonexistent global variable

Redis

What 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.

Open in DBAtlas →

More from this engine