Redis ordered set (sorted set)

Source: Internet
Author: User

A Redis ordered collection is a collection of elements of type string, as well as a collection, and does not allow duplicate members.

The difference is that each element is associated with a double-type fraction. Redis is a small-to-large ordering of the members in a collection by fractions.

The members of an ordered collection are unique, but fractions (score) can be duplicated.

The collection is implemented by a hash table, so the complexity of adding, deleting, and finding is O (1). The maximum number of members in the collection is 232-1 (4294967295, each of which can store 40多亿个 members).

Instance
  1. Redis 127.0. 0.1:6379> zadd w3ckey 1 redis
  2. (integer) 1
  3. Redis 127.0. 0.1:6379> zadd w3ckey 2 mongodb
  4. (integer) 1
  5. Redis 127.0. 0.1:6379> zadd w3ckey 3 mysql
  6. (integer) 1
  7. Redis 127.0. 0.1:6379> zadd w3ckey 3 mysql
  8. (integer) 0
  9. Redis 127.0. 0.1:6379> zadd w3ckey 4 mysql
  10. (integer) 0
  11. Redis 127.0. 0.1:6379> zrange w3ckey 0 withscores
  12. 1) "Redis"
  13. 2) "1"
  14. 3) "MongoDB"
  15. 4) "2"
  16. 5) "MySQL"
  17. 6) "4"

In the above example we add three values to the ordered set of Redis and associate the scores with the command Zadd .

Redis ordered Collection command

The following table lists the basic commands for the Redis ordered collection:

Serial Number Command and Description
1 Zadd key Score1 member1 [Score2 member2] adds one or more members to an ordered collection, or updates the fraction of an existing member
2 Zcard Key gets the number of members of an ordered collection
3 Zcount Key min Max calculates the number of members that specify interval fractions in an ordered set
4 Zincrby key increment member a specified member's score plus an increment in an ordered collection increment
5 Zinterstore destination Numkeys key [key ...] computes the intersection of one or more ordered sets given and stores the result set in the new ordered collection key
6 Zlexcount Key min Max calculates the number of members within a specified dictionary interval in an ordered set
7 Zrange key start stop [Withscores] returns an ordered set of members within a specified range by an index interval
8 Zrangebylex key min Max [LIMIT offset Count] Returns the members of an ordered collection through a dictionary interval
9 Zrangebyscore key min Max [withscores] [LIMIT] Returns the members of an ordered set in a specified range by fractions
10 Zrank Key member returns the index of the specified member in the Ordered collection
11 Zrem key member [member ...] removes one or more members from an ordered collection
12 Zremrangebylex key min Max removes all members of the given dictionary interval in the ordered collection
13 Zremrangebyrank key Start stop removes all members of the given rank range in the ordered collection
14 Zremrangebyscore key min Max removes all members of a given fractional interval in an ordered collection
15 Zrevrange key start stop [Withscores] returns the member within the specified interval of an ordered set, through the index, the score from the high end
16 Zrevrangebyscore key Max min [Withscores] returns the members within the specified fractional interval in an ordered set, sorted from highest to lowest
17 Zrevrank Key member returns the rank of the specified member in an ordered collection, ordered set members are descending by fractional value (from large to small)
18 Zscore Key member returns the fractional value of an ordered set of members
19 Zunionstore destination Numkeys key [key ...] calculates the set of a given one or more ordered sets and stores them in a new key
20 Zscan key cursor [MATCH pattern] [count count] iterates over elements in an ordered collection (including element members and element scores)

Redis ordered set (sorted set)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.