Reputation: 2910
Is there any way to Remove all Redis Client Connections with one command?
I know that it's possible to remove by IP:PORT
CLIENT KILL addr:port
Also I found that is possible to do this since Redis 2.8.12. But I couldn't find anything about.
Upvotes: 24
Views: 33449
Reputation: 10908
CLIENT KILL
can receive TYPE
argument that can be one of a three connection types; normal
, slave
and pubsub
.
You can kill all open connections by sending the following three commands:
CLIENT KILL TYPE normal
CLIENT KILL TYPE slave
CLIENT KILL TYPE pubsub
Note that you can skip the later two if you do not use them (slave and pubsub connections).
You can also add a SKIPME no
for a kamikaze connections killer.
Upvotes: 46
Reputation: 494
You can use the following command to check your connection numbers:
netstat -an | grep :6379 | grep ESTABLISHED | wc -l
Then try Redis Client command to kill connection: http://redis.io/commands/client-kill
Upvotes: 4
Reputation: 49942
So SHUTDOWN
is definitely the easiest way, especially in dev.
However, although Redis doesn't have a CLIENT KILL *
variant, you can script it. AFAIR you could even do it in Lua but I checked now and CLIENT LIST
errs so I'm guessing that's changed. Still, it is fairly easy to do this with the CLI - this appears to do the trick:
redis-cli CLIENT LIST | cut -d ' ' -f 2 | cut -d = -f 2 | awk -e '{ print "CLIENT KILL " $0 }' | redis-cli -x
Upvotes: 8