Home > Database > Redis > body text

How redis caches paging data

(*-*)浩
Release: 2019-11-28 10:34:56
Original
6503 people have browsed it

We often need to cache data that needs paging in our projects. There are several ideas as follows. Let’s compare the advantages and disadvantages of each

How redis caches paging data

## An idea:

Each page of data uses a key cache, and sets the expiration time respectively. It is initialized when the data is requested and is not in the cache. PageIndex and pageSize are used as part of the cache key, for example: (Recommended learning: Redis video tutorial)

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

value: serialization (List)


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

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

value: serialization (List)

Use ordered sets to cache hotspot data, sort conditions as scores, and use the command [ZRANGE key start stop [WITHSCORES]] to achieve paging effects

key: cstm:zset:pageList

value: Serialization (Customer)


Analysis of advantages and disadvantages:

The first method: initialize between data addition and deletion Caching will cause data duplication or omission. For example: after the first page of data is cached, if there is new data, when the second page of data is cached, the cached data of the two pages will be duplicated

Second The first method: If the data is updated frequently, the cached data will be updated more frequently.

The third method: This method is relatively friendly. You need to maintain the cache while the data changes, and pay attention to trimming the list length

For more Redis-related technical articles, please visit the

Redis Getting Started Tutorial column to learn!

The above is the detailed content of How redis caches paging data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!