refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
This commit is contained in:
42
api/.agents/skills/redis-development/rules/ram-limits.md
Normal file
42
api/.agents/skills/redis-development/rules/ram-limits.md
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
title: Configure Memory Limits and Eviction Policies
|
||||
impact: HIGH
|
||||
impactDescription: Prevents out-of-memory crashes and unpredictable behavior
|
||||
tags: memory, maxmemory, eviction, lru, ttl
|
||||
description: Configure Memory Limits and Eviction Policies
|
||||
alwaysApply: 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](https://redis.io/docs/latest/operate/oss_and_stack/management/optimization/memory-optimization/)
|
||||
|
||||
Reference in New Issue
Block a user