بما أن Redis يخزن البيانات في ذاكرة الوصول العشوائي (RAM)، فإن إدارة الذاكرة حرجة — فهم حد maxmemory، سياسات الحذف، تحسين الذاكرة، والمراقبة ضروري لتشغيل Redis بشكل موثوق دون نفاد الذاكرة.
maxmemory وسياسات الحذف
Set a memory limit so Redis doesn't consume all RAM:
maxmemory 2gb # cap Redis at 2GB
maxmemory-policy allkeys-lru # what to do when the limit is reached
When the limit is hit, Redis EVICTS keys per the policy (or rejects writes):
allkeys-lru → evict least-recently-used (any key) — common for a pure cache
allkeys-lfu → evict least-frequently-used
volatile-lru → evict LRU among keys WITH a TTL only
volatile-ttl → evict keys closest to expiry
noeviction → reject writes when full (good if Redis holds important data)
