Files
life-echo/api/.agents/skills/redis-development/rules/ram-limits.md
Sully 53e0065e3e refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
2026-05-22 13:44:50 +08:00

1.4 KiB

title, impact, impactDescription, tags, description, alwaysApply
title impact impactDescription tags description alwaysApply
Configure Memory Limits and Eviction Policies HIGH Prevents out-of-memory crashes and unpredictable behavior memory, maxmemory, eviction, lru, ttl Configure Memory Limits and Eviction Policies true

Configure Memory Limits and Eviction Policies

Always configure maxmemory and an eviction policy to prevent Redis from consuming all available memory.

Correct: Set explicit memory limits.

maxmemory 2gb
maxmemory-policy allkeys-lru
Policy Use Case
volatile-lru Evict keys with TTL, least recently used first
allkeys-lru Evict any key, least recently used first
volatile-ttl Evict keys closest to expiration
noeviction Return errors when memory is full (use for critical data)

Incorrect: Running Redis without memory limits.

# No maxmemory set - Redis will use all available RAM
# Can cause OOM killer to terminate Redis or other processes

Memory optimization tips:

  • Use Hashes for small objects (more memory-efficient than separate keys)
  • Use OBJECT ENCODING key to check how Redis stores your data
  • Use MEMORY USAGE key to check individual key memory consumption
  • Enable compression in your client for large values

Reference: Redis Memory Optimization