Vi. Basic Redis Command--ordered set

Source: Internet
Author: User

1, the ordered set is by the hash list and the jumping table realizes, so even if the element is many, obtains the intermediate element speed also quickly.
2. An ordered set is associated with a fraction for each element in the collection.
3. Comparison of ordered sets and listsSame point:
are all ordered and can get a certain range of elements     different points:1, the list is implemented by two-way linked lists, so get close to both ends of the data quickly, get intermediate data will be very slow. 2, the orderly set is the use of a hash table and jumping tables (Baidu good understanding)3. The position of an element cannot be adjusted in the list, but the collection can, by changing the score. 4, ordered collection more memory-intensive
4, Zadd add elements, return the number of new additions (not included)127.0.0.1:6379> zadd eng_score Klov klov2(integer) 3if the element already exists, it replaces the original score with the new score, returning the data 0127.0.0.1:6379> Zadd Eng_score Klov
(integer) 0
127.0.0.1:6379> Zscore Eng_score Klov
"99"

5. Zscore gets the fraction of the element127.0.0.1:6379> Zscore Eng_score Klov
" the"
6, the score not only supports positive numbers, but also supports floating-point numbers
7. Get a list of elements ranked within a rangezrange key start stop [Withscores]------------order from small to largezrevrange key start stop [Withscores]--------order from large to smallreturns all elements of the index from start to stop (containing data at both ends) in order of fractions from small to large (large to low). Similar to the Lrange command, the index starts at 0, and the negative number represents a forward lookup (-1 for the last element, so Zrange key 0-1 is to get all the elements)127.0.0.1:6379> zrange eng_score 0-1 withscores1) "Klov2"
2) "
All in All"
3) "Klov"
4) "
the"
5) "Klov3"
6) " the"If two elements have the same score, they are returned in dictionary order127.0.0.1:6379> zrange eng_score 0-1 withscores
1) "Klov2"
2) "
All in All"
3) "Klov"
4) "
the"
5) "Angla"
6) "
the"
7) "Klov3"
8) " the"
8. Get the specified range of elementszrangebyscore key min Max [withscores] [LIMIT offset count]Gets the element that contains both the Min and max. If you do not need both ends to execute:127.0.0.1:6379> zrangebyscore Eng_score (1) "Klov2"
2) "Klov"
also supports infinity:-inf +inf

9. Increase the score of an element: Zincrby key Increment member returns the added value127.0.0.1:6379> Zincrby Eng_score Klov3
"150"













Vi. Basic Redis Command--ordered 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.