Monitoring
Redis exposes its internal state through a handful of commands and a small set of latency tools. The metrics you actually want to watch are memory, evictions, slow queries, client churn, and replication lag. Hook them into Prometheus or your dashboard once and you will know about most incidents before users do.
INFO + slowlog + latency + a Prometheus-ready exporter
EXAMPLE
# 1) INFO sections — keep an eye on these fields
redis-cli INFO memory | grep -E 'used_memory|maxmemory|evicted_keys'
# used_memory_human: actual RSS
# used_memory_peak_human: high water mark
# evicted_keys: growing -> you are pushing the cache too hard
# mem_fragmentation_ratio: >1.5 sustained -> consider MEMORY PURGE / restart
redis-cli INFO clients | grep -E 'connected_clients|blocked_clients|tracking'
# connected_clients: current open connections
# blocked_clients: those waiting in BLPOP / BRPOP
redis-cli INFO stats | grep -E 'instantaneous_ops|expired_keys|keyspace_hits|keyspace_misses'
# instantaneous_ops_per_sec: throughput
# keyspace_hits / misses ratio: hit rate; below 0.9 == not caching well
redis-cli INFO replication
# master_link_status, master_last_io_seconds_ago, slave_repl_offset
# 2) Slow log — query that took longer than slowlog-log-slower-than micros
redis-cli CONFIG SET slowlog-log-slower-than 10000 # log queries > 10 ms
redis-cli CONFIG SET slowlog-max-len 256
redis-cli SLOWLOG GET 5
# 3) Latency monitor — system-level latency events
redis-cli CONFIG SET latency-monitor-threshold 100 # ms
redis-cli LATENCY HISTORY event
redis-cli LATENCY LATEST
redis-cli LATENCY DOCTOR # prose summary
# 4) Live keyspace events — sample what is happening RIGHT NOW
redis-cli MONITOR | head -20 # NOTE: serialised; do not run in prod long
# 5) Memory usage of a specific key — useful for finding hot/large keys
redis-cli MEMORY USAGE myset:42 SAMPLES 0
redis-cli --bigkeys # sweeps for the biggest keys per type
# 6) Latency of a single command path
redis-cli --latency -h prod.redis -p 6379 -i 1
redis-cli --latency-history # rolling history
# 7) Sampling for hotkeys
redis-cli --hotkeys
# 8) Prometheus — run redis_exporter alongside Redis
# docker run -d -p 9121:9121 \
# --name redis_exporter \
# oliver006/redis_exporter \
# --redis.addr=redis://prod.redis:6379 \
# --redis.password=$REDIS_PASS
# Prometheus scrape config
# - job_name: redis
# static_configs: [ { targets: ['redis_exporter:9121'] } ]
# 9) Alerts that pay rent
# - evicted_keys > 0 sustained for 5m
# - keyspace_misses / (hits+misses) > 0.2 for 10m
# - replication_lag_seconds > 5
# - used_memory > maxmemory * 0.9
# - blocked_clients > 0 for 5m (queue backed up)
# - slowlog growth > 50 / minute
Why it matters
A 90%+ hit rate is the simplest health signal you have for a cache-style Redis. Below that, either your TTLs are too short, your working set has outgrown memory, or someone is using Redis as a database instead of a cache. The fix depends on which, and INFO + MEMORY USAGE tell you in two minutes.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…