Questions about loading to Redis when data is not in the database after Redis restart

Source: Internet
Author: User
Tags redis

Now the project uses Redis, which greatly improves the efficiency of data extraction, but if the logic is handled carelessly, it will give itself a pit

1. Completely rely on REDIS data provided in the background, when the Redis occupancy rate is high when the reboot (generally not landed), data loss.

When the data has not been loaded from the database to Redis, and there is new data to write at this time, when the cache is read again, the cache exists and is displayed directly. Causes the displayed data to be incorrect

There are two ways to solve this problem:

Pre-loading at the main entrance to solve the problem of Redis restart, but when there is no data to be cached, it will cause frequent sweep of the library

When inserting the data when Zadd, do exists key existence judgment, only in the case of the existence of the cache is added. When used, the full load is done


2. In some scenarios, you can determine whether the data is displayed based on the cache. It is best to deal with the non-display, only the content, not clear its key, with the content to determine whether the display.

Otherwise, do not display the case of deleting key, resulting in key does not exist, and large-scale sweep of the database, to the database pressure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.