Case Study of Software Examination System Architecture (Redis Related Concepts)

1. Comparison of Redis and Memcache capabilities

Work MemCache Redis
type of data Simple key/value structure Rich data structures
persistence not support support
Distributed storage Client-side hash sharding/consistent hashing Multiple methods, master-slave, Sentinel, Cluster, etc.
Multi-threading support support Supported (not supported by Redis5.0 and previous versions)
Memory management Private memory pool/memory pool none
Transaction support not support Limited support
Data disaster recovery Not supported, data recovery cannot be done Supports data recovery when a disaster occurs

2. Common ways of slicing Redis clusters

Cluster slicing method Core features
Client Sharding On the client side, the hash value of the key is used to correspond to different servers.
Middleware implements sharding Between the application software and Redis, such as: Twemproxy, Codis, etc., the middleware implements routing and dispatching of services to the background Redis node.
Client-server collaborative sharding The client and server collaborate to complete sharding processing.

3. Redis distributed storage solution

Distributed storage solution Core features
Master/Slave mode One master and multiple slaves, manual switching in case of failure.
Sentinel mode There is one master and multiple slaves with sentinels. If the master node fails, a new master node will be automatically selected.
Cluster mode The cluster is divided into peer-to-peer clusters, divided into slots, and information about different slots is stored in different nodes.

4. Redis data sharding solution

Sharding scheme Sharding method illustrate
range sharding Score based on data range value Example: Sharding by user number, 0-999999 is mapped to instance A; 1000000-1999999 is mapped to instance B.
Hash sharding Sharding by hashing the key Data can be allocated to different instances, which is similar to the remainder operation. If the remainders are the same, they are placed on one instance.
Consistent hash sharding Improvements to hash sharding It can effectively solve the hit-missing problem caused by redistributing nodes.

5. Redis persistence

RDB: The idea of ​​snapshots in traditional databases. Snapshot the data at specified intervals.

AOF: The idea of ​​logs in traditional databases is to append each command that changes the data set to the end of the AOF file. If something goes wrong, you can re-execute the command in the AOF file to rebuild the data set.

Contrast Dimensions RDB persistence AOF persistence
Backup volume Heavy-duty full backup, saving the entire database Lightweight incremental backup, only saves one modified command at a time
save interval Long save interval The save interval is short, the default is 1 second
Restore speed Data restoration speed is fast Data restore speed is slow
blocking situation save will block, but bgsave or automatically will not block No matter it is normal or AOF rewriting, it will not block
Data volume Equivalent data size: small Same data volume: large
safety Data security: low, easy to lose data Data security: high, determined according to policy

Guess you like

Origin blog.csdn.net/qq_41273999/article/details/134085834