1. Add with score
ZADD inserts a member with a float score, keeping the set ordered by that score.
ZADD board 100 "ada"Typorithm · medium
Step 1 of 8 · intro card
Data Types
A Redis sorted set keeps members ordered by a float score, making it the natural structure for leaderboards where rank follows the score.
A sorted set (zset) stores unique members each paired with a float score, and Redis keeps them ordered by that score. ZADD inserts a member with its score.
ZINCRBY adds to an existing member's score atomically — here bumping bob by 5. ZRANGE board 0 -1 returns members in ascending score order, and WITHSCORES includes each score alongside the member.
Rank queries make leaderboards trivial: ZREVRANK returns a member's position counting from the top (highest score = rank 0), so you can show where a player stands instantly.
Members are ordered by a float score.
ZADD adds; ZINCRBY bumps a score.
ZREVRANK gives rank from the top.
ZADD board 100 "ada"
ZADD board 80 "bob"
ZINCRBY board 5 "bob"
ZRANGE board 0 -1 WITHSCORES
ZREVRANK board "ada"Connect each part of the code to the concept before you type.
ZADD inserts a member with a float score, keeping the set ordered by that score.
ZADD board 100 "ada"Each member has its own score; bob enters with 80, ranking below ada's 100.
ZADD board 80 "bob"ZINCRBY adds to a member's existing score, here raising bob from 80 to 85.
ZINCRBY board 5 "bob"ZRANGE returns members by ascending rank; WITHSCORES appends each member's score.
ZRANGE board 0 -1 WITHSCORESZREVRANK gives a member's 0-based position counting from the highest score down.
ZREVRANK board "ada"Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.