0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · درس

استمرارية رسائل التدفقات

استكشفوا كيفية توفير Streams لاستمرارية الرسائل وتسليمها بترتيب، وما يميزها عن Pub/Sub.

استمرارية رسائل التدفقات درس مجاني في Redis Caching & Messaging (Pub/Sub, Streams) على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Redis Caching & Messaging (Pub/Sub, Streams)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Redis Caching & Messaging (Pub/Sub, Streams) 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What is Message Persistence?

In messaging systems, persistence means messages aren't lost, even if the recipient isn't ready to receive them immediately.

Think of it like leaving a note on a fridge instead of shouting it to someone who might not be home. The note stays until it's read.

This is crucial for reliability in many applications.

Streams Retain Your Data

Unlike some other Redis messaging features, Redis Streams are designed to be persistent. Every message (entry) you add to a stream is stored in Redis.

This storage acts like an append-only log. New entries are always added to the end, creating a historical record of events.

Unique Entry IDs for Order

Every entry in a Redis Stream gets a unique Entry ID. This ID is automatically generated by Redis and consists of two parts:

  • Timestamp (milliseconds): The time the entry was added.
  • Sequence Number: A counter for entries added within the same millisecond.

Example: 1678886400000-0

Adding Messages to a Stream

We use the XADD command to add new entries to a stream. The * tells Redis to auto-generate the Entry ID, ensuring uniqueness and proper ordering.

Each entry also holds field-value pairs, like a mini-hash.

XADD mystream * sensor-id 123 temperature 25.5

Reading from a Stream

To read entries from a stream, we use the XREAD command. You specify the stream name and the ID from which to start reading.

Crucially, reading an entry does not remove it from the stream. It stays there for other consumers or for future review.

XREAD COUNT 2 STREAMS mystream 0

Streams vs. Pub/Sub: Persistence

This is where Redis Streams significantly differ from Redis Pub/Sub (Publish/Subscribe).

  • Streams: Messages are persistent. They are stored and can be read multiple times, even by consumers who connect later.
  • Pub/Sub: Messages are ephemeral. They are delivered once to active subscribers and then disappear.

Pub/Sub: Fire and Forget

With Pub/Sub, if no client is subscribed to a channel when a message is published, that message is simply lost. There's no backlog or history.

It's like a live broadcast: if you're not tuned in, you miss it. This is great for real-time notifications where history isn't needed.

Streams Ensure Order

The automatically generated Entry IDs in Redis Streams guarantee strict chronological order. Messages are always stored and retrieved in the exact order they were added.

This is vital for applications where the sequence of events matters, such as logging, auditing, or event sourcing.

When to Use Persistent Streams

Choose Redis Streams when you need:

  • Reliable Event Logs: A complete, ordered history of events.
  • Message Replay: Ability for new consumers to process past events.
  • Auditing & Analytics: Historical data for analysis.
  • Decoupled Microservices: Services can process events at their own pace.

Stream Persistence Check

You're building an application that needs to ensure every event is processed, even if a consumer is temporarily offline. Which Redis feature is best suited for this requirement?

Recap: Streams' Core Strengths

In this lesson, we explored the crucial aspects of Redis Streams: message persistence and guaranteed ordered delivery.

  • Streams store all entries, forming an immutable log.
  • Each entry has a unique, time-based ID ensuring strict order.
  • This persistence and ordering are key differentiators from Redis Pub/Sub, making Streams ideal for reliable event processing and historical data.

الأسئلة الشائعة

هل درس «استمرارية رسائل التدفقات» مجاني؟

نعم — نص درس «استمرارية رسائل التدفقات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Redis Caching & Messaging (Pub/Sub, Streams)، انتقل إلى CoddyKit PRO. تتضمن دورة Redis Caching & Messaging (Pub/Sub, Streams) 4 دروس في المجموع.

ماذا ستتعلم في «استمرارية رسائل التدفقات»؟

استكشفوا كيفية توفير Streams لاستمرارية الرسائل وتسليمها بترتيب، وما يميزها عن Pub/Sub. تتمرن على Redis Caching & Messaging (Pub/Sub, Streams) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Redis Caching & Messaging (Pub/Sub, Streams)؟

لا تُشترط خبرة سابقة. Redis Caching & Messaging (Pub/Sub, Streams) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «استمرارية رسائل التدفقات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Redis Caching & Messaging (Pub/Sub, Streams) هذا؟

نعم. كل درس في Redis Caching & Messaging (Pub/Sub, Streams) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ما هي Redis Streams؟
  2. هياكل بيانات التدفقات وأوامرها
  3. استمرارية رسائل التدفقات
  4. تحديد طول التدفقات وتقليصها
← العودة إلى Redis Caching & Messaging (Pub/Sub, Streams)