Client Commands
Client commands for managing connections, debugging, and controlling client behavior.
Commands
Section titled âCommandsâ| Command | Syntax | Description |
|---|---|---|
| CLIENT SETNAME | CLIENT SETNAME name | Set connection name |
| CLIENT GETNAME | CLIENT GETNAME | Get connection name |
| CLIENT LIST | CLIENT LIST | List all connected clients |
| CLIENT ID | CLIENT ID | Get current connection ID |
| CLIENT INFO | CLIENT INFO | Get current connection info |
| CLIENT KILL | CLIENT KILL ID id | Kill a client connection |
| CLIENT PAUSE | CLIENT PAUSE ms | Pause all clients |
| CLIENT UNPAUSE | CLIENT UNPAUSE | Resume paused clients |
Examples
Section titled âExamplesâConnection Naming
Section titled âConnection NamingâSet a meaningful name for debugging:
127.0.0.1:6379> CLIENT SETNAME worker-1OK
127.0.0.1:6379> CLIENT GETNAME"worker-1"Get Connection ID
Section titled âGet Connection IDâ127.0.0.1:6379> CLIENT ID(integer) 42Current Connection Info
Section titled âCurrent Connection Infoâ127.0.0.1:6379> CLIENT INFOid=42 addr=127.0.0.1:52341 name=worker-1 db=0 cmd=clientList All Clients
Section titled âList All Clientsâ127.0.0.1:6379> CLIENT LISTid=1 addr=127.0.0.1:52340 name=admin db=0 cmd=clientid=42 addr=127.0.0.1:52341 name=worker-1 db=0 cmd=getid=43 addr=127.0.0.1:52342 name=worker-2 db=0 cmd=blpopid=44 addr=127.0.0.1:52343 name= db=1 cmd=setEach line shows:
id- Unique connection IDaddr- Client IP and portname- Client name (if set)db- Selected databasecmd- Last command executed
Kill a Client
Section titled âKill a Clientâ# Find the client127.0.0.1:6379> CLIENT LISTid=99 addr=192.168.1.100:12345 name=rogue-client db=0 cmd=keys
# Kill by ID127.0.0.1:6379> CLIENT KILL ID 99OKPause All Clients
Section titled âPause All ClientsâTemporarily pause all client operations (useful for maintenance):
# Pause for 5 seconds127.0.0.1:6379> CLIENT PAUSE 5000OK
# All other clients block on commands...
# Or resume early127.0.0.1:6379> CLIENT UNPAUSEOKPractical Examples
Section titled âPractical ExamplesâIdentify Slow Clients
Section titled âIdentify Slow Clientsâ# List clients to see what they're doing127.0.0.1:6379> CLIENT LISTid=1 addr=127.0.0.1:52340 name=web-1 cmd=getid=2 addr=127.0.0.1:52341 name=web-2 cmd=getid=3 addr=127.0.0.1:52342 name=batch-job cmd=keys # Slow KEYS command!Connection Debugging
Section titled âConnection Debuggingâ# Set descriptive name on connectCLIENT SETNAME "api-server-pod-abc123"
# Later, in monitoring:CLIENT LIST# Can identify which pod/service each connection belongs toGraceful Maintenance
Section titled âGraceful Maintenanceâ# 1. Pause writes during backupCLIENT PAUSE 10000
# 2. Perform backup# ... backup operations ...
# 3. ResumeCLIENT UNPAUSEKill Misbehaving Clients
Section titled âKill Misbehaving Clientsâ# Find clients doing expensive operations127.0.0.1:6379> CLIENT LISTid=50 addr=10.0.0.5:43210 name= db=0 cmd=keys # KEYS * is bad!
# Terminate the connection127.0.0.1:6379> CLIENT KILL ID 50OKClient Info Fields
Section titled âClient Info Fieldsâ| Field | Description |
|---|---|
id | Unique client connection ID |
addr | Client address (IP:port) |
name | Client name from CLIENT SETNAME |
db | Currently selected database (0-15) |
cmd | Last command executed |
Use Cases
Section titled âUse CasesâApplication Monitoring
Section titled âApplication Monitoringâ# Each app instance names itselfCLIENT SETNAME "app-instance-${HOSTNAME}"
# Ops team can see all connectionsCLIENT LISTConnection Limits
Section titled âConnection Limitsâ# Check how many clients connectedCLIENT LIST# Count lines to see total connections
# Kill oldest/idle connections if neededCLIENT KILL ID <oldest_id>Debugging Connection Issues
Section titled âDebugging Connection Issuesâ# Which database is this connection using?CLIENT INFO# Shows: db=3
# What was the last command?CLIENT INFO# Shows: cmd=hgetallBlue-Green Deployments
Section titled âBlue-Green Deploymentsâ# During deployment:# 1. Pause old clientsCLIENT PAUSE 30000
# 2. Deploy new version
# 3. Resume (or let timeout expire)CLIENT UNPAUSEImportant Notes
Section titled âImportant NotesâServer Mode Only
Section titled âServer Mode OnlyâCLIENT commands are only available in server mode - they manage TCP connections which donât exist in embedded library mode.
CLIENT PAUSE Behavior
Section titled âCLIENT PAUSE Behaviorâ- All clients (except the one issuing PAUSE) block
- Read and write commands are paused
- Pub/Sub messages are still delivered
- Timeout in milliseconds
Connection Naming
Section titled âConnection Namingâ- Names have no spaces or special characters
- Empty string clears the name
- Names are for debugging only, no security implications
Killing Connections
Section titled âKilling Connectionsâ- CLIENT KILL immediately closes the TCP connection
- Client will need to reconnect
- Use for misbehaving clients or maintenance