Difficulty: Beginner
How do you check how many clients are connected to Redis right now, and what the maximum connection limit is?
Run INFO clients to see the live count in connected_clients, and CONFIG GET maxclients to see the ceiling, which defaults to 10,000. When the limit is hit, Redis rejects new connections with ERR max number of clients reached and increments rejected_connections in INFO stats.
INFO clients returns a small block of fields. The ones worth knowing:
connected_clients: open client connections, not counting replicas.blocked_clients: clients waiting on blocking calls such as BLPOP, BRPOP or XREAD BLOCK.maxclients: the configured limit (shown here in recent versions, so you may not even need CONFIG GET).client_recent_max_input_buffer and client_recent_max_output_buffer: early warning that one client is sending or receiving huge payloads.For per-connection detail use CLIENT LIST. Each line shows the client's addr, name, age (seconds connected), idle (seconds since last command), db and the last cmd. Sorting this by idle is the fastest way to spot leaked connections.
Every client is a file descriptor. At startup Redis checks the process's open-file limit (ulimit -n) and reserves 32 descriptors for its own use. If maxclients 10000 is configured but the OS only allows 4,096 files, Redis lowers maxclients and logs a warning. So on a fresh Linux box you must raise the limit (systemd LimitNOFILE, or /etc/security/limits.conf) before raising maxclients. Managed services such as ElastiCache or Upstash set their own per-plan limits, and on those you check the provider's console as well.
Hitting 10,000 connections is almost always an application bug, not genuine load:
quit() leaks one connection per call.timeout defaults to 0, meaning Redis never drops idle clients.timeout 300 so idle clients are dropped, and keep tcp-keepalive at its default of 300 seconds so dead peers are detected.CLIENT SETNAME checkout-api so CLIENT LIST shows which service is misbehaving.CLIENT KILL ID <id> or a whole group with CLIENT KILL USER <name>.connected_clients crossing around 80% of maxclients, and on any increase in rejected_connections.# Current connection count and limit
redis-cli INFO clients | grep -E 'connected_clients|blocked_clients|maxclients'
redis-cli CONFIG GET maxclients
# Have any connections been refused?
redis-cli INFO stats | grep rejected_connections
# Who is connected? Count connections per client name
redis-cli CLIENT LIST | grep -o 'name=[^ ]*' | sort | uniq -c | sort -rn
# Drop idle clients after 5 minutes and raise the limit
redis-cli CONFIG SET timeout 300
redis-cli CONFIG SET maxclients 20000 # needs ulimit -n above 20032
Counting connections by name immediately shows which service holds the most. Unnamed connections (name= with nothing after) are a hint that some code path is not using the shared, named client.
// redis.js - import this module everywhere instead of creating clients
import { createClient } from 'redis';
const client = createClient({
url: process.env.REDIS_URL,
name: 'orders-api', // shows up in CLIENT LIST
});
client.on('error', (err) => console.error('Redis error', err));
await client.connect();
// Close cleanly on shutdown so connections are not left dangling
process.on('SIGTERM', async () => {
await client.quit();
process.exit(0);
});
export default client;
Creating the client once at module load means every request reuses the same connection. Redis pipelines commands from one connection efficiently, so one client per process is enough for most apps.
maxclients, INFO clients, CLIENT LIST, Connection Pooling, File Descriptors