Thursday, December 11, 2025

Redis DBA Daily Commands

Redis DBA Daily Commands

1. Service Management

sudo systemctl start redis → Start the Redis service if it’s stopped.
sudo systemctl stop redis → Stop Redis safely (use before maintenance).
sudo systemctl restart redis → Restart Redis after config changes.
systemctl status redis → Check if Redis is running and view recent logs.

2. Connectivity & Basic Ops

redis-cli → Open the Redis command-line interface.
redis-cli ping → Quick health check; returns PONG if Redis is alive.
redis-cli SET mykey "hello" → Store a key/value pair.
redis-cli GET mykey → Retrieve the value of a key.

3. Monitoring & Health

redis-cli INFO → Full server stats (memory, clients, persistence, replication).
redis-cli INFO memory → Focused memory usage report.
redis-cli CLIENT LIST → Show all connected clients (IP, state, etc.).
redis-cli MONITOR → Stream all commands in real time (use carefully in prod).
redis-cli SLOWLOG get 10 → Show the 10 most recent slow queries.

4. Persistence & Backup

redis-cli SAVE → Force an immediate RDB snapshot (blocking).
redis-cli BGSAVE → Trigger background snapshot (non-blocking).
redis-cli INFO persistence → Check persistence status (last save, AOF enabled).

Backup files:
dump.rdb → RDB snapshot file.
appendonly.aof → AOF log file.

5. Memory & Key Management

redis-cli DBSIZE → Count how many keys are in the database.
redis-cli KEYS '*' → List all keys (avoid in large DBs, can block).
redis-cli DEL mykey → Delete a specific key.
redis-cli EXPIRE mykey 60 → Set a 60‑second TTL on a key.

6. Replication & High Availability

redis-cli INFO replication → Show replication role (master/replica) and status.
redis-cli SLAVEOF NO ONE → Promote a replica to master.
redis-cli SLAVEOF <master_ip> <master_port> → Make this node a replica of another.

7. Cluster Administration (if enabled)

redis-cli -c CLUSTER NODES → List all cluster nodes and their roles.
redis-cli -c CLUSTER INFO → Cluster health and slot coverage.
redis-cli --cluster check <ip:port> → Validate cluster configuration.

8. Security & Access

redis-cli -a <password> → Authenticate with password.
redis-cli ACL LIST → Show all ACL rules (Redis 6+).
redis-cli ACL WHOAMI → Show which user you’re logged in as.

Redis Daily Health‑Check Runbook

1. Service Status
systemctl status redis
Confirms Redis service is running and shows recent logs.

2. Connectivity
redis-cli ping
Quick test; should return PONG if Redis is alive.

3. Memory & Resource Usage
redis-cli INFO memory
Check total memory used, peak memory, fragmentation ratio.
Watch for memory close to system limits.

4. Persistence
redis-cli INFO persistence
Verify RDB/AOF status, last save time, and whether background saves are succeeding.

5. Replication / HA
redis-cli INFO replication
Shows if this node is master or replica.
Check replica lag and connected replicas.

6. Clients
redis-cli CLIENT LIST | wc -l
Count connected clients.
Useful to detect spikes or stuck connections.

7. Slow Queries
redis-cli SLOWLOG get 5
Review the last 5 slow queries.
Helps identify performance bottlenecks.

8. Keyspace Stats
redis-cli INFO keyspace
Shows number of keys per database and how many have TTLs.
Useful for monitoring growth and expiration behavior.

9. General Server Info
redis-cli INFO server
Check Redis version, uptime, and role.
Confirms you’re running the expected build.

10. Optional Cluster Checks (if enabled)
redis-cli -c CLUSTER INFO
redis-cli -c CLUSTER NODES
Verify cluster health, slot coverage, and node states.

✅ Daily Routine Summary

Service status → Is Redis running?
Ping test → Is it responsive?
Memory check → Is usage healthy?
Persistence check → Are RDB/AOF saves working?
Replication check → Are replicas in sync?
Client count → Any unusual spikes?
Slow queries → Any performance issues?
Keyspace stats → Growth and TTL behavior.
Server info → Version, uptime, role.
Cluster info → Slot coverage and node health (if clustered).

No comments:

Post a Comment