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:
- 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