修改本页
Redis

CLIENT KILL [ip:port] [ID client-id] [TYPE normal|slave|pubsub] [ADDR ip:port] [SKIPME yes/no]

The CLIENT KILL command closes a given client connection. Up to Redis 2.8.11 it was possible to close a connection only by client address, using the following form:

CLIENT KILL addr:port

The ip:port should match a line returned by the CLIENT LIST command (addr field).

However starting with Redis 2.8.12 or greater, the command accepts the following form:

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. The following filters are available:

It is possible to provide multiple filters at the same time. The command will ahdnle multiple filters via logical AND. For example:

CLIENT KILL addr 127.0.0.1:6379 type slave

is valid and will kill only a slaves with the specified address. This format containing multiple filters is rarely useful currently.

When the new form is used the command no longer returns OK or an error, but instead the number of killed clients, that may be zero.

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-treaded 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).

返回值

When called with the three arguments format:

Simple string reply: OK if the connection exists and has been closed

When called with the filter / value format:

Integer reply: the number of clients killed.

Comments powered by Disqus