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

How to realize the automatic launch of real-time page update by redis

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how redis can automatically launch real-time page updates. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Requirement description

Some pages need to be configured with advertisements or campaign maps, and advertisements or events need to be online at any time, automatically offline after expiration, and automatically online at that time.

For example, the current time is 2019-2-22 16:16:13, the award-receiving activity should be configured on the payment completion page, the activity should be launched on time at 00:00:00 on 2019-3-10, and the activity will end at 23:59:59 on 2019-3-30.

So the desired effect is that after the activity is configured at any time before the event goes online, the activity will be launched automatically at the time of the page. It may also be other multiple activities or advertisements, the number of advertisements on each page is variable, different online and offline time can be different, other pages also need to achieve this function, the activities between the page and the page are not necessarily the same.

Demand analysis

Need a few simple words, so let's analyze it in detail.

Extract keywords

Advertising or event promotional map

Go up and down at any time, automatically go offline after expiration, and go online automatically when it arrives.

The number of ads per page is variable.

The time of going online is different for different advertisements.

The activity between the page and the page is not necessarily the same

Database analysis

1. [advertising or event promotional map]

To set up different advertisements for different pages, some page ads may be the same, that is, advertisements will be reused, and all must have advertising tables.

2. [the number of advertisements per page is variable] [the online and offline time of different advertisements may be different] [the activities between pages are not necessarily the same]

The page can be configured with multiple advertisements, all of which must have a page configuration table, as well as the relationship table between the advertisement and the page, that is, the page advertisement table.

The page configuration table mainly configures the number of advertisements on the page to achieve [variable number of ads on each page], and the page advertisement table mainly configures the time for each advertisement to go online and offline on the page, and realizes that [the time for different advertisements can be different]

After simple analysis, the table structure is as follows: advertisement table adv, page configuration table page_config, page advertisement table page_adv.

Thinking

The advertisements configured on these pages will not change for a period of time. If there are more page requests, the number of ad queries will be very frequent, causing unnecessary pressure on the database. Therefore, caching can be introduced to reduce the number of database requests and alleviate the pressure on the database. The Redis used here.

When is it cached?

You can choose to asynchronously load the advertisements that have been in the online and offline time range to the cache when the service is started, or choose to take the cache when the request is made, and then check the database when it is not in the cache and then put it into the cache. Cache time depends on the situation.

The choice here is that when the project starts, asynchronously store the qualified page advertising configuration information into Redis, those who have not yet reached the specified time do not put Redis, wait until the visiting page loads ads, first check Redis, if not, then check the database according to the condition (> = nowtime), and find the Redis later.

After getting the ad configuration information in the API, determine whether the current time is within the configured time range. Since multiple advertisements are configured on a page, different ad times are also different, so iterate to return those that match, mark those that have expired, and then delete the configuration information of the entire page in Redis. (or do not choose to load at startup, just add the cache when the user requests it, but the method in step 1 below will be used when refreshing the load, so it cannot be deleted.)

Step 1: save the page advertisement configuration information into Redis when the project starts.

A. Query all pageId

SELECT pageId FROM page_config page_adv WHERE nowtime

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

Internet Technology

Wechat

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

12
Report