Study Notes: Redis Database Basics (2)

RDB synchronization mechanism:

  1. On and Off: By default it is on. If you want to turn it off, then comment out redis.confall the options in the file save.
  2. Synchronization mechanism:
    • save 900 1: If a data update operation occurs within 900s, a synchronization operation will be performed.
    • save 300 10: If 10 data update operations occur within 300s, a synchronization operation will be performed.
    • save 60 10000: If 10000 data update operations occur within 60s, a synchronization operation will be performed.
  3. Storage content: specific values, but commands. And it is stored after compression.
  4. Storage path: specified according to and redis.confbelow . The default is .dirrdbfilename/var/lib/redis/dump.rdb
  5. advantage:
    • Storing data in a file will be compressed, and the file size is smaller than aof.
    • Because the specific value of redis is stored and compressed, it is faster than AOF during recovery.
    • Great for backups.
  6. shortcoming:

    • The RDB will start the synchronization mechanism when there are many write operations in a certain period of time. Because the compression mechanism is adopted, the RDB will re-save the data in the entire Redis during synchronization, so you generally set it to save the data once at least 5 minutes . In this case, once the server fails, 5 minutes of data will be lost
      .
    • When data is saved into RDB, Redis will fork a sub-process for synchronization, which may be very time-consuming when the amount of data is relatively large.

AOF synchronization mechanism:

  1. On and Off: The default is off. appendonly yesIf you want to open it, you can modify it in redis.conf
  2. Synchronization mechanism:
    • appendfsync always: Every time there is a data update operation, it will be synchronized to the file.
    • appendfsync everysec: update every second.
    • appendfsync no: Use the operating system to update. It is generally updated every 30s.
  3. Storage content: the storage is a specific command. No compression will be done.
  4. Storage path: specified according to and redis.confbelow . The default is .dirappendfilename/var/lib/redis/appendonly.aof
  5. advantage:
    • AOF's strategy is to synchronize every second or every time a write operation occurs, so even if the server fails, only 1 second of data will be lost at most.
    • AOF stores Redis commands and is directly appended to the aof file, so you only need to add new data to it every time you back up.
    • If the AOF file is relatively large, Redis will rewrite it to keep only the smallest set of commands.
  6. shortcoming:
    • AOF files are larger than RDB because they are not compressed.
    • AOF is backed up every second or every write operation, so if the concurrency is relatively large, the efficiency may be a bit slow.
    • Because AOF files store commands, Redis will re-run the commands in AOF during disaster recovery, which is not as fast as RDB.

Specify a password for redis:

  1. Set password: In reids.confthe configuration file, requirepass pasworduncomment and specify the password you want to set.
  2. Connect reids with password:
    • Log in first, and then use autho passwordthe command to authorize.
    • When connecting, -aspecify the password through the parameter to connect.

Other machines connect to redis:

If you want other machines to connect to the local redis server, you should redis.confspecify it in the configuration file bind 本机的ip地址. In this way, other machines
can connect successfully. Unlike what is said on the Internet, you need to specify the ip address of the other party.

Guess you like

Origin blog.csdn.net/chenxuezhong0413/article/details/114649506