How to fix the “Redis is busy running a script” error

redis

My servers are repeatedly crashing due to receiving the following error from Redis:

BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.

However, I can't seem to find a way to determine what is this "script" the message is referring to, and how I may terminate the script. Any help would be appreciated.

Best Answer

The error means that there's a long-running server-side Lua script. Such a script is invoked by the EVAL or the EVALSHA Redis commands. "Long-running" means that the script's execution time had exceeded the threshold defined by the lua-time-limit configuration directive (5000ms by default).

Because Redis is single-threaded, it responds with the "-BUSY" error after the timeout to indicate that it is still, well, busy. You can either wait for the script's execution to end or (if you've got an infinite loop for example) issue one of the commands suggested by the error to attempt to stop the script.

SCRIPT KILL will succeed only if the script performed no write operations. In case writes were made by the script, the only way to stop it is by shutting down the server without saving the changes via SHUTDOWN NOSAVE.