In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you the method of paging query on redis, and analyze and describe it from a professional point of view. I hope you can get something after reading this article.
Paging query caching scheme based on SortedSet
The first solution that comes to mind is to use @ see ListOperations to no longer use multiple key based on paging conditions, but to use one key, without paging to cache all the data in redis, and then use range (key,start,limit) to get the paged results according to paging conditions.
This can lead to a problem, when the cache fails, the concurrent write cache will cause duplicate data, so think of using set to deal with concurrent duplicate data, @ see ZSetOperations
The code logic is as follows:
Range (key,start,limit) acquires cache according to paging condition, and returns cache miss directly if hit. Query (no paging condition) database or call (no paging condition) underlying API add (key,valueScoreMap) to write cache. Expire sets cache time when cache needs to be cleaned, delete key directly. If data is added or deleted, you can add (key,value,score) or remove (key,value).
In redis, the data in map is arranged according to the ascending order of score score. Generally speaking, score score is the filedA value of order by filedA in sql statement, which ensures data consistency.
But there are some problems with this approach:
The value of this key cache is indeed hot data, but only a few data may be used frequently and the rest may not be used at all. For example, if the data has 100 pages, the first 10 pages may actually be used, which will also lead to a waste of cache space. If redis virtual memory is used, it will also have a certain impact.
Sql query has changed from paging query to non-paging query. After cache invalidation, the processing capacity of the system will be lower than before, especially for large tables.
The above is the method of realizing paging query in redis shared by Xiaobian. If you have similar doubts, you might as well refer to the above method to try. If you want to know more about it, please follow the industry information.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.