Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of caching paged data by redis

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the method of caching paging data in redis. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Several ways of thinking:

Each page of data uses a key cache, which sets the expiration time, initializes when the data is requested and is not in the cache, and pageIndex and pageSize are used as part of the cache key, such as:

Key:cstm:list:$ {pageIndex} _ ${pageSize}

Value: serialization (List)

Each page of data uses a key cache. When the data is updated, actively update the data of all pages. PageIndex and pageSize are used as part of the cache key, such as:

Key:cstm:list:$ {pageIndex} _ ${pageSize}

Value: serialization (List)

Use ordered collections to cache hot spot data, sort conditions as scores, and use the command [ZRANGE key start stop [WITHSCORES]] to achieve paging effect.

Key:cstm:zset:pageList

Value: serialization (Customer)

Pros and cons analysis:

The first way: initializing the cache between data additions and deletions will occur, data duplicates, or omissions, for example, if the data is added after the first page of data cache is completed, when caching the second page of data, two pages of cached data will be duplicated

The second way: if the data is updated frequently, the cached data will be updated more frequently

The third way: this method is relatively friendly, it needs to maintain the cache while the data changes, and pay attention to pruning the list length.

This is the end of the method of caching paging data in redis. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report