When Redis is used as a distributed cache, how do you solve the problem of data update?

redis as a cache feature has many advantages, which can ease the pressure on the server
first determine whether there is any in the cache. If not, check DB
, then directly use
. What if DB is updated? Isn"t the data in redis just the old dirty data?

Jan.08,2022

immediately update the redis cache data after updating the redis data. You can use message queuing and other methods to update the cache immediately, add a timeout elimination, and set the expiration time for the cache. If there is a problem with the active update, the dirty data will also be expired and deleted.


1. After the new DB, you can directly let the cache expire. The next query will check the database first, and then save it to redis.
2. Use queues to update asynchronously.

Menu