redis SortedSet type command

Sorted Set in Redis is an ordered, non-repeating data structure. Each member of the Sorted Set is associated with a score, by which the members can be sorted. Here are some common commands for the Sorted Set type in Redis:

  1. ZADD key [NX|XX] [CH] [INCR] score member [score member …] : Add one or more members to the ordered set and specify the corresponding score.

    Example:ZADD mysortedset 1.5 member1 2.0 member2

    Optional parameters:

    • NX : Only added if the member does not exist.
    • XX : Only updated if the member already exists.
    • CH : Returns the updated number of members.
    • INCR : Increment the member by increasing the specified score.
  2. ZCARD key : Get the number of members in the ordered set.

    Example:ZCARD mysortedset

  3. ZSCORE key member : Get the score of the specified member in the ordered set.

    Example:ZSCORE mysortedset member1

  4. ZINCRBY key increment member : Increase the score of the specified member in the ordered set and return the increased score.

    Example:ZINCRBY mysortedset 2.5 member1

  5. ZREM key member [member …] : Remove one or more members from an ordered set.

    Example:ZREM mysortedset member1 member2

  6. ZRANK key member : Get the ranking (from low to high) of the specified member in the ordered set.

    Example:ZRANK mysortedset member1

  7. ZREVRANK key member : Get the ranking (from high to low) of the specified member in the ordered set.

    Example:ZREVRANK mysortedset member1

  8. ZRANGE key start stop [WITHSCORES] : Get the members in the ordered set according to the ranking range.

    Example:ZRANGE mysortedset 0 2 WITHSCORES

  9. ZREVRANGE key start stop [WITHSCORES] : Get the members of the ordered set according to the ranking range (reverse order).

    Example:ZREVRANGE mysortedset 0 2 WITHSCORES

  10. ZCOUNT key min max : Get the number of members in the ordered set whose scores are within the specified range.

    Example:ZCOUNT mysortedset 1 3

Guess you like

Origin blog.csdn.net/drhnb/article/details/132178166