Redis real study notes

Data security and performance guarantee

1. Persistence Options

  1. Offers two a lasting solution:
    1. Snapshot: there will be some point in the data is written to the hard disk. When you use the snapshot to persist when a server crashes, the user will be lost after the most recent snapshot generation, modification of all data
      1. If completed before created a new snapshot, Redis, systems, hardware any of the three crashes, then redis will lose all data written after the most recent snapshot.
      2. redis received when shutdown, the command will execute a save, blocking all clients, no longer execute any command sent by the client and the server shut down after the save is completed.
    2. Just append file (AOF): persistence is to perform a write operation command persisted to the hard disk.
      1. appendfsync <synchronizing frequency>
        1. always: Each command synchronized to your hard drive.
          If the use of solid state disk (SSD) storage commands to speed the way, but each store will only execute a command. It may lead to serious "write amplification" problem, resulting in reduced service life of the SSD.
        2. everysec: synchronous execution once per second.
        3. no: OS decide when to synchronize.
      2. Use of the process issue
        1. AOF file size is too large: Redis continue to execute the command, aof continue to keep order, resulting in aof the file size is increasing, resulting file size is too large.
          Solution:
          1 may be used to remove aof BGREWRITEAOF command file, the command is repeated, reducing the file size. Frequency compression may be by design, automatic compression aof file. auto-aof-rewrite-percentage (aof the document file size twice as big than the last (100%)), auto- aof-rewrite-min-size ( volume exceeds this level, compression)
        2. Data recovery is too slow: AOF because the file is too large, Redis restart when will aof file to load, the recovery time will be long data.

2. Copy

  1. Redis does not support the master-master replication , if the two redis set to master, references to each other, will lead to take a lot of processing resources and continuous attempts to communicate with each other.
  2. When the slave server with the master server to initialize the link, it will clear the data slave database, replacing the master data
  3. Master-slave chain: master server can have a lot of slave servers, slave servers can also have their own slave server, the trip from the main chain.
  4. Check if the data written to disk: 0 can be determined according to whether the attribute value of aof_pending_bio_fsync.

3. Processing system failure

  1. When a system failure, you can use redis-check-aof aof and snapshot files and check the status of redis-check-dump, and the file repair in case of need.

    1. Use redis-check-aof --fix of aof file repair. Fix: just look for incorrect or incomplete command, the first command when found error, the program will delete all commands and command error after error command.
    2. Snapshots can not be repaired because the snapshot files are compressed, remove the command error position, may cause the snapshot can not be read. The best save multiple backup files, data recovery time, to verify the contents of the snapshot file by calculating SHA1 and SHA256 hash value.
  2. Replace the Redis master server

    1. Let slave server using the save command to generate a snapshot file.
    2. Redis start the new server, load the snapshot file.

4. Transaction

  1. Pipeline: a one-time sending multiple commands, then wait for all replies appear. Reduce the number of communications with the server.

Guess you like

Origin blog.csdn.net/weixin_38608626/article/details/90898927