Skip to content
Ameen Abozaid
Planned lessonMID-038-L02

Data structures and their uses

  • Lesson 2 of 7
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

pick the right structure for each problem.

Planned topics

  • String: a value or counter; SET, GET, INCR, SET key v EX 60. Use for cached JSON and counters.
  • Hash: field-value map under one key; HSET, HGET. Use for objects you update field by field.
  • Set: unique members; SADD, SISMEMBER. Use for tags, "who liked this".
  • Sorted set: members with a score, ordered; ZADD, ZRANGE, ZINCRBY. Use for leaderboards and time-ordered indexes.
  • Expiration applies to the whole key, not to a hash field or set member.
Draft outline details

Demonstration

ProblemStructure
Cached product JSONString with TTL
Cart (field per product)Hash
Users who viewed a productSet
Top-selling productsSorted set

Check your understanding

Which structure gives "top 10 by score" cheaply?

Show answer

Sorted set: ZREVRANGE/ZRANGE ... REV.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.