The maximum number of connections in a Redis server is primarily determined by the maxclients configuration parameter. This parameter can be set in the Redis configuration file or dynamically adjusted at runtime using Redis commands.
The default value of maxclients typically depends on the server's operating system and its configuration. On most Linux systems, the default limit for the number of file descriptors that a process can open is 1024, and Redis's connection settings default to reserving 32 connections for internal and replication purposes, resulting in a default maxclients value of 992.
To handle more client connections, you can increase this limit through the following two steps:
- Increase the operating system's file descriptor limit: This can be achieved by modifying the
/etc/security/limits.conffile to adjust thenofilevalue, which represents the maximum number of files a single process can open. For example, you can set:
shell* soft nofile 10000 * hard nofile 10000
This configuration sets the soft and hard limits for all users to 10000. After modification, you need to log out or restart the system for the changes to take effect.
- Adjust the Redis
maxclientssetting: Once confirmed that the operating system's file descriptor limit is sufficient, you can modify the Redis configuration file to increase themaxclientsvalue. For example:
shellmaxclients 10000
Alternatively, you can dynamically adjust it while Redis is running using the command:
shellCONFIG SET maxclients 10000
After this configuration, Redis can handle more concurrent connections and accommodate larger-scale application requirements. Note that increasing the maximum number of connections may increase the memory usage of the Redis server, as each connection consumes a certain amount of memory resources. Therefore, when adjusting these settings, you should monitor memory usage to ensure stable server operation.