Why should I use a Sorted Set for a live leaderboard in Redis?
Use a Sorted Set instead of plain string keys sorted in the app, since ZADD updates in O(log N) and ZRANGE ... REV returns the top 100 already ordered.
Tag
Caches, locks, counters and queues with Redis: using in-memory data correctly. questions under this tag, answered directly.
4 answered questions carry this tag.
Use a Sorted Set instead of plain string keys sorted in the app, since ZADD updates in O(log N) and ZRANGE ... REV returns the top 100 already ordered.
Keep the invariant in the DB with an atomic UPDATE ... WHERE balance >= 40 or a SELECT ... FOR UPDATE, and save Redlock for non-DB resources.
Per-IP limits lose to rotating proxies, so key the Redis sliding-window on account + IP + ASN, add account lockout and leave volumetric floods to the edge.
A single-flight lock plus TTL jitter covers most cases; reach for XFetch only when recompute is truly expensive, and add stale-while-revalidate either way.