Redis-sort Set

Source: Internet
Author: User

Ordered collection

Sorted set and set are also collections of elements of type string, but each element is associated with a double type of score. The implementation of the sorted set is a mix of skip list and hash table when the element is added to the collection, an element to the score map is added to the hash table, so the cost of getting the score for a given element is O (1), Another score-to-element mapping is added to the skip list and sorted by score, so the elements in the collection can be ordered sequentially. Add, the cost of the delete operation is the same as the cost of O (log (N)) and skip list, and the Redis skip list implementation uses a doubly linked list so that the elements can be taken from the tail in reverse order. The most common use of sorted set is to use it as an index. We can store the fields to be sorted as score, the object's ID when the element is stored.

The following is the sorted set-related command:

Zadd Key Score Member

Adds an element to the collection, the element exists in the collection, and updates the corresponding score

Zrem Key Member

Deletes the specified element, 1 indicates success, if the element does not exist return 0

Zincrby Key INCR Member

Increase the score value of the corresponding member, then move the element and keep the skip list in order. Returns the updated score value

Zrank Key Member

Returns the rank (subscript) of the specified element in the collection, in which the elements are sorted by score from small to large

Zrevrank Key Member

Ditto, but the elements in the collection are sorted by score from large to small

Zrange Key Start end

Similar to the Lrange operation to specify the elements of the interval from the collection. Returns an ordered result

Zrevrange Key Start end

Ibid., return results are in reverse order score

Zrangebyscore Key min Max

Returns the elements of a set in a given interval score

Zcount Key min Max

Returns the number of score in a set in a given interval

Zcard Key

Returns the number of elements in the collection

Zscore key Element

Returns the score corresponding to the given element

Zremrangebyrank Key min Max

Deletes an element in a collection that is ranked in a given interval

Zremrangebyscore Key min Max

Deletes an element in a collection that score at a given interval


Redis-sort 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.