Sorted sets #
15 commands. Scores are 64-bit integers, not doubles — the one difference that changes query results, not just the wire format.
| Cmd | RW | Syntax | Returns | Example → reply |
|---|---|---|---|---|
ZADD | W | ZADD KEY score MEMBER [score MEMBER ...] | integer members added | ZADD board 100 ada 90 bob → 2 |
ZINCRBY | R ⚠ | ZINCRBY KEY increment MEMBER | bulk new score | ZINCRBY board 5 ada → 105 |
ZREM | W | ZREM KEY MEMBER [MEMBER ...] | integer members removed | ZREM board bob → 1 |
ZCARD | R | ZCARD KEY | integer cardinality | ZCARD board → 1 |
ZCOUNT | R | ZCOUNT KEY min max | integer members within the score range | ZCOUNT board 0 200 → 1 |
ZSCORE | R | ZSCORE KEY MEMBER | bulk score, null if absent | ZSCORE board ada → 105 |
ZRANK | R | ZRANK KEY MEMBER | integer rank (0-based), null if absent | ZRANK board ada → 0 |
ZREVRANK | R | ZREVRANK KEY MEMBER | integer reverse rank, null if absent | ZREVRANK board ada → 0 |
ZRANGE | R | ZRANGE KEY start stop [WITHSCORES] | array members (and scores) | ZRANGE board 0 -1 WITHSCORES → [ada, 105] |
ZREVRANGE | R | ZREVRANGE KEY start stop [WITHSCORES] | array members (and scores) | ZREVRANGE board 0 0 → [ada] |
ZRANGEBYSCORE | R | ZRANGEBYSCORE KEY min max [WITHSCORES] | array members (and scores) | ZRANGEBYSCORE board 100 200 → [ada] |
ZREVRANGEBYSCORE | R | ZREVRANGEBYSCORE KEY max min [WITHSCORES] | array members (and scores) | ZREVRANGEBYSCORE board 200 100 → [ada] |
ZREMRANGEBYRANK | R ⚠ | ZREMRANGEBYRANK KEY start stop | integer members removed | ZREMRANGEBYRANK board 0 0 → 1 |
ZREMRANGEBYSCORE | R ⚠ | ZREMRANGEBYSCORE KEY min max | integer members removed | ZREMRANGEBYSCORE board 0 50 → 0 |
ZCLEAR | W | ZCLEAR KEY | integer members removed | ZCLEAR board → 1 |
Notes #
- ⚠
ZINCRBY,ZREMRANGEBYRANKandZREMRANGEBYSCOREare registered as read commands even though they mutate. Locally that is harmless; in a cluster their effect is not replicated and does not survive a leader change. Until that is fixed: compute scores client-side and write them withZADD, and remove members withZREM. - No TTL for sorted sets. There is no
ZEXPIRE/ZTTL; clear and recreate the key (ZCLEAR), or keep the expiry bookkeeping in a string key. - Scores parse as
int64. A float score such as1.5is rejected;WITHSCORESreturns integers. ZRANGEBYSCORE min maxis inclusive on both ends;ZREVRANGEBYSCORE max mintakes the arguments in reverse order, as in Redis.ZRANK/ZREVRANKanswernullfor a missing member,ZSCORElikewise.- All range reads are ordered by score, then by member for equal scores.