Redis cheatsheet
redis-cli — connect
| Command | Description |
|---|---|
redis-cli -h localhost -p 6379 | Connect to server |
redis-cli -a password | Connect with password (avoid on shared hosts) |
redis-cli -u redis://user:pass@host:6379/0 | URL-style connection |
redis-cli PING | Health check (returns PONG) |
redis-cli --latency | Sample round-trip latency |
Service and health
| Command | Description |
|---|---|
systemctl status redis-server | Service status (Debian/Ubuntu) |
systemctl status redis | Service status (RHEL) |
ss -tlnp | grep 6379 | Confirm listener |
redis-cli INFO server | Version, uptime, config path |
redis-cli INFO memory | Used memory, peak, fragmentation |
redis-cli INFO stats | Ops/sec, connections, evictions |
Key commands
| Command | Description |
|---|---|
SET key value EX 3600 | Set with 1-hour TTL |
GET key | Read string value |
TTL key | Seconds until expiry (-1 no TTL, -2 missing) |
TYPE key | Data structure type |
DEL key [key ...] | Delete keys |
SCAN 0 MATCH prefix:* COUNT 100 | Iterate keys safely |
DBSIZE | Key count in current database |
Memory and config
| Command | Description |
|---|---|
CONFIG GET maxmemory | Memory limit |
CONFIG GET maxmemory-policy | Eviction policy |
MEMORY USAGE key | Bytes used by a key |
INFO keyspace | Keys per database |
Persistence
| Command | Description |
|---|---|
BGSAVE | Background RDB snapshot |
LASTSAVE | Unix time of last successful save |
INFO persistence | RDB/AOF status, last save errors |
CONFIG GET save | RDB auto-save rules |
CONFIG GET appendonly | AOF enabled? |
Replication
| Command | Description |
|---|---|
INFO replication | Role, connected replicas, lag offsets |
ROLE | Role and replication offsets |
REPLICAOF host port | Configure as replica at runtime |
REPLICAOF NO ONE | Promote replica to primary |
Backup and restore
| Command | Description |
|---|---|
BGSAVE | Trigger RDB; copy dir/dump.rdb when done |
cp /var/lib/redis/dump.rdb /backup/ | Copy snapshot (after BGSAVE) |
redis-cli --rdb /backup/dump.rdb | Remote RDB download via redis-cli |
redis-server /path/redis.conf | Start with empty dir + RDB file to restore |
Debugging
# Slow commands (last 10)
SLOWLOG GET 10
# Clients and what they're doing
CLIENT LIST
# Kill a stuck client
CLIENT KILL ip:port
# Live command stream (use briefly in prod!)
MONITOR
Pro tips
- Never run
KEYS *on production — useSCAN - Set
maxmemoryand a policy before Redis eats all RAM FLUSHALLandFLUSHDBare destructive — disable or restrict via ACL- After
redis.confchanges:systemctl restart redis-serverorCONFIG REWRITEfor runtime-tunable params - Replication ≠ backup — schedule RDB copies; test restores
Practice scenarios
Hands-on Redis scenarios on live Linux VMs: redis