6. Basic Redis commands-ordered set, redis command-Set

Source: Internet
Author: User

6. Basic Redis commands-ordered set, redis command-Set
1. Ordered Sets are implemented by hash tables and skip tables. Therefore, even if there are more elements, the process of retrieving intermediate elements is fast.
2. An ordered set associates a score with each element in the set.
3. Comparison between Ordered Sets and lists:
They are all ordered and can get different elements in a specific range. 1. The list is implemented using a two-way linked list. Therefore, it is very fast to obtain data close to both ends, and it will be very slow to obtain intermediate data. 2. Ordered Sets use hash and skip tables (which are easy to understand by Baidu). 3. The position of an element cannot be adjusted in the list, but the set can be changed by changing the score. 4. Ordered Sets consume more memory.
4. Add the ZADD element and return the number of newly added elements (excluding existing ones) 127.0.0.1: 6379> ZADD eng_score 85 klov 90 klov2 100 klov3 (integer) 3. If the element already exists, the original score is replaced with the new score, and the returned data is 0 127.0.0.1: 6379> ZADD eng_score 99 klov.
(Integer) 0
127.0.0.1: 6379> ZSCORE eng_score klov
"99"

5. ZSCORE score 127.0.0.1: 6379> ZSCORE eng_score klov
"88"
6. The score not only supports positive numbers, but also floating-point numbers.
7. Obtain the list of elements in a certain range in the ZRANGE key start stop [WITHSCORES] ------------ Ascending Order ZREVRANGE key start stop [WITHSCORES] -------- descending order score from small to large (large to small) returns all the elements (including data at both ends) between the start and stop of the index ). Similar to the LRANGE command, the index starts from 0, and the negative number indicates the forward query (-1 indicates the last element, so ZRANGE key 0-1 is used to retrieve all elements) 127.0.0.1: 6379> ZRANGE eng_score 0-1 WITHSCORES 1) "klov2"

2) "90"
3) "klov"
4) "99"
5) "klov3"
6) "100" if the scores of the two elements are the same, 127.0.0.1: 6379> ZRANGE eng_score 0-1 WITHSCORES will be returned in alphabetical order.
1) "klov2"
2) "90"
3) "klov"
4) "99"
5) "angla"
6) "100"
7) "klov3"
8) "100"
8. Obtain the element ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] in the specified range. The obtained elements include min and max at both ends. if you do not need the two ends, run: 127.0.0.1: 6379> ZRANGEBYSCORE eng_score (60 (100 1) "klov2"
2) "klov"
It also supports infinity:-inf + inf

9. Add an element score: ZINCRBY key increment member returns the added value 127.0.0.1: 6379> ZINCRBY eng_score 50 klov3
"150"













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.