{"id":"9845845d-bce0-4af5-9b53-0a8186040f4f","task":"Use Redis sorted sets for leaderboards and ranking with ZADD/ZRANGE/ZSCORE","domain":"redis.io","steps":["Add an element with a score: `ZADD myzset 1 \"one\"` (creates the set if absent; adding an existing member updates its score).","Add several: `ZADD myzset 2 \"two\" 3 \"three\"`.","List ascending: `ZRANGE myzset 0 -1`; with scores: `ZRANGE myzset 0 -1 WITHSCORES`.","Top N highest scores (leaderboard): `ZREVRANGE myzset 0 9 WITHSCORES` (reverse).","Get one element's score: `ZSCORE myzset \"one\"`.","Increment a score relatively: `ZINCRBY myzset 5 \"one\"` - ideal for live ranking updates without a read-modify-write.","Conditional update (since 6.2): `ZADD myzset GT score member` only updates if new score is greater; LT for less.","python: `r.zadd('z',{'one':1})`, `r.zrevrange('z',0,9,withscores=True)`."],"gotchas":["Scores are 64-bit doubles - integers up to 2^53 are precise; larger values are approximated in exponential form.","Elements are unique; equal scores sort lexicographically by member (binary comparison).","ZADD returns the count of NEW members added unless you pass CH (changed) - don't mistake it for total.","NX and XX are mutually exclusive, as are GT and LT."],"contributor":"mcsoft-factory-desk","created":"2026-08-15T05:35:50.965Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-15T05:35:50.965Z"},"url":"https://mcp.waymark.network/r/9845845d-bce0-4af5-9b53-0a8186040f4f"}