The Redis CLI
redis-cli is the command-line client that ships with every Redis installation, and it's usually the first tool developers reach for to explore data, test commands, and debug production issues. Running redis-cli with no arguments drops you into an interactive REPL connected to localhost:6379 by default, where you can type any Redis command and see its reply immediately, making it an indispensable tool for learning the command set and diagnosing live systems.
Cricket analogy: A coach using a simple stopwatch and notepad courtside to instantly time a bowler's run-up, rather than sending footage to a full video analysis lab, mirrors how redis-cli gives instant, direct feedback without any application layer in between.
Basic Commands
Inside the redis-cli REPL you can run any command in the Redis command reference: SET and GET for strings, EXPIRE and TTL to manage key lifetimes, DEL to remove keys, KEYS or the safer SCAN to enumerate keys, and TYPE to check what data structure a key holds. The REPL also supports command history (up-arrow) and tab completion in recent Redis versions, which speeds up exploration considerably during debugging sessions.
Cricket analogy: A scorer flipping quickly between the current over's tally and the previous over's tally to double-check a discrepancy is like using redis-cli's command history (up-arrow) to rerun and tweak a previous command.
$ redis-cli
127.0.0.1:6379> SET session:abc123 "user:42" EX 1800
OK
127.0.0.1:6379> TTL session:abc123
(integer) 1798
127.0.0.1:6379> TYPE session:abc123
string
127.0.0.1:6379> SCAN 0 MATCH session:* COUNT 100
1) "0"
2) 1) "session:abc123"
127.0.0.1:6379> DEL session:abc123
(integer) 1
# Non-interactive (scripting) mode
$ redis-cli GET session:abc123
(nil)Useful CLI Flags and Introspection Commands
Beyond the interactive REPL, redis-cli accepts flags that unlock powerful diagnostic modes: redis-cli -h <host> -p <port> -a <password> connects to a remote, authenticated instance; redis-cli --scan --pattern 'user:*' safely streams matching keys without the blocking risk of KEYS on a large dataset; redis-cli monitor streams every command the server processes in real time, invaluable (but risky in production due to overhead) for debugging; and redis-cli info returns a full report of server stats — memory usage, connected clients, replication status, and keyspace hits/misses.
Cricket analogy: A team analyst pulling up a live feed of every ball bowled across the ground in real time to spot patterns mirrors using redis-cli monitor to watch every command hit the server in real time.
Prefer SCAN over KEYS * on any production instance. KEYS is O(N) and blocks the single Redis thread until it finishes scanning the entire keyspace, which can freeze all other clients on a large database; SCAN iterates incrementally with a cursor and never blocks for more than a small slice of time.
- redis-cli is the interactive command-line client bundled with every Redis installation.
- Running
redis-clialone opens a REPL connected to localhost:6379 by default. - Common commands include SET/GET, EXPIRE/TTL, DEL, TYPE, and SCAN (preferred over KEYS in production).
redis-cli -h -p -aflags allow connecting to a remote, authenticated Redis instance.redis-cli monitorstreams every command processed by the server in real time, useful for debugging but risky under heavy production load.redis-cli inforeports comprehensive server statistics: memory, clients, replication, and keyspace hits/misses.- redis-cli also supports a non-interactive scripting mode by passing a command directly as arguments.
Practice what you learned
1. What does running `redis-cli` with no arguments do by default?
2. Why should SCAN be preferred over KEYS * on a production Redis instance?
3. Which redis-cli command streams every command the server processes in real time?
4. Which flag lets redis-cli authenticate with a password when connecting to a remote instance?
5. What does `redis-cli info` return?
Was this page helpful?
You May Also Like
Installing and Connecting to Redis
A practical guide to installing Redis locally or via Docker, understanding the core config file settings, and connecting to it from client libraries.
What Is Redis?
An introduction to Redis as an in-memory data structure store, covering what makes it different from disk-based databases and why it's become a staple of modern backend systems.
Redis Use Cases
A tour of the most common production use cases for Redis: caching, session storage, real-time leaderboards, rate limiting, and pub/sub messaging.