Redis CLI
redis-cli is the first tool on every production incident.
Introduction
redis-cli is the first tool on every production incident. Before Grafana loads, you will run SLOWLOG GET, INFO memory, and LATENCY DOCTOR to narrow the blast radius.
It speaks RESP over TCP (or Unix socket), supports interactive mode, one-shot commands, and cluster-aware routing with --cluster options.
Master these diagnostics and you can distinguish a hot key from a memory fragmentation crisis in under two minutes.
Understanding the topic
Key concepts
- Interactive mode: redis-cli with no args opens a REPL.
- One-shot: redis-cli GET key for scripts and CI checks.
- MONITOR streams every command — dev only, crushes prod.
- SLOWLOG captures commands exceeding slowlog-log-slower-than.
- LATENCY DOCTOR summarizes recent latency spikes.
- --bigkeys and --hotkeys scan keyspace for outliers (use off-peak).
flowchart TBCLI[redis-cli] --> Data[GET HGET ZRANGE]CLI --> Server[INFO CONFIG]CLI --> Debug[SLOWLOG LATENCY MONITOR]CLI --> Cluster[CLUSTER NODES]
Step-by-step explanation
- redis-cli connects to host:port (default 127.0.0.1:6379).
- -a or --user for ACL authentication.
- Commands sent as RESP; replies rendered as text or raw.
- Cluster mode follows MOVED/ASK redirects with -c flag.
- Pipe mode (--pipe) bulk-loads data for migrations.
Syntax reference
Common commands
- TTL/TYPE — first step on any mystery key.
- SLOWLOG — find commands blocking the event loop.
- LATENCY DOCTOR — human-readable latency report.
redis-cli -h prod.redis.internal -a '$PASS' --no-auth-warningTTL session:abcTYPE session:abcSLOWLOG GET 10LATENCY DOCTORMEMORY DOCTOR
Informative example
Investigate a slow API — check slowlog and memory in one session:
redis-cli SLOWLOG GET 5# 1) 1) (integer) 1234567# 2) (integer) 8500 ← microseconds# 3) (integer) 10# 4) 1) "KEYS" 2) "*"redis-cli INFO memory | grep used_memory_humanredis-cli --hotkeys -i 0.1
KEYS in slowlog is a smoking gun. Replace with SCAN in application code and flush the offender deploy.
Real-world use
Real-world use cases
- On-call: confirm connectivity and auth after network change.
- Find slow commands blocking the event loop.
- Inspect TTL and type before deleting mystery keys.
- Cluster slot migration with CLUSTER MEET / ADDSLOTS.
- Bulk import via cat data.txt | redis-cli --pipe.
Best practices
- Use --no-auth-warning in scripts; prefer REDISCLI_AUTH env var.
- Never MONITOR in production under load.
- Run --bigkeys during maintenance windows only.
- Wrap repeated checks in shell aliases for on-call runbooks.
- Use -c for cluster; without it MOVED errors confuse juniors.
- Prefer read-only ACL user for diagnostic scripts.
Common mistakes
- Running KEYS * on production to count keys.
- Leaving MONITOR running over SSH disconnect.
- Forgetting -c on cluster and misreading errors.
- Pasting production passwords into Slack with redis-cli -a.
Advanced interview questions
Q1BeginnerHow do you connect to Redis from CLI?
Q2BeginnerWhat does PING return?
Q3IntermediateHow do you find slow commands?
Q4IntermediateWhy avoid MONITOR in production?
Q5AdvancedDebug high latency without application access?
Summary
redis-cli is the primary production diagnostic tool.