Redis

How to Check and Set Max Connections in Redis

Although Redis is an in-memory database, it allows more than one client to connect to the database. It uses connections from the clients on the configured TCP port or Unix sockets.

This short article will discuss how to check and increase or decrease the maximum clients supported by the Redis instance.

Redis Check Maximum Clients

The maximum number of clients supported by the Redis server is defined in the configuration file.

By default, the value is set to 10,000 clients. However, you can increase or decrease this value, as discussed in the later sections.

To check the number of max clients in your Redis server, open the terminal and log in to Redis:

$ redis-cli

Once logged in, run the command:

127.0.0.1:6379> config get maxclients

The previous command will check the current configuration and return the maximum clients.

The following output example output is provided:

127.0.0.1:6379> config get maxclients
1) "maxclients"
2) "10000"

Redis Set Maximum Clients

There are various ways to set the maximum number of clients who can connect to the Redis server.

The first method is to specify the number of clients when starting the Redis server.

The example is as shown below:

$ redis-server --maxclients 20000

In the previous command, we tell the Redis server to accept 20,000 clients. We can get the max clients as follows:

127.0.0.1:6379> config get maxclients
1) "maxclients"
2) "20000"

The second method to set the maximum number of clients for the Redis server is to use the config command.

The following example is provided:

127.0.0.1:6379> config set maxclients 20000

OK

There is one drawback with the methods above. Once the server is restarted, the maximum number of clients is reset to default.

We set the maximum number of clients in the Redis configuration file to create persistent value.

Edit the following file with your favorite text editor:

$ vim /etc/redis/redis.conf

Locate the entry below and change the value from 10,000 to your desired value.

# maxclients 10000 -> maxclients 20000

Note: the previous line may be commented out. Enable it by removing the pound sign.

Save and close the file. Restart the Redis server.

$ sudo /etc/init.d/redis-server restart

Redis Get Connected Clients

To show the connected clients to your Redis server, log in to the Redis instance and run the command:

127.0.0.1:6379> client list

This should return the information about the connected clients. The output example is as shown below:

Conclusion

This guide discussed how to view and manage the maximum number of clients connected to your Redis instance. In addition, we provided examples for the two methods to set the maximum number of clients who can connect to the Redis server. We hope you enjoyed the tutorial. Check the other Linux Hint articles for tips and articles.

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