هياكل البيانات الأساسية في Redis
افهموا هياكل Strings وHashes وLists وSets وSorted Sets وطبّقوها لتلبية احتياجات نمذجة البيانات المختلفة.
هياكل البيانات الأساسية في Redis درس مجاني في 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 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Redis Data Types & Strings
Redis offers real data structures, not just plain keys. We start with Strings: a value up to 512 MB holding text, JSON, or binary — like a persistent variable.
Strings: Set & Get
Store and read a String with SET and GET. The code below sets a couple of keys and fetches them back.
SET mykey "Hello CoddyKit!"
GET mykey
SET user:1:name "Alice"
GET user:1:nameHashes: Store Objects
Redis Hashes are like objects: many field-value pairs under one key. Perfect for modeling things like a user profile with several attributes.
Hashes: HSET & HGETALL
Use HSET to set fields in a hash, HGETALL to read them all, and HGET for a single field. The code below builds and reads a user hash.
HSET user:1 name "Alice" email "alice@example.com" age 30
HGETALL user:1
HGET user:1 nameLists: Ordered Collections
Redis Lists are ordered string collections — push or pop from either end. Great for queues, stacks, and recent-activity feeds that keep insertion order.
Lists: LPUSH & LRANGE
LPUSH adds to the head, RPUSH to the tail, and LRANGE reads a range (0 -1 means everything). The code below pushes and lists items.
LPUSH mylist "task A" "task B"
RPUSH mylist "task C"
LRANGE mylist 0 -1
LPOP mylist
LRANGE mylist 0 -1Sets: Unique Items
Redis Sets are unordered collections of unique strings — duplicates are silently ignored. Ideal for unique visitors, tags, or friendships.
Sets: SADD & SMEMBERS
SADD adds members (dupes ignored), SMEMBERS lists them all, and SISMEMBER checks membership. The code below demonstrates all three.
SADD unique_users "user:101" "user:102" "user:101"
SMEMBERS unique_users
SISMEMBER unique_users "user:102"Sorted Sets: Ranked Data
Redis Sorted Sets pair each unique member with a score and keep them ordered by it — perfect for leaderboards, rankings, and priority queues.
Sorted Sets: ZADD & ZRANGE
ZADD adds scored members, ZRANGE reads a range (add WITHSCORES to see scores), and ZSCORE gets one member's score. See the code below.
ZADD leaderboard 100 "PlayerA" 150 "PlayerB" 75 "PlayerC"
ZRANGE leaderboard 0 -1 WITHSCORES
ZSCORE leaderboard "PlayerB"Data Structure Challenge
Imagine you need to store a list of unique product tags for an item, and you don't care about their order. Which Redis data structure is best suited for this?
Recap: Structures Mastered
Recap: Redis data structures — Strings for basics, Hashes for objects, Lists for ordered queues, Sets for unique items, Sorted Sets for ranked data.
الأسئلة الشائعة
هل درس «هياكل البيانات الأساسية في Redis» مجاني؟
نعم — نص درس «هياكل البيانات الأساسية في Redis» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Redis Caching & Messaging (Pub/Sub, Streams)، انتقل إلى CoddyKit PRO. تتضمن دورة Redis Caching & Messaging (Pub/Sub, Streams) 4 دروس في المجموع.
ماذا ستتعلم في «هياكل البيانات الأساسية في Redis»؟
افهموا هياكل Strings وHashes وLists وSets وSorted Sets وطبّقوها لتلبية احتياجات نمذجة البيانات المختلفة. تتمرن على Redis Caching & Messaging (Pub/Sub, Streams) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Redis Caching & Messaging (Pub/Sub, Streams)؟
لا تُشترط خبرة سابقة. Redis Caching & Messaging (Pub/Sub, Streams) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «هياكل البيانات الأساسية في Redis»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Redis Caching & Messaging (Pub/Sub, Streams) هذا؟
نعم. كل درس في Redis Caching & Messaging (Pub/Sub, Streams) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مقدمة إلى Redis
- أساسيات Redis CLI
- هياكل البيانات الأساسية في Redis
- انتهاء صلاحية المفاتيح وTTL في Redis