AgentSkillsCN

redis-performance

掌握Redis性能——内存优化、慢日志分析、基准测试、监控和调优策略

SKILL.md
--- frontmatter
name: redis-performance
description: Master Redis performance - memory optimization, slow log analysis, benchmarking, monitoring, and tuning strategies
sasmp_version: "1.3.0"
bonded_agent: 08-redis-production
bond_type: PRIMARY_BOND

# Production Configuration
version: "2.1.0"
last_updated: "2025-01"

# Parameters
parameters:
  analysis_type:
    type: string
    required: true
    enum: [memory, latency, throughput, slow_queries]

# Retry Configuration
retry_config:
  max_retries: 3
  backoff_strategy: exponential
  backoff_base_ms: 100

# Observability
observability:
  metrics:
    - memory_used_bytes
    - memory_fragmentation_ratio
    - instantaneous_ops_per_sec
    - slowlog_length

Redis Performance Skill

Memory Management

conf
maxmemory 4gb
maxmemory-policy allkeys-lru
maxmemory-samples 10

Eviction Policies

PolicyDescriptionUse Case
noevictionError on fullCritical data
allkeys-lruEvict LRUGeneral cache
volatile-lruEvict LRU with TTLSession cache
allkeys-lfuEvict LFUFrequency-based

Memory Analysis

redis
INFO memory
MEMORY DOCTOR
MEMORY USAGE key
MEMORY STATS
redis-cli --bigkeys

Slow Log

redis
CONFIG SET slowlog-log-slower-than 10000  # 10ms
CONFIG SET slowlog-max-len 128

SLOWLOG GET 10
SLOWLOG LEN
SLOWLOG RESET

Common Slow Commands

CommandFix
KEYS *Use SCAN
SMEMBERSUse SSCAN
HGETALLUse HMGET

Benchmarking

bash
# Basic
redis-benchmark -q -n 100000

# With pipelining
redis-benchmark -q -n 100000 -P 16

# Specific commands
redis-benchmark -t set,get -n 100000 -q

Latency Monitoring

redis
CONFIG SET latency-monitor-threshold 100
LATENCY DOCTOR
LATENCY HISTORY command

Key Metrics

MetricHealthyWarningCritical
Memory<75%75-90%>90%
Ops/secBaseline+50%+100%
Latency<1ms1-10ms>10ms
Hit ratio>95%90-95%<90%

Assets

  • performance-config.conf - Optimized config

References

  • PERFORMANCE_GUIDE.md - Tuning guide

Troubleshooting

High Memory

redis
INFO memory
redis-cli --bigkeys

Fix: Set eviction policy, add TTL

High Latency

redis
SLOWLOG GET 10
LATENCY DOCTOR

Fix: Optimize slow commands


Error Codes

CodeNameRecovery
PERF001OOMIncrease maxmemory or evict
PERF002HIGH_LATCheck slow log
PERF003FRAGMEMORY PURGE or restart