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:
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:
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:
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:
(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:
(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:
(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.