CLIENT KILL
CLIENT KILL <ip:port | <[ID client-id] | [TYPE <NORMAL | MASTER | SLAVE | REPLICA | PUBSUB>] | [USER username] | [ADDR ip:port] | [LADDR ip:port] | [SKIPME <YES | NO>] | [MAXAGE maxage] [[ID client-id] | [TYPE <NORMAL | MASTER | SLAVE | REPLICA | PUBSUB>] | [USER username] | [ADDR ip:port] | [LADDR ip:port] | [SKIPME <YES | NO>] | [MAXAGE maxage] ...]>>
- Available since:
- Redis Open Source 2.4.0
- Time complexity:
- O(N) where N is the number of client connections
- ACL categories:
-
@admin,@slow,@dangerous,@connection, - Compatibility:
- Redis Software and Redis Cloud compatibility
The CLIENT KILL command closes a given client connection. This command support two formats, the old format:
CLIENT KILL addr:port
The ip:port should match a line returned by the CLIENT LIST command (addr field).
The new format:
CLIENT KILL <filter> <value> ... ... <filter> <value>
With the new form it is possible to kill clients by different attributes instead of killing just by address. See below for the list of supported filters.
It is possible to provide multiple filters at the same time. Multiple filters are combined using logical AND.
CLIENT KILL addr 127.0.0.1:12345 type pubsub
is valid and will kill only a pubsub client with the specified address.
When the new form is used the command no longer returns OK or an error, but instead the number of killed clients, which may be zero.
Optional arguments
Provide the legacy ip:port argument to close a client by address, or one or more of the following filters, which can be combined to select the clients to close.
ip:port
Close the client at the given address. This is the legacy single-argument form.
ID client-id
Close only the client with the given unique ID.
TYPE NORMAL | MASTER | SLAVE | REPLICA | PUBSUB
Close only clients of the given type.
USER username
Close only clients authenticated as the given ACL user.
ADDR ip:port
Close only clients connected from the given address.
LADDR ip:port
Close only clients connected to the given local (server) address.
SKIPME YES | NO
Whether to skip the calling client (YES, the default) or allow it to be closed too (NO).
MAXAGE maxage
Close only clients older than the given age, in seconds.
Details
CLIENT KILL and Redis Sentinel
Recent versions of Redis Sentinel (Redis 2.8.12 or greater) use CLIENT KILL in order to kill clients when an instance is reconfigured, in order to force clients to perform the handshake with one Sentinel again and update its configuration.
Notes
Due to the single-threaded nature of Redis, it is not possible to kill a client connection while it is executing a command. From the client point of view, the connection can never be closed in the middle of the execution of a command. However, the client will notice the connection has been closed only when the next command is sent (and results in network error).
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
One of the following:
- Simple string reply:
OKwhen called in 3 argument format and the connection has been closed. - Integer reply: when called in filter/value format, the number of clients killed.
History
- Starting with Redis version 2.8.12: Added new filter format.
- Starting with Redis version 2.8.12:
IDoption. - Starting with Redis version 3.2.0: Added
mastertype in forTYPEoption. - Starting with Redis version 5.0.0: Replaced
slaveTYPEwithreplica.slavestill supported for backward compatibility. - Starting with Redis version 6.2.0:
LADDRoption. - Starting with Redis version 7.4.0:
MAXAGEoption.