BUSY error
A Lua script or function has run for too long, and Redis is blocked until it ends.
Redis returns this error when a Lua script or function has run for longer than the busy-reply-threshold setting, which is 5 seconds by default. While a script runs, Redis doesn't run any other command. So instead of making other clients wait, Redis answers almost every command with this error, even PING.
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
For a function, the message names FUNCTION KILL instead of SCRIPT KILL. A module command that runs for a long time causes a similar error: BUSY Redis is busy running a module command.
In client libraries
| Client library | Exception or error type | Message |
|---|---|---|
| redis-py | ResponseError |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| Jedis | JedisBusyException |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| node-redis | SimpleErrorTest with err.message.startsWith('BUSY') |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| Lettuce The async API wraps the exception in an ExecutionException (get()) or a CompletionException (join()). |
RedisBusyException |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| go-redis | redis.ErrorTest with redis.HasErrorPrefix(err, "BUSY") |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| ioredis | ReplyErrorTest with err.message.startsWith('BUSY') |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| StackExchange.Redis NRedisStack uses StackExchange.Redis, so it raises the same exceptions. The sync and async APIs raise the same exceptions. |
RedisConnectionException |
It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.StackExchange.Redis sends commands when it connects, and the server refused them while a script ran, so a new connection fails. |
| Predis | Predis\Response\ServerExceptionTest with $e->getErrorType() === 'BUSY' |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
| redis-rb | Redis::CommandError |
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. (redis://<host>:<port>) |
| redis-rs The sync and async APIs raise the same errors. |
ErrorKind::ExtensionTest with err.code() == Some("BUSY") |
"BUSY": Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. |
Example
While another client runs a script that never ends:
> GET mykey
(error) BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
> SCRIPT KILL
OK
How to fix it
-
Stop the script with
SCRIPT KILL, or stop a function withFUNCTION KILL. The client that ran the script then gets an error that starts withERR Script killed by user with SCRIPT KILL. -
If the script has already changed data, Redis can't stop it, because that would leave the change half done.
SCRIPT KILLthen fails: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.You can either wait for the script to finish, or stop the server with
SHUTDOWN NOSAVE.SHUTDOWN NOSAVEloses all changes that weren't saved to disk. -
Change the script so that it can't run this long. Common causes are a loop that never ends, and a script that processes too many keys or elements in one call. Split large jobs into several smaller calls.