Detailed description of the redis configuration file
Sed's @ ^ [#]. * $ @ G'/usr/local/redis/etc/redis. conf | awk '{if (length! = 0) print $0 }'
1. Redis does not run as a daemon by default. You can modify this configuration item and use yes to enable the daemon.
Daemonize yes
2. When Redis runs as a daemon, Redis writes the pid to the/var/run/redis. pid file by default, which can be specified through pidfile
Pidfile/usr/local/redis/var/redis. pid
3. specify the Redis listening port. The default port is 6379. The author explains in his blog why 6379 is used as the default port, because 6379 corresponds to the MERZ number on the mobile phone key, MERZ is taken from the name of Alessia Merz, an Italian singer.
Port 6379
4. Bound host address
# Bind 127.0.0.1
5. When the client is idle for a long time, the connection is closed. If it is set to 0, the function is disabled.
Timeout 0
Tcp-keepalive 0
6. Specify the log record level. Redis supports four levels in total: debug, verbose, notice, and warning. The default value is notice.
Loglevel notice
7. log record location. The default value is standard output.
Logfile/usr/local/redis/var/redis. log
8. Set the number of databases. The default database is 0. You can use the SELECT command to specify the database id for the connection.
Databases 16
9. specify how many update operations are performed within the specified time period to synchronize data to the data file. Multiple conditions can be used together.
Save
1 change in 900 seconds (15 minutes), 10 Changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds.
The default configuration file of Redis provides three conditions:
Save 900 1
Save 300 10
Save 60 10000
Stop-writes-on-bgsave-error yes
10. Specify whether to compress data when stored in the local database. The default value is yes. Redis uses LZF to compress data. To save CPU time, disable this option, but this will cause huge changes in database files.
Rdbcompression yes
Rdbchecksum yes
11. Specify the local database file name. The default value is dump. rdb.
Dbfilename dump. rdb
12. Specify the local database storage directory
Dir/usr/local/redis/var
13. Set the IP address and port of the master service when the local machine is slave service. When Redis is started, it will automatically synchronize data from the master.
# Slaveof
14. When password protection is set for the master service, the slave service connects to the master password
# Masterauth
15. Set the Redis connection password. If the connection password is configured, the client must use the AUTH command to provide the password when connecting to Redis. The password is disabled by default.
# Requirepass foobared
16. Set the maximum number of client connections at the same time. In Redis2.4, the maximum number of connections is directly hardcoded in the Code, and in version 2.6, this value becomes configurable. The default value of maxclients is 10000. You can also modify this value in redis. conf.
Of course, this value is only a wishful thinking value of Redis. Redis will also take care of the system's limit on the number of file descriptors used by processes. At startup, Redis checks the soft limit of the system to check the maximum number of opened file descriptors. If the number set by the system is smaller than the number we want to add 32 to the maximum number of connections, the setting of this maxclients will not work, and Redis will set this value as required by the system. (ADD 32 because Redis uses a maximum of 32 file descriptors internally, so the connection can use equal to any descriptive symbols that can be used minus 32 ).
When this happens (maxclients does not work after it is set), there will be corresponding logs during Redis startup. For example, if the following command is used to set the maximum number of clients to 100000, Redis needs 100000 + 32 file descriptors, and the maximum file descriptor of the system is set to 10144, therefore, Redis can only set maxclients to 10144-32 = 10112.
# Maxclients 10000
17. specify the maximum memory limit of apsaradb for Redis. Redis loads data into the memory at startup. After the maximum memory is reached, Redis first tries to clear the expired or expiring Key, after this method is processed, it still reaches the maximum memory setting, and no write operation can be performed, but the read operation can still be performed. Redis's new vm mechanism stores keys in memory, and values in the swap Area
# Maxmemory
Slave-serve-stale-data yes
Slave-read-only yes
Repl-disable-tcp-nodelay no
Slave-priority 100
18. specify whether to record logs after each update operation. Redis asynchronously writes data to the disk by default. If this parameter is not enabled, data may be lost for a period of time during power failure. Because Redis synchronizes data files according to the above slave conditions, some data will only exist in the memory for a period of time. The default value is no.
Appendonly no
19. Specify the Update log file name. The default value is appendonly. aof.
# Appendfilename appendonly. aof
20. Specify the log update conditions. There are three optional values:
No: indicates that the data cache is synchronized to the disk by the operating system (FAST)
Always: indicates that data is written to a disk by manually calling fsync () after each update operation (slow and secure)
Everysec: Indicates synchronization once per second (compromise, default)
Appendfsync everysec
21. specifies whether to enable the virtual memory mechanism. The default value is no. For a brief introduction, the VM mechanism stores data on pages, and Redis stores cold data on the disk, that is, pages with less traffic, multiple accessed pages are automatically swapped out from the disk to the memory (I will carefully analyze the VM mechanism of Redis in the following article)
Vm-enabled no
22. virtual memory file path. The default value is/tmp/redis. swap. It cannot be shared by multiple Redis instances.
Vm-swap-file/tmp/redis. swap
23. store all data greater than vm-max-memory into the virtual memory. No matter how small the vm-max-memory settings are, all index data is stored in the memory (Redis's index data is keys ), that is to say, when vm-max-memory is set to 0, all values exist on the disk.
Vm-max-memory 0
24. redis swap files are divided into many pages. One object can be stored on multiple pages, but one page cannot be shared by multiple objects, vm-page-size is set based on the size of stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64 bytes. If a large object is stored, you can use a larger page. If you are not sure, use the default value.
Vm-page-size 32
25. set the number of pages in the swap file. Because the page table (a bitmap indicating that the page is idle or used) is in the memory, every 8 pages on the disk consumes 1 byte of memory.
Vm-pages 134217728
26. set the number of threads used to access the swap file. It is best not to exceed the number of server cores. 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.
Vm-max-threads 4
No-appendfsync-on-rewrite no
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64 mb
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
27. When a specified number or maximum element exceeds a critical value, a special hash algorithm is used.
Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64
List-max-ziplist-entries 512
List-max-ziplist-value 64
Set-max-intset-entries 512
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64
28. Specify whether to enable or disable hash resetting. The default setting is enable (this will be detailed later when we introduce the hash algorithm of Redis)
Activerehashing yes
Client-output-buffer-limit normal 0 0 0
Client-output-buffer-limit slave 256 mb 64 mb 60
Client-output-buffer-limit pubsub 32 mb 8 mb 60
Hz 10
29. Specify other configuration files. You can use the same configuration file between multiple Redis instances on the same host, and each instance has its own specific configuration file.
# Include/path/to/local. conf