Redis Paging Query Comprehension

Source: Internet
Author: User

Accidentally found an interface in the code, the interface definition is paged query, but the logical implementation is redis. Don't quite understand, how does Redis split pages? Later I saw an article, and then I learned it.

1, Zrevrange realization

The SortedSet zrevrange topicid (page-1) x10 (page-1) x10+perpage directive enables paging functionality.

Redis zrevrange Command-Returns the member within the specified interval of an ordered set, indexed by the score from high to the end.
Reference: Redis Zrevrange Command _ Returns the members within the specified interval of an ordered set, through the index, the score from the high end

Note: The command value following the Zrevrange command is the index value. So there's no problem.

2, Zrevrangebyscore command implementation

In addition, the Zrevrangebyscore command is used in our code.

This command should only guarantee that the page range is consistent, do not omit the data, but there is no guarantee that the total number of pages per page must be.

It is generally not appropriate to use a page-by-page approach to how many pages of data are traditionally used for waterfall streams or to comment on how dynamically loaded data.

Note: The command value following the Zrevrangebyscore command is the fractional value. So there are inconsistencies in the total number of data.

Question: Why do we use the Zrevrangebyscore command in our code? It doesn't feel good.

3. Reference:
  1. Pagination sorting query in Redis | Niuniu ' s Blog
    http://liu-xin.me/2015/11/17/%E5%9C%A8Redis%E4%B8%AD%E8%BF%9B%E8%A1%8C%E5%88%86%E9%A1%B5%E6%8E%92%E5%BA%8F%E6% 9f%a5%e8%af%a2/

Redis Paging Query Comprehension

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.