Redis — detailed explanation of configuration file


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

  daemonize yes

2. When redis runs as a daemon, redis will write PID to / var / run / by default PID file, which can be specified through pidfile

  pidfile /usr/local/redis/var/

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.

  port 6379

4. Bound host address

  # bind

5. Close the connection after the client is idle for a long time. If 0 is specified, it means that the function is closed

  timeout 0

  tcp-keepalive 0

6. Specify the logging level,RedisFour levels are supported: debug, verbose, notice and warning. The default is notice

  loglevel notice

7. Log location, default to 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 on the connection

  databases 16

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

  stop-writes-on-bgsave-error yes

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

  rdbcompression yes

  rdbchecksum yes

11. Specify the local database file name. The default value is dump rdb

  dbfilename dump.rdb

12. Specify 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 a 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 uses the password to connect to the master

  # masterauth

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

  # maxmemory

  slave-serve-stale-data yes

  slave-read-only yes

  repl-disable-tcp-nodelay no

  slave-priority 100

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

  appendonly 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)

  appendfsync everysec

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)

  vm-enabled no

22. Virtual memory file path. The default value is / TMP / redis Swap, which cannot be shared by multiple redis instances

  vm-swap-file /tmp/redis.swap

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.

  vm-max-memory 0

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

  vm-page-size 32

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.

  vm-pages 134217728

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

  vm-max-threads 4

  no-appendfsync-on-rewrite no

  auto-aof-rewrite-percentage 100

  auto-aof-rewrite-min-size 64mb

  lua-time-limit 5000

  slowlog-log-slower-than 10000

  slowlog-max-len 128

27. Specify a special hash algorithm when the number of elements exceeds a certain number or the maximum element exceeds a critical value

  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 activate reset hash. It is on by default

  activerehashing yes

  client-output-buffer-limit normal 0 0 0

  client-output-buffer-limit slave 256mb 64mb 60

  client-output-buffer-limit pubsub 32mb 8mb 60

  hz 10

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

Recommended Today

How to insert an LSM tree into NVM

Introduction: with the commercial promotion of nonvolatile memory products, we are more and more interested in its large-scale promotion potential in cloud native database. X-engine is an LSM tree storage engine developed by the polardb new storage engine team of Alibaba cloud database products division. It currently provides external services on Alibaba cloud polardb products. […]