How does Redis ensure data consistency with the database

How does Redis ensure data consistency with the database?

  1. Update the database first, and then update Redis. If the Reids update fails, there may still be data inconsistencies
  2. Delete the cached data in Redis first, then update the database, and query again to add the data in the database to the Reids cache. Although this solution can solve the problem in solution 1, the performance will be very low under high concurrency conditions, and However, data inconsistency will still occur.
    For example,
    thread 1 deletes the Reids cache data and is updating the database. At this time, another query is checking the database, and the old data will be updated to Reids.
  3. Delayed double deletion, the step is to delete the data in the Redis cache first, then update the data in the database, and then delete the data in Redis after a few milliseconds delay, so that even in the middle of updating the database, if the old data is queried and written to Redis Does not affect data consistency.

Guess you like

Origin blog.csdn.net/qq_42455262/article/details/128570238