Usage of redis sortedset

Source: Internet
Author: User
1 first, create a sortedset. The command is as follows: The zaddmyset1000 clerk is a command to add a collection element. Zadd indicates adding myset indicates that the Set Name 1000 indicates the key, and the clerk indicates the key. Returns the elements of myset from small to large. 0-1 indicates the subscript. If it is 0-1, all are displayed. If it is a normal range, then

1 first, create a sorted set. The command is as follows: zadd myset 1000 is a command to add a collection element. Zadd indicates adding myset indicates that the Set Name 1000 indicates the key, and the clerk indicates the key. Returns the elements of myset from small to large. 0-1 indicates the subscript. If it is 0-1, all are displayed. If it is a normal range, then

1 first, create a sorted set. The command is as follows:


Zadd myset 1000 "clerk" is a command to add a collection element. Zadd indicates adding myset indicates that the Set Name 1000 indicates the key and the clerk indicates the value.

Returns the elements of myset from small to large. 0-1 indicates the subscript. If it is 0-1, all are displayed. If it is a normal range value, all values in the range of this subscript will be displayed. <Strong? Http: www.2cto.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + yOe3tbvYMC00tcTPwrHqtcTWsM67w/uzxqGjPC9wPgo8cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20140326/2014032609094024.png" alt = "\">

If you want to display the key value at the same time, you should include the withscores parameter.


If you want to use the descending order, you can use the ZREVRANGE command.


Because myset is sorted, to return the data, you only need to traverse the time complexity to O (N ). If not sorted, O (NlogN) is required)

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.