Redis maxclients Explained: Configuring Maximum Client Connections
Introduction
The maxclients directive controls the maximum number of client connections that a Redis server can accept simultaneously.
Each client connection consumes system resources, including memory and file descriptors. Without a connection limit, excessive client connections may overwhelm the server and reduce overall performance.
This guide explains how maxclients works, how to configure it, common connection limit issues, and best practices for production environments.
Default Value
Most Redis installations use:
maxclients 10000
Redis can accept up to 10,000 concurrent client connections by default.
The actual limit may be lower if the operating system does not provide enough file descriptors.
Syntax
maxclients
Examples:
maxclients 5000
maxclients 20000
How maxclients Works
When the number of connected clients reaches the configured limit:
Existing clients continue to operate normally.
New connection attempts are rejected.
Clients attempting to connect may receive an error similar to:
ERR max number of clients reached
Configure maxclients
Open the Redis configuration file.
sudo nano /etc/redis.conf
Locate:
maxclients 10000
Modify it if necessary.
Example:
maxclients 20000
Restart Redis.
sudo systemctl restart redis
Verify the Configuration
Run:
redis-cli CONFIG GET maxclients
Example output:
1) "maxclients"
2) "20000"
Check Current Connections
Redis provides client statistics.
Run:
redis-cli INFO clients
Example output:
connected_clients:125
blocked_clients:0
To list connected clients:
redis-cli CLIENT LIST
Operating System Limits
The maxclients setting is also affected by the operating system's file descriptor limit.
Check the current limit:
ulimit -n
Example:
1024
If the operating system allows only 1,024 file descriptors, Redis cannot support 10,000 client connections.
Increase the file descriptor limit before raising maxclients.
Choosing the Right Value
The appropriate setting depends on your workload.
Higher values require more memory and operating system resources.
Common Mistakes
Increasing maxclients Without Raising ulimit
Redis cannot exceed the operating system's file descriptor limit.
Both settings must be configured together.
Assuming More Connections Improve Performance
A higher connection limit does not automatically make Redis faster.
Excessive connections may increase memory consumption and scheduling overhead.
Ignoring Connection Leaks
Applications that fail to close unused connections may eventually reach the client limit.
Use connection pooling whenever possible.
Best Practices
Monitor the number of connected clients regularly.
Use connection pools in application frameworks.
Increase the operating system's file descriptor limit before raising maxclients.
Avoid unnecessarily large connection limits.
Investigate connection leaks if client counts continue to grow.
Related Articles
Redis protected-mode Explained
Conclusion
The maxclients directive limits the number of simultaneous client connections that Redis accepts, helping protect the server from resource exhaustion. Choosing an appropriate value ensures that Redis can handle expected workloads while maintaining stable performance.
When increasing maxclients, remember that the operating system's file descriptor limit must also be adjusted. Monitoring client connections and using connection pooling are essential practices for reliable production deployments.
Explore More
› Redis timeout Explained: Managing Idle Client Connections
› Redis tcp-keepalive Explained: Maintaining Reliable Client Connections
› Redis save Explained: Configuring RDB Snapshots for Data Persistence
› Redis bind Explained: Configuring Network Interfaces Securely
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Northern vs Southern Chinese Business Culture: Key Differences Explained