The scheme of consistency between cached data in redis and database data

Method 1: The database saves data, and redis does not persist
. After redis is started, loading data from the database
does not require strong consistency and real-time read requests. Redis processes read requests that
require strong consistency and real-time performance, and the database handles
write requests. There are two types of processing. The method is handled by the database
- the application writes the database first, and then updates the redis
- the application writes the database first, and then other daemons synchronize to redis
Advantages: Redis startup does not need to deal with redis data and database inconsistencies
Disadvantages: Redis startup puts a lot of read pressure on the database

Mode 2: The database and redis process different data types respectively. The
database processes data that requires strong consistency and real-time, such as financial data and transaction data.

Redis handles data that does not require strong consistency and real-time, such as the most popular website rankings

 

 

 

Synchronization of Redis and MySQL data can be roughly done at the code level:
read: read redis->no, read MySQL- >write mysql data back to redis
write: write mysql->success, write redis

 

 

Concurrency is not high:
read: read redis->no, read mysql->write mysql data back to redis, if there is any, directly fetch from redis;
write: write mysql->success, then write redis;

high concurrency :
read: read redis->no, read mysql->write mysql data back to redis, if there is any, directly fetch it from redis;
write: asynchronous, write to the redis cache first, then return directly; regular or specific actions will Data is saved to mysql, which can be updated multiple times and saved once;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326805322&siteId=291194637