Operates Redis from redis-cli: GET/SET/hashes/lists, SCAN, latency/bigkeys, ACL, cluster, pub/sub, MONITOR. Use when querying or diagnosing a Redis instance from the command line. Not for application Redis clients (redis-py/ioredis), choosing Vercel/Upstash storage (vercel-storage), or Redis module/source development.
Operates Redis from redis-cli: GET/SET/hashes/lists, SCAN, latency/bigkeys, ACL, cluster, pub/sub, MONITOR. Use when querying or diagnosing a Redis instance from the command line. Not for application Redis clients (redis-py/ioredis), choosing Vercel/Upstash storage (vercel-storage), or Redis module/source development.
redis-cli is the primary command-line tool for interacting with Redis. It supports two modes: command-line execution (run a command and exit) and interactive mode (a REPL with tab completion, history, and hints). It also provides special modes for monitoring, latency analysis, keyspace scanning, and data import/export.
Windows host note: On Windows, redis-cli may be available via WSL2, Docker Desktop, or a native Redis port. If running under PowerShell, pipe-based examples (| wc -l, while read) require adaptation — use WSL or Git Bash for shell pipelines, or use PowerShell equivalents (Measure-Object, ForEach-Object).
Procedure
Step 1 — Establish a Connection
# Basic connection (default: 127.0.0.1:6379)
redis-cli
redis-cli -h redis15.localnet.org -p 6390 PING
# With password — NEVER pass -a in production; use REDISCLI_AUTH env var
REDISCLI_AUTH=YOUR_PASSWORD redis-cli PING
# URI connection
redis-cli -u redis://user:password@host:port/dbnum PING
# TLS
redis-cli --tls --cacert /path/to/ca.crt -h redis.example.com PING
# Specific database
redis-cli -n 2 DBSIZE
# IPv4/IPv6 preference
redis-cli -4 PING # prefer IPv4
redis-cli -6 PING # prefer IPv6
Step 2 — Choose Execution Mode
Command-line mode (execute one command and exit):
redis-cli INCR mycounter
redis-cli GET mykey
Interactive mode (REPL with tab completion and history):
The prompt shows host:port[db]. Use CONNECT <host> <port> to switch instances interactively.
Step 3 — Query Data by Type
String operations (O(1)):
GET key
SET key value [NX|XX] [EX sec|PX ms|KEEPTTL]
SET key value GET # Set new, return old value
GETSET key newvalue # [Prefer SET key value GET]
MGET key1 key2 ...
INCR key
INCRBY key 10
STRLEN key
GETRANGE key 0 50
Hash operations:
HGET key field # O(1)
HMGET key f1 f2 # O(N)
HGETALL key # O(N)
HKEYS key # O(N)
HLEN key # O(1)
HEXISTS key field # O(1)
HSCAN key 0 [MATCH pat] # O(1) per call
SCAN guarantees: a full iteration (cursor 0 → cursor 0) always returns all elements that existed for the entire duration. Elements may appear multiple times — handle duplicates in your application.
Step 5 — Inspect Server Health
# Real-time stats (updates every second; -i changes interval)
redis-cli --stat# Server information by section
redis-cli INFO server
redis-cli INFO memory
redis-cli INFO keyspace
redis-cli INFO replication
redis-cli INFO all
# Key space analysis
redis-cli --bigkeys # Largest keys by element count
redis-cli --memkeys # Largest keys by memory usage
redis-cli --keystats # Combined bigkeys + memkeys with distribution# Latency analysis
redis-cli --latency # Continuous latency sampling
redis-cli --latency-history # Latency over time (15s windows)
redis-cli --latency-dist # Latency spectrum visualization
redis-cli --intrinsic-latency 5 # System baseline (run on Redis host)
Step 6 — Control Output Format
# Raw output (no type prefixes) — default when piping
redis-cli --raw GET mykey
redis-cli GET mykey > /tmp/output.txt # auto raw mode# Human-readable (force) when piping
redis-cli --no-raw GET mykey | cat# CSV output
redis-cli --csv LRANGE mylist 0 -1
# JSON output (RESP3; use -2 for RESP2)
redis-cli --json HGETALL user:1
# Read last argument from stdincat /etc/services | redis-cli -x SET net_services
# Pipe commands from filecat /tmp/commands.txt | redis-cli
Step 7 — Repeat and Monitor Commands
# Run command N times
redis-cli -r 5 INCR counter
# Run with delay (seconds, supports decimals)
redis-cli -r -1 -i 1 INFO | grep rss_human # infinite, every 1s# Interactive: prefix with count
5 INCR mycounter # runs 5 times
Step 8 — Administer Server
# ACL management
redis-cli ACL LIST
redis-cli ACL SETUSER admin on >YOUR_PASSWORD ~* +@all
redis-cli ACL SETUSER readonly on >YOUR_PASSWORD ~* +@read
redis-cli ACL DELUSER username
redis-cli ACL DRYRUN username GET key
redis-cli ACL GENPASS
# Client management
redis-cli CLIENT LIST
redis-cli CLIENT KILL ADDR ip:port
redis-cli CLIENT PAUSE 5000 WRITE
redis-cli CLIENT SETNAME my-app
# Configuration
redis-cli CONFIG GET maxmemory
redis-cli CONFIG SET maxmemory 100mb
redis-cli CONFIG REWRITE
redis-cli CONFIG RESETSTAT
# Replication acknowledgment
redis-cli WAIT 2 5000 # Wait for 2 replicas (5s timeout)
redis-cli WAITAOF 1 1 5000 # Wait for AOF fsync (Redis 7.2+)# Persistence
redis-cli BGSAVE
redis-cli BGREWRITEAOF
redis-cli LASTSAVE
# Replication
redis-cli REPLICAOF host port
redis-cli REPLICAOF NO ONE
# Server lifecycle
redis-cli SHUTDOWN SAVE
redis-cli SHUTDOWN NOSAVE
# Slow log
redis-cli SLOWLOG GET 10
redis-cli SLOWLOG LEN
redis-cli SLOWLOG RESET
# Cluster management
redis-cli --cluster check host:port
redis-cli --cluster reshard host:port
redis-cli -c -h cluster-node PING
Common Workflows
Explore an Unknown Database
# Step 1: Basic stats
redis-cli INFO keyspace
redis-cli DBSIZE
# Step 2: Find big keys and memory usage
redis-cli --bigkeys
redis-cli --memkeys
# Step 3: Sample keys and inspect types
redis-cli --scan | head -20
redis-cli TYPE <key>
redis-cli TTL <key>
# Step 4: Read data based on type
redis-cli HGETALL <hash_key>
redis-cli LRANGE <list_key> 0 -1
redis-cli ZRANGE <zset_key> 0 -1 WITHSCORES
Monitor in Real Time
# Live server stats
redis-cli --stat -i 2
# Watch memory specifically
redis-cli -r -1 -i 5 INFO memory | grep used_memory_human
# Monitor all commands (caution: high overhead)
redis-cli MONITOR
# Continuous latency
redis-cli --latency-history -i 5
Never pass passwords via -a in production — visible in shell history and process listings. Always use the REDISCLI_AUTH environment variable instead.
Never use KEYS * on production databases — it blocks the server. Always use SCAN or --scan.
MONITOR logs all commands including sensitive data — use cautiously, never for extended periods on production servers.
FLUSHALL / FLUSHDB are irreversible — always verify the target database first with CLIENT LIST or INFO keyspace before executing.
--rdb transfer during write operations may produce inconsistent snapshots on busy servers. Run during low-traffic windows or use BGSAVE first.
SCAN may return duplicate keys across iterations — deduplicate in your application logic.
CONFIG SET at runtime is not persisted — follow with CONFIG REWRITE to save to redis.conf, or changes are lost on restart.
SHUTDOWN NOSAVE discards all in-memory data — verify persistence status (INFO persistence, LASTSAVE) before using.
Shell pipelines (| wc -l, while read) do not work natively in PowerShell — use WSL, Git Bash, or PowerShell equivalents (Measure-Object, ForEach-Object).