0Pricing
System Design Basics for Backend Developers · درس

التخزين المؤقت الموزع باستخدام Redis

طبّق حلول التخزين المؤقت الموزع باستخدام أدوات مثل Redis لمشاركة ذاكرة التخزين المؤقت بين مثيلات متعددة للتطبيق.

التخزين المؤقت الموزع باستخدام Redis درس مجاني في System Design Basics for Backend Developers على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في System Design Basics for Backend Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة System Design Basics for Backend Developers 4 دروس في المجموع.

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

What is Distributed Caching?

Imagine your app has many servers. If each server has its own 'local' cache, they don't share data. This can lead to inconsistencies or redundant data fetching.

Distributed caching solves this! It's a shared cache that all your application servers can access. Data is stored across multiple nodes in a network.

Why Redis for Caching?

Redis (REmote DIctionary Server) is a popular choice for distributed caching. It's an open-source, in-memory data store.

  • Speed: Being in-memory makes Redis incredibly fast for reads and writes.
  • Versatility: It supports various data structures, not just simple key-value pairs.
  • Simplicity: Easy to use and integrate into existing systems.

Redis Data Model: Keys & Values

At its core, Redis stores data as key-value pairs. Think of it like a dictionary or a hash map. Each unique key points to a specific value.

  • Keys: Usually strings, used to retrieve data.
  • Values: Can be strings, lists, hashes, sets, and more.

This simple model allows for very fast lookups.

Connecting Your App to Redis

To use Redis, your application needs a client library. Most programming languages (Java, Python, Node.js, etc.) have well-supported Redis clients.

These clients handle the network communication, allowing your app to send commands to the Redis server and receive responses seamlessly.

Adding Data with SET

The most basic command to store a string value is SET. You provide a key and the value you want to store. Try running this in a Redis CLI:

SET user:1:name "Alice Smith"

Retrieving Data with GET

Once data is stored, you can retrieve it using the GET command, specifying the key. This is how your application would fetch cached data.

GET user:1:name

Expiring Data with TTL

Cache data shouldn't live forever! Redis allows you to set a Time-To-Live (TTL) for keys. After this duration, Redis automatically deletes the key.

Use EX (seconds) or PX (milliseconds) with your SET command.

SET product:101:price 49.99 EX 3600

Updating & Deleting Data

You can update a key's value by simply calling SET again with the same key. To remove a key and its value entirely, use the DEL command.

This is crucial for cache invalidation when the source data changes.

SET user:1:name "Alice J. Smith"
DEL product:101:price

Beyond Strings: Other Data Types

Redis isn't just for simple strings! It supports rich data structures, making it powerful for various caching needs:

  • Hashes: Store objects with many fields.
  • Lists: Ordered collections of strings.
  • Sets: Unordered collections of unique strings.
  • Sorted Sets: Sets where each member has a score, allowing for ranking.

Benefits of Distributed Caching

Implementing a distributed cache like Redis brings significant advantages to your system:

  • Faster Response Times: Data is retrieved from fast memory, not slower disk.
  • Reduced Database Load: Fewer requests hit your primary database.
  • Scalability: Cache can be scaled independently of your database.
  • Shared State: Multiple application instances can access the same cached data.

Quick Check: Redis Benefits

You've learned about the power of Redis for distributed caching. Which of the following are key benefits of using a distributed cache like Redis?

Lesson Summary

Great job! You now understand the fundamentals of distributed caching with Redis.

  • Distributed caches provide a shared, fast data layer for multiple app servers.
  • Redis is an excellent in-memory key-value store for this purpose.
  • Basic commands like SET, GET, DEL, and EX are essential.
  • Redis supports various data types beyond simple strings.
  • Benefits include faster responses, reduced database load, and improved scalability.

Keep exploring Redis to unlock its full potential!

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

هل درس «التخزين المؤقت الموزع باستخدام Redis» مجاني؟

نعم — نص درس «التخزين المؤقت الموزع باستخدام Redis» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة System Design Basics for Backend Developers، انتقل إلى CoddyKit PRO. تتضمن دورة System Design Basics for Backend Developers 4 دروس في المجموع.

ماذا ستتعلم في «التخزين المؤقت الموزع باستخدام Redis»؟

طبّق حلول التخزين المؤقت الموزع باستخدام أدوات مثل Redis لمشاركة ذاكرة التخزين المؤقت بين مثيلات متعددة للتطبيق. تتمرن على System Design Basics for Backend Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ System Design Basics for Backend Developers؟

لا تُشترط خبرة سابقة. System Design Basics for Backend Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «التخزين المؤقت الموزع باستخدام Redis»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس System Design Basics for Backend Developers هذا؟

نعم. كل درس في System Design Basics for Backend Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. أنماط إبطال التخزين المؤقت
  2. تكامل CDN والتخزين المؤقت عند الحافة
  3. التخزين المؤقت الموزع باستخدام Redis
  4. سياسات طرد عناصر ذاكرة التخزين المؤقت
← العودة إلى System Design Basics for Backend Developers