In Redis, connected_clients has climbed close to maxclients; how do you use CLIENT LIST to find out who holds those connections?
answer
- one line per connection
- group by where they come from
- age and idle tell the story
- flags name the unusual ones
- not free with thousands of clients
basics
~20 sCLIENT LIST prints one line per connection with its address, name, age, idle time, flags and last command. Group the lines by host or name, then use age, idle and flags to separate a leaking pool, connection churn and blocked clients.
solid answer
~50 s`CLIENT LIST` returns one line of `key=value` fields per connection. I group lines by `addr` host, `name` and `lib-name` to see which service holds the connections. Then `age` and `idle` tell me the shape: high `age` with high `idle` looks like an oversized or leaking pool, while low `age` everywhere plus a fast-rising `total_connections_received` means a client reconnecting instead of reusing. `flags` picks out the unusual ones: `b` for a blocking call, `P` for Pub/Sub, `O` for a `MONITOR` client. `omem` and `tot-mem` show a client that is not reading its replies. `name` is empty unless the client set one, so I want every service to do that. The command is O(N) in connections, so I run it when needed rather than polling it hard, and I filter with `TYPE` or `ID` when I can. The lasting fix belongs in the client's pool settings.
code
bash · 1 lineredis-cli CLIENT LIST TYPE normal | grep -o ' addr=[^:]*' | sort | uniq -c | sort -rn | headgo deeper
Recall that CLIENT LIST prints one line per connection and that addr, name, age, idle and cmd identify who a client is and what it last did.
Explain how to group the output to find an owner, how age and idle separate a stale pool from churn, and what the b, P and O flags mean.
Confirm a diagnosis with total_connections_received, know the O(N) cost at the worst moment, and buy time safely while sending the real fix to the client side.
Set the standing rule that every service names its connections and declares a pool size, so that the sum of pools across a fleet is compared with maxclients before a deploy rather than during an incident.
## The situation `connected_clients` in `INFO clients` is one number. `maxclients`, 10000 by default, is the upper limit for the sum of `connected_clients`, `connected_slaves` and `cluster_connections`. Past it, new connections are refused and `rejected_connections` in `INFO stats` rises. **`CLIENT LIST`** is what turns the one number into names. Note what the count covers. `connected_clients` excludes replicas, which you can see with `CLIENT LIST TYPE replica`, but it includes `MONITOR` clients, which belong to the `normal` class. ## What each line contains The reply has one line per connection, in `key=value` form. The fields you need most: - **`addr`**: the client's IP and port. **`laddr`** is the local address it connected to. - **`name`**: set by the client with `CLIENT SETNAME` or the `SETNAME` option of `HELLO`; empty otherwise. - **`lib-name`**, **`lib-ver`**: the client library, set with `CLIENT SETINFO`, available since Redis 7.2, and also empty if the library does not send them. - **`user`**: the authenticated ACL user. - **`age`**, **`idle`**: seconds since connecting, and seconds since the last interaction. - **`flags`**: the connection's state, as letters. - **`cmd`**: the last command it ran. - **`tot-cmds`**: how many commands it has executed in total. - **`omem`**, **`tot-mem`**: output buffer memory, and total memory across its buffers. ## From lines to a diagnosis Work in this order: 1. **Group by source.** Count lines by `addr` host, then by `name` or `lib-name`. One deployment holding 8,000 connections is usually the whole answer. 2. **Read the shape** of that group, using the table below. 3. **Check it against the rate.** Compare two readings of `total_connections_received` to separate a static pile of connections from churn. 4. **Fix the source**, then confirm that the number falls. | What you see | Likely meaning | Where the fix is | |---|---|---| | High `age`, high `idle`, plain `flags=N` | Pool too large, or connections leaked and never closed | Client pool size, close paths | | Low `age` across the group, `total_connections_received` climbing fast | Connecting per request instead of reusing | Client connection reuse | | `flags` contains `b`, `cmd` is a blocking command, `blocked_clients` is high | Workers parked on `BLPOP` or similar, which may be by design | Check whether the count is intended | | `flags` contains `P`, `sub` above zero | Pub/Sub subscribers, each holding a connection | Subscriber fan-out | | `flags=O` | A `MONITOR` client, possibly a forgotten one | Close it | | High `omem` | A client not reading replies fast enough | That client, and its buffer limit | These are likelihoods, not proofs. High `idle` is normal for a pool sized for peak traffic; it looks like a leak only if the count keeps growing while traffic does not. Also add up what the pools are allowed to hold: forty instances of a service with a pool of 200 can reach 8,000 connections with nothing broken at all. ## What it costs and how to run it `CLIENT LIST` is O(N) in the number of connections, so its cost is at its highest exactly when you need it most. It runs on the main thread and is in the `@admin`, `@slow` and `@dangerous` ACL categories. Running it a few times during an investigation is reasonable; a dashboard that polls it every second on an instance with thousands of clients is not. The `TYPE` filter narrows the output by class, and `ID` asks about specific clients. The fields also change between releases, and the docs tell scripts to tolerate missing and unknown ones. Extract fields by name, not by position. ## Relieving pressure If the instance is about to refuse connections: - `CLIENT KILL ID <id>` closes one connection. `CLIENT KILL USER`, `ADDR` and `MAXAGE` filter more broadly. - The `timeout` setting closes idle clients, but it is 0, meaning disabled, in the shipped `redis.conf`. - Raising `maxclients` buys time, at the cost of memory and file descriptors. None of those is a real fix on its own. A pool that leaks will reconnect and fill up again, so the lasting change is on the client side. Asking every service to call `CLIENT SETNAME` makes the next incident far shorter, because the listing then names its owners.
- Why does connected_clients sometimes disagree with the number of lines CLIENT LIST prints?`connected_clients` subtracts replica connections, while an unfiltered `CLIENT LIST` also lists them. The two readings are also not atomic, so connections can come and go between them. Comparing with `CLIENT LIST TYPE normal` plus `TYPE pubsub` gets you closer to the same population.
- What would you ask service teams to change so that the next connection incident takes minutes?Have every service call `CLIENT SETNAME` with a recognisable name when it connects, so `name` identifies the owner directly instead of an IP you must trace through a load balancer or container platform. The docs expect client libraries to report `lib-name` and `lib-ver` through `CLIENT SETINFO`, which helps spot an old driver.
- CLIENT LIST is free to poll every second however many clients are connected.
- connected_clients counts every connection, including those from replicas.
- Every connection shows its service's name automatically, without the client setting it.
- High idle on a connection always proves that a pool is leaking.
- A client in MONITOR mode is listed under TYPE replica.
- Killing the idle connections with CLIENT KILL solves a leaking pool.