Cache database-redis data types and operations (sorted set)

Source: Internet
Author: User

One: Redis ordered set (sorted set)

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).

Second: The orderly set of common operations

1) zadd (name, *args, **kwargs) Add elements to the ordered collection of name

2) Zcard (name) Gets the number of ordered collection elements for name

3) Zcount (name, Min, max) gets the number of points in the ordered collection of name corresponding to [Min,max]

4) Zincrby (name, value, amount) the name corresponding to the ordered collection of the name corresponding to the score

5) Zrange (name, start, end, Desc=false, Withscores=false, score_cast_func=float) Gets the element of the ordered collection of name corresponding to the index range

    # 参数:

     # name,redis的name      # start,有序集合索引起始位置(非分数)      # end,有序集合索引结束位置(非分数)      # desc,排序规则,默认按照分数从小到大排序      # withscores,是否获取元素的分数,默认只获取元素的值      # score_cast_func,对分数进行数据转换的函数6) Zrank (name, value) gets the rank of a value in the ordered set of name (starting from 0) 7) zrem (name, values) removes the value of the ordered collection of name corresponding to the member of Values 9) Zremrangebyrank (NA   Me, Min, max) Zremrangebyscore (name, Min, max) is deleted according to the range of fractions) Zscore (name, value) gets the fraction of the name corresponding to the value in the Ordered collection Zinterstore (dest, keys, Aggregate=none) gets the intersection of two ordered sets, and if different fractions of the same value are encountered, operate according to aggregate (Zunionstore, keys, Aggregate=none) Gets the set of two ordered sets and, if a different score of the same value is encountered, operates according to aggregate) Zscan (name, cursor=0, Match=none, Count=none, Score_cast _func=float)

Cache database-redis data types and operations (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.