RDB synchronization mechanism:
- On and Off: By default it is on. If you want to turn it off, then comment out
redis.conf
all the options in the filesave
. - 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.
- Storage content: specific values, but commands. And it is stored after compression.
- Storage path: specified according to and
redis.conf
below . The default is .dir
rdbfilename
/var/lib/redis/dump.rdb
- 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.
- 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:
- On and Off: The default is off.
appendonly yes
If you want to open it, you can modify it in redis.conf - 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.
- Storage content: the storage is a specific command. No compression will be done.
- Storage path: specified according to and
redis.conf
below . The default is .dir
appendfilename
/var/lib/redis/appendonly.aof
- 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.
- 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:
- Set password: In
reids.conf
the configuration file,requirepass pasword
uncomment and specify the password you want to set. - Connect reids with password:
- Log in first, and then use
autho password
the command to authorize. - When connecting,
-a
specify the password through the parameter to connect.
- Log in first, and then use
Other machines connect to redis:
If you want other machines to connect to the local redis server, you should redis.conf
specify 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.