100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Redis

The Redis CLI

How to use redis-cli, the command-line client bundled with Redis, to run commands interactively, inspect keys, monitor traffic, and script common operations.

Redis FoundationsBeginner8 min readJul 10, 2026
Analogies

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.

bash
$ 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-cli alone 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 -a flags allow connecting to a remote, authenticated Redis instance.
  • redis-cli monitor streams every command processed by the server in real time, useful for debugging but risky under heavy production load.
  • redis-cli info reports 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

Was this page helpful?

Topics covered

#Redis#RedisStudyNotes#Database#TheRedisCLI#CLI#Commands#Useful#Flags#StudyNotes#SkillVeris