Data structures and their uses
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
| Problem | Structure |
|---|---|
| Cached product JSON | String with TTL |
| Cart (field per product) | Hash |
| Users who viewed a product | Set |
| Top-selling products | Sorted 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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.