Database / REDIS
What is a Redis Sorted Set?
A Sorted Set (ZSET) stores unique members the same way a plain Set does, but pairs each member with a floating-point score, and Redis automatically keeps the whole collection ordered by that score — giving you a structure that's simultaneously a unique-membership set and an ordered ranking, without needing to re-sort anything yourself.
ZADD leaderboard 1500 "alex" ZADD leaderboard 2200 "sam" ZRANGE leaderboard 0 -1 WITHSCORES # returns members in ascending score order ZRANK leaderboard "alex" # returns alex's rank (0-indexed)
Because Redis maintains this order internally using a skip list plus a hash table, range queries by score or by rank (ZRANGE, ZRANGEBYSCORE) and rank lookups (ZRANK) are efficient even on large sets, which is exactly what makes Sorted Sets the natural fit for leaderboards, priority queues, and time-ordered event feeds where the score is often a timestamp.
More Related questions...
