Detailed explanation of redis configuration file
1. RedisIt does not run as a daemon by default. You can modify it through this configuration item and use yes to enable the daemon
2. When redis runs as a daemon, redis will write PID to / var / run / redis.com by default PID file, which can be specified through pidfile
3. Specify the redis listening port. The default port is 6379. Why choose 6379 as the default port? Because 6379 is the number corresponding to Merz on the mobile phone button, and Merz is taken from the name of Italian singer Alessia Merz.
4. Bound host address
# bind 127.0.0.1
5. Close the connection after the client is idle for a long time. If 0 is specified, it means that the function is closed
6. Specify the logging level,RedisFour levels are supported: debug, verbose, notice and warning. The default is notice
7. Log location, default to standard output
8. Set the number of databases. The default database is 0. You can use the select command to specify the database ID on the connection
9. Specify how long and how many update operations will be performed to synchronize the data to the data file. Multiple conditions can be matched
It means 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes) and 10000 changes in 60 seconds respectively.
Redis default configuration file provides three conditions:
save 900 1
save 300 10
save 60 10000
10. Specify whether to compress data when stored in the local database. The default is yes. Redis adopts lzf compression. If you want to save CPU time, you can turn this option off, but the database file will become huge
11. Specify the local database file name. The default value is dump rdb
12. Specify local database storage directory
13. Set the IP address and port of the master service when the local machine is a slave service. When redis is started, it will automatically synchronize data from the master
14. When password protection is set for the master service, the slave service uses the password to connect to the master
15. Set the redis connection password. If the connection password is configured, the client needs to provide the password through the auth command when connecting to redis. It is closed by default
# requirepass foobared
16. Set the maximum number of client connections at the same time on redis2 In version 4, the maximum number of connections is directly hard coded in the code, while in version 2.6, this value becomes configurable. The default value of maxclients is 10000. You can also use redis Modify this value in conf.
Of course, this value is only a wishful thinking value of redis. Redis will also take into account the system’s own restrictions on the number of file descriptors used by the process. At startup, redis will check the soft limit of the system to see the maximum number of open file descriptors. If the number set by the system is less than the maximum number of connections we want plus 32, the setting of maxclients will not work. Redis will set this value as required by the system. (add 32 because redis will use up to 32 file descriptors internally, so what can be used by the connection is equivalent to all available descriptors minus 32).
When the above situation occurs (when maxclients does not work after setting), there will be corresponding log records during redis startup. For example, the following command wants to set the maximum number of clients to 100000, so redis needs 100000 + 32 file descriptors, and the maximum file description symbol of the system is set to 10144, so redis can only set maxclients to 10144 – 32 = 10112.
# maxclients 10000
17. Specify the maximum memory limit of redis. When redis starts, it will load data into memory. After reaching the maximum memory, redis will first try to clear the expired or about to expire keys. When this method is used for processing
After, the maximum memory setting is still reached, and the write operation can no longer be carried out, but the read operation can still be carried out. Redis’s new VM mechanism will store the key in memory and the value in the swap area
18. Specify whether to log after each update operation. Redis writes data to disk asynchronously by default. If it is not turned on, it may cause data loss for a period of time in case of power failure. Because redis synchronizes data files according to the above slave conditions, some data will only exist in memory for a period of time. The default is No
19. Specify the name of the update log file. The default is appendonly aof
# appendfilename appendonly.aof
20. Specify the update log condition. There are three optional values:
No: indicates that the operating system performs data cache synchronization to the disk (fast)
Always: indicates that after each update operation, fsync() is called manually to write data to disk (slow and safe)
Everysec: indicates one synchronization per second (compromise, default)
21. Specify whether to enable the virtual memory mechanism. The default value is No. for a brief introduction, the VM mechanism stores the data in pages. Redis will swap the cold data of the pages with less visits to the disk, and the pages with more visits will be automatically swapped out to memory by the disk (I will analyze redis’s VM mechanism in detail in the following article)
22. Virtual memory file path. The default value is / TMP / redis Swap, which cannot be shared by multiple redis instances
23. Store all data larger than VM Max memory into virtual memory. No matter how small VM Max memory is set, all index data is stored in memory (redis index data is keys), that is, when VM Max memory is set to 0, all values are actually stored in disk.
24. Redis swap files are divided into many pages. One object can be saved on multiple pages, but one page cannot be shared by multiple objects. VM page size should be set according to the stored data size. The author suggests that if many small objects are stored, the best page size should be 32 or 64 bytes; If you store very large objects, you can use a larger page. If you are not sure, you can use the default value
25. Set the number of pages in the swap file. Since the page table (a bitmap indicating that the page is idle or used) is placed in memory, every 8 pages on the disk will consume 1 byte of memory.
26. Set the number of threads accessing the swap file. It is better not to exceed the number of cores of the machine. If it is set to 0, all operations on the swap file are serial, which may cause a long delay. The default value is 4
27. Specify a special hash algorithm when the number of elements exceeds a certain number or the maximum element exceeds a critical value
28. Specify whether to activate reset hash. It is on by default
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
29. Specify to include other configuration files. You can use the same configuration file among multiple redis instances on the same host, and each instance has its own specific configuration file
# include /path/to/local.conf