Akışları Sınırlandırma ve Kırpma
MAXLEN ile uzunluğu sınırlayarak, MINID ile ID'ye göre kırparak ve performans için yaklaşık kırpmayı kullanarak akış belleğinin büyümesini denetleyin.
Akışları Sınırlandırma ve Kırpma, CoddyKit'te ücretsiz bir Redis Caching & Messaging (Pub/Sub, Streams) dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Redis Caching & Messaging (Pub/Sub, Streams) öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Redis Caching & Messaging (Pub/Sub, Streams) kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Streams Grow Forever
Unless told otherwise, a Redis Stream keeps every entry you append. For high-throughput producers this means unbounded memory growth. Capping and trimming let you keep streams to a manageable size.
Capping at Add Time
The cleanest approach is to cap during XADD using MAXLEN. Redis evicts the oldest entries to keep the length at or below the limit.
XADD events MAXLEN 1000 * action login user 42Exact vs Approximate
Exact trimming can be costly. The ~ modifier requests approximate trimming, which is far cheaper because Redis only removes whole macro-nodes.
MAXLEN 1000exactMAXLEN ~ 1000approximate, may keep slightly more
XADD events MAXLEN ~ 1000 * action clickTrimming After the Fact
You can trim an existing stream with XTRIM, using the same options as the XADD capping clause.
XTRIM events MAXLEN 500
XTRIM events MAXLEN ~ 500Trimming by ID with MINID
Instead of length, you can trim by entry ID. MINID removes all entries older than a given ID, which maps naturally to time since IDs start with a millisecond timestamp.
XTRIM events MINID 1716900000000
XADD events MINID ~ 1716900000000 * a 1Time-Window Retention
Because the first part of a stream ID is a Unix millisecond timestamp, MINID lets you keep only the last hour or day of events. Compute the cutoff timestamp in your app and pass it in.
# keep last 24h: cutoff = (now_ms - 86400000)
XTRIM events MINID 1716813600000Limiting Eviction Work
The LIMIT option (with approximate trimming) caps how many entries a single trim removes, smoothing out latency spikes on very large streams.
XTRIM events MAXLEN ~ 1000 LIMIT 100Checking Stream Length
Use XLEN to see the current entry count and XINFO STREAM for detailed metadata including first and last IDs.
XLEN events
XINFO STREAM eventsTrimming and Consumer Groups
Trimming removes entries regardless of whether consumer groups have read them. If a slow consumer falls behind the trim point, those messages are lost for it. Size your cap to cover your slowest consumer's lag.
Choosing a Strategy
Use MAXLEN when you care about count and bounded memory. Use MINID when you care about a time window. Prefer the ~ approximate form in production for performance unless exact bounds are required.
Memory in Practice
Capping at add time is usually best: it keeps memory steady without a separate cleanup job. Reserve XTRIM for ad-hoc cleanups or when retention rules change.
Quick Check
Test your understanding of stream trimming.
Recap
You learned to control stream growth with MAXLEN capping, MINID time-window trimming, the cheaper ~ approximate mode, the LIMIT option to bound eviction work, and the caveat that trimming can drop messages slow consumers have not yet read.
Yapay zeka eğitmeniyle Redis Caching & Messaging (Pub/Sub, Streams) öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 12
- Dersler
- 48
Sıkça Sorulan Sorular
“Akışları Sınırlandırma ve Kırpma” dersi ücretsiz mi?
Evet — “Akışları Sınırlandırma ve Kırpma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Redis Caching & Messaging (Pub/Sub, Streams) kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Redis Caching & Messaging (Pub/Sub, Streams) kursu toplamda 4 dersten oluşur.
“Akışları Sınırlandırma ve Kırpma” dersinde ne öğreneceğim?
MAXLEN ile uzunluğu sınırlayarak, MINID ile ID'ye göre kırparak ve performans için yaklaşık kırpmayı kullanarak akış belleğinin büyümesini denetleyin. Redis Caching & Messaging (Pub/Sub, Streams) ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Redis Caching & Messaging (Pub/Sub, Streams) öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Redis Caching & Messaging (Pub/Sub, Streams), başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.
“Akışları Sınırlandırma ve Kırpma” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Redis Caching & Messaging (Pub/Sub, Streams) dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Redis Caching & Messaging (Pub/Sub, Streams) dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Redis Akışları Nedir?
- Akış Veri Yapıları ve Komutları
- Akış Mesajlarının Kalıcılığı
- Akışları Sınırlandırma ve Kırpma