Redis

How to Use the Redis Client Kill Command

In some cases, you may need to terminate all the connections to a database. For example, you do not need clients connected to the database server when performing upgrades and maintenance.

In Redis, we can terminate a client connection using the client command. Let us learn how to accomplish this.

Redis Client Kill

In Redis, the CLIENT KILL command terminates the specified client connection. The syntax is provided below:

CLIENT KILL address:port

The format should be in hostname:port.

Redis List Clients

Before terminating the clients connected to the Redis cluster, it is good to know the connected clients and whether it’s good to close them or not.

To show all the connections to the Redis instance, use the client list command as follows:

127.0.0.1:6379> client list

The previous command should return a list of all the connections to the Redis server. An example output is provided below:

Note that each connection has a corresponding IP address and port. Therefore, to terminate a connection, you must specify the IP address and the port to which they are connected.

Redis Close Connection

We can close a connection as shown in the following example:

127.0.0.1:6379> client kill 127.0.0.1:43674

OK

The previous command will return OK if the operation is executed successfully.

Close Connection by ID

Redis also allows you to close a connection based on the id. For example, from the output of the client list command, you will notice the id column as shown below:

You can use the following id to terminate the connection as shown:

127.0.0.1:6379> client kill id 4

(integer) 1

The command returns 1, indicating the command executes successfully.

Close All Local Connections

You can terminate all the connections connected to a specified local address.

An example is provided below:

127.0.0.1:6379> client kill laddr 127.0.0.1:6379

(integer) 2

The previous command will terminate and return the number of connections closed.

Redis Skip Me

You will notice that Redis does not close the connection performing the closing. The SKIPME parameter conducts this. The SKIPME parameter takes yes/no as the value. It is set to yes by default.

However, if you want to close all the connections to the server, including yours, you can set the SKIPME parameter to no.

An example is provided below:

127.0.0.1:6379> client kill laddr 127.0.0.1:6379 skipme no

(integer) 5

Conclusion

This article specifies how to close client connections on the Redis server. This helpful tutorial highlights how to close client connections on the Redis server using a reliable process, such as the Redis Client Kill command, Redis List Clients, Redis Close Connection, Close Connection by ID, and Close All Connection We hope you found this article helpful. Check the other Linux Hint articles for more tips and commands.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list