Skip to content
Ameen Abozaid
Planned lessonMID-038-L06

Demo: a leaderboard with sorted sets

  • Lesson 6 of 7
  • Mid-level
On This Lesson 3 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

build a "top products this week" board. Prepares the data-structure selection scenarios.

Draft outline details

Step by step

  1. Create key shop:top:week:2026-W44 and record sales with ZINCRBY key 1 productId.
  2. Read the top 10 with ZRANGE key 0 9 REV WITHSCORES.
  3. Wrap it in a Spring StringRedisTemplate.opsForZSet() service.
  4. Set EXPIRE of two weeks so old boards disappear.
  5. Planned mistake: store the board as a JSON string and rewrite it on each sale; two concurrent sales overwrite each other. Fix: ZINCRBY, which is atomic.
  6. Show rank lookup with ZREVRANK.

Check your understanding

Why is ZINCRBY better than read-modify-write?

Show answer

It is atomic; no lost updates.

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.