tencent cloud

Tencent Cloud Distributed Cache (Redis OSS-Compatible)

Sorted Sets Group

Download
Modo Foco
Tamanho da Fonte
Última atualização: 2026-08-11 11:11:58
Traduzido por IA

Command Introduction

The Sorted Sets command family is used to operate on unique member collections sorted by score. It serves as the core data structure for scenarios such as leaderboards, priority queues, and latency task scheduling. Based on their features, its core commands can be categorized into the following five types:
Add/Remove Members and Score Operations
ZADD: Adds a member and its score (supports NX/XX/GT/LT conditions).
ZREM / ZREMRANGEBYRANK / ZREMRANGEBYSCORE / ZREMRANGEBYLEX: removes members by member name, rank range, score range, or lexicographical range.
ZINCRBY: atomically increments a member's score, making it suitable for real-time leaderboard scoring.
Rank and Score Queries
ZSCORE / ZMSCORE: queries the score of a single member or multiple members.
ZRANK / ZREVRANK: queries the ascending/descending rank of a member.
ZCARD / ZCOUNT / ZLEXCOUNT: counts the total number of members, the number of members within a score range, or the number of members within a lexicographical range.
ZRANDMEMBER: returns a member randomly.
Range Search
ZRANGE / ZREVRANGE / ZRANGEBYSCORE / ZREVRANGEBYSCORE / ZRANGEBYLEX / ZREVRANGEBYLEX: searches for members by rank, score, or lexicographical range, and supports pagination (LIMIT).
ZRANGESTORE: stores the range search result into a new key.
ZSCAN: iterates incrementally using a cursor.
Operations Between Sets
ZUNIONSTORE / ZINTERSTORE: computes the union or intersection and stores the result into a new key (supports WEIGHTS and AGGREGATE).
ZDIFF / ZDIFFSTORE / ZINTER / ZUNION: directly returns the difference, intersection, or union result.
ZINTERCARD: quickly counts the cardinality of an intersection.
Pop Operations (Queue Scenario, Redis 5.0+ / Valkey 8.0+)
ZPOPMIN / ZPOPMAX: pops the member with the lowest/highest score.
BZPOPMIN / BZPOPMAX: performs a blocking pop.
ZMPOP / BZMPOP (Redis 7.0+): pops in batches from multiple keys, suitable for latency queue consumption and priority scheduling.
For more information, see the Valkey official documentation: Sorted Set Command Group.

Command Support Overview

Basic Commands: zadd, zcard, zcount, zincrby, zinterstore, zlexcount, zrange, zrangebylex, zrangebyscore, zrank, zrem, zremrangebylex, zremrangebyrank, zremrangebyscore, zrevrange, zrevrangebylex, zrevrangebyscore, zscore, zrevrank, zscan, zunionstore. These commands are supported by the standard architecture of Redis versions 2.8, 4.0, 5.0, 6.2, and 7.0, as well as the standard and cluster architectures of Valkey versions 8.0 and 9.0.
Commands Added in Version 5.0+: zpopmax, zpopmin, bzpopmax, bzpopmin. These commands are supported only by Redis versions 5.0, 6.2, and 7.0, and Valkey versions 8.0 and 9.0.
Commands Added in Version 6.2+: zdiff, zdiffstore, zrandmember, zrangestore, zunion, zmscore, zinter. These commands are supported only by Redis versions 6.2 and 7.0, and Valkey versions 8.0 and 9.0.
Commands Added in Version 7.0+: zmpop, bzmpop, zintercard. These commands are supported only by Redis version 7.0, and Valkey versions 8.0 and 9.0.
Cross-Slot Restriction: In a cluster architecture, zinterstore and zunionstore do not support cross-slot operations.

Command Compatibility Matrix

The support status of Sorted Set family commands across different versions and architectures is shown in the table below (✓ indicates supported, ✗ indicates not supported, and — indicates that the command does not involve a cross-slot access scenario).
Command
Valkey 9.0 Standard Architecture
Valkey 9.0 Cluster Architecture
Redis 7.0/Valkey 8.0 Standard Architecture
Redis 7.0/Valkey 8.0 Cluster Architecture
Redis 6.2 Standard Architecture
Redis 6.2 Cluster Architecture
Redis 5.0 Standard Architecture
Redis 5.0 Cluster Architecture
Redis 4.0 Standard Architecture
Redis 4.0 Cluster Architecture
Redis 2.8 Standard Architecture
Cluster Architecture Support for Cross-Slot
zadd
zcard
zcount
zincrby
zinterstore
zlexcount
zrange
zrangebylex
zrangebyscore
zrank
zrem
zremrangebylex
zremrangebyrank
zremrangebyscore
zrevrange
zrevrangebylex
zrevrangebyscore
zscore
zrevrank
zscan
zunionstore
zpopmax
zpopmin
bzpopmax
bzpopmin
zdiff
zdiffstore
zinter
zrandmember
zrangestore
zunion
zmscore
zmpop
bzmpop
zintercard

Ajuda e Suporte

Esta página foi útil?

comentários