skills/redis-development/rules/observe-commands.md

54 lines
1.1 KiB
Markdown

---
title: Use Observability Commands for Debugging
impact: MEDIUM
impactDescription: Enables quick diagnosis of performance issues
tags: observability, slowlog, info, memory, debugging
description: Use Observability Commands for Debugging
alwaysApply: true
---
## Use Observability Commands for Debugging
Redis provides built-in commands for monitoring and debugging.
**Key commands:**
```
# Slow query log - find slow commands
SLOWLOG GET 10
SLOWLOG LEN
SLOWLOG RESET
# Server info - comprehensive stats
INFO all
INFO memory
INFO stats
INFO replication
INFO clients
# Memory analysis
MEMORY DOCTOR
MEMORY STATS
MEMORY USAGE mykey
# Client connections
CLIENT LIST
CLIENT INFO
# Index info (RQE)
FT.INFO idx:products
FT.PROFILE idx:products SEARCH QUERY "@name:laptop"
```
**Correct:** Check SLOWLOG regularly.
```python
# Get recent slow queries
slow_queries = redis.slowlog_get(10)
for query in slow_queries:
print(f"Duration: {query['duration']}μs, Command: {query['command']}")
```
Reference: [Redis Monitoring](https://redis.io/docs/latest/operate/oss_and_stack/management/optimization/latency/)