BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. This error means a Lua script (EVAL/EVALSHA) or a Redis Function (FCALL) has been running longer than busy-reply-threshold, 5 seconds by default. The script is still running. Redis has simply started rejecting other clients' commands. What you can do next depends on one question: has the script already written anything?
127.0.0.1:6379> GET session:42
(error) BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
-- with Redis Functions (FCALL) the hint names FUNCTION KILL instead
(error) BUSY Redis is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE.
Why Redis stops answering
Redis runs a script atomically. The scripting documentation says that while a script executes, all server activities are blocked for its entire runtime. A script that runs for a millisecond is invisible. A script that loops over a million keys freezes the whole instance for every client.
The threshold does not stop the script. According to the comments in redis.conf, once the maximum execution time is reached Redis starts to reply to most commands with a BUSY error and allows only a handful of commands, such as SCRIPT KILL, FUNCTION KILL and SHUTDOWN NOSAVE. The setting used to be called lua-time-limit; since Redis 7.0 it is busy-reply-threshold, and the old name still works as an alias. Setting it to 0 or a negative value disables the mechanism, so clients simply wait with no way to interrupt the script. Do not do that in production.
127.0.0.1:6379> CONFIG GET busy-reply-threshold
1) "busy-reply-threshold"
2) "5000"
What to do right now
- Find out what is running. For functions,
FUNCTION STATSis allowed during BUSY and the documentation says it returns the function name, the command it was called with andduration_ms.
For127.0.0.1:6379> FUNCTION STATS -- shortened; the running_script part contains: -- name the function name, e.g. cleanup_expired -- command e.g. FCALL cleanup_expired 0 -- duration_ms how long it has been runningEVALscripts there is no such command, so check the application side: what was deployed, which job started, what calls EVAL. - Try to kill it. Use
SCRIPT KILLforEVALscripts andFUNCTION KILLfor functions. Each refuses the other kind. The SCRIPT KILL documentation explains that it only works if the script has not yet performed a write. The client that ran the script gets an error, and the rest of Redis returns to normal.127.0.0.1:6379> SCRIPT KILL OK -- the script already wrote something: 127.0.0.1:6379> SCRIPT KILL (error) UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command. - If the answer is UNKILLABLE, choose between waiting and a hard stop. A script that already wrote cannot be stopped halfway without breaking atomicity. Your options are to wait until it finishes, or to run
SHUTDOWN NOSAVE, which kills the process without saving so that half-written data is never persisted. After a restart Redis loads whatever RDB snapshot or AOF it has; with RDB only, everything written since the last snapshot is lost. On a primary with replicas, a failover to a replica is usually the better "hard stop".
Replicas are not stuck. Since Redis 7.0 scripts are replicated only by their effects: the documentation says replicas run the write commands without executing the script, and the commands are sent as one MULTI/EXEC block once the script finishes. A long script on the primary does not freeze replicas, which is why failing over to one is a real option.
What Sentinel does
If you run Sentinel, the Sentinel documentation describes the behaviour: when the master returns BUSY, Sentinel tries SCRIPT KILL before triggering a failover. That only succeeds if the script was read-only. If the instance is still in an error state after this try, it will eventually be failed over. So a write-heavy runaway script can cause a failover once it has been BUSY for longer than down-after-milliseconds. That is usually what you want, but check your Sentinel setup so the timeout and quorum match your expectations.
Valkey
Valkey has the same mechanism, the same busy-reply-threshold setting with the lua-time-limit alias and the same 5000 ms default. The message names the server it runs on: Valkey 9.0 replies BUSY Valkey is busy running a script unless extended-redis-compatibility is enabled, which valkey.conf describes as a temporary option added in 8.0 that makes Valkey pretend to be Redis. If your alerting greps for the exact text "Redis is busy", update it after a migration.
On large production instances
On a test instance with a few thousand keys, every script finishes in milliseconds. The same script on tens of millions of keys is what produces BUSY, so plan for scale:
- Never iterate the keyspace inside a script.
KEYS,SMEMBERSorHGETALLon a big key, or a loop over a big list, inside one script is the most common cause. In our experience, moving the loop to the client and doing small batches per call solves it:-- bad: one call walks the whole keyspace -- EVAL "for _,k in ipairs(redis.call('KEYS','tmp:*')) do redis.call('DEL',k) end" 0 -- better: the client drives SCAN and deletes a small batch per round trip redis-cli --scan --pattern 'tmp:*' | xargs -r -n 500 redis-cli UNLINK - Keep every script bounded. Pass a maximum count as an argument, process at most that many items and return a cursor so the client can call it again.
- Watch slow scripts before they hit the threshold. A script that takes 200 ms today will take several seconds when the data grows.
SLOWLOGrecordsEVAL/FCALLcalls that exceedslowlog-log-slower-than; our guide to Redis latency spikes and SLOWLOG shows how to read it. - Expect a burst after a long writing script. Its effects reach replicas and the AOF as one MULTI/EXEC block, so a script that wrote a lot sends a large chunk to replicas when it ends.
- Clients time out before BUSY. In our experience, client libraries with a 1 to 2 second command timeout start failing, retrying and opening new connections long before the 5 second BUSY threshold. A frozen Redis can then face a connection storm when it recovers. Set retry limits and backoff.
- Prefer read-only scripts where possible. A script that only reads can always be killed. In Redis 7.0+, declaring
#!lua flags=no-writesmakes that explicit.
Key takeaways
- BUSY means a script or function has exceeded
busy-reply-threshold(5000 ms by default) and is still running. SCRIPT KILL(EVAL) orFUNCTION KILL(FCALL) work only if the script has not written yet.- If it has written, wait, or stop it hard with
SHUTDOWN NOSAVEor a failover to a replica. - Sentinel tries SCRIPT KILL first, then fails over if the master stays down.
- Keep scripts bounded and move keyspace loops to the client; that is what holds up on big datasets.