Introduction to common configurations of redis configuration files

Blog content starting address

Parameter Description

The redis.conf configuration items are described as follows:

  1. Redis does not run as a daemon process by default, you can modify it through this configuration item, use yes to enable the
    daemonize no

  2. When Redis runs in daemon mode, Redis will write pid to /var/run/redis.pid file by default, which can be specified by pidfile.

  3. Specifies the listening port for Redis. The default port is 6379.
    port 6379

  4. The bind host address.
    bind 127.0.0.1

  5. When the client is idle for a long time, the connection is closed. If it is specified as 0, it means to close the function.
    timeout 300

  6. Specify the logging level. Redis supports a total of four levels: debug, verbose, notice, warning. The default is verbose.
    loglevel verbose

  7. Logging mode, the default is standard output. If Redis is configured to run in daemon mode, and the logging mode is configured as standard output, the log will be sent to /dev/null.
    logfile stdout

  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 many update operations in a period of time and synchronize the data to the data file. You can use multiple conditions with
    save seconds changes
    . Redis provides three conditions in the default configuration file:
    save 900 1
    save 300 10
    save 60 10000
    respectively Means 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes) and 10000 changes in 60 seconds.

  10. Specifies whether to compress data when storing it in the local database. The default is yes. Redis uses LZF compression. If you want to save CPU time, you can turn off this option, but it will cause the database file to become huge.
    rdbcompression 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 ./

  13. Set the IP address and port of the master service when the machine is the slave service. When Redis starts, it will automatically synchronize data from the master.
    slaveof masterip masterport

  14. When the master service is password protected, the slav service connects to the master password
    masterauth master-password

  15. Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the AUTH password command when connecting to Redis. By default,
    requirepass foobared is disabled.

  16. Set the maximum number of client connections at the same time. The default is unlimited. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that the Redis process can open. If maxclients is set to 0, it means that there is no limit. When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients reached error message to the client
    maxclients 128

  17. Specify the maximum memory limit of Redis. Redis will load data into memory when it starts up. After reaching the maximum memory, Redis will first try to clear the keys that have expired or are about to expire. After this method is processed, the maximum memory setting is still reached. Write operations will no longer be possible, but read operations will still be possible. The new vm mechanism of Redis will store the Key in memory and the Value in the swap area.
    maxmemory bytes

  18. Specifies whether to perform logging 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 during power failure. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. Defaults to no
    appendonly no

  19. Specify the update log file name, the default is appendonly.aof
    appendfilename appendonly.aof

  20. Specify the update log condition, there are 3 optional values:
    no : Indicates that the operating system synchronizes the data cache to the disk (fast)
    always : Indicates that fsync() is manually called after each update operation to write the data to the disk (slow, safe)
    everysec : means sync once per second (compromise, default)
    appendfsync everysec

  21. Specifies whether to enable the virtual memory mechanism. The default value is no. To briefly introduce, the VM mechanism stores data in pages. Redis swaps the pages with less access, that is, cold data, to the disk, and the pages that are accessed more are automatically swapped out from the disk. into memory (in a later article I will carefully analyze the VM mechanism of Redis)
    vm-enabled no

  22. Virtual memory file path, the default value is /tmp/redis.swap, multiple Redis instances cannot share
    vm-swap-file /tmp/redis.swap

  23. Store all data larger than vm-max-memory in virtual memory, no matter how small vm-max-memory is set, all index data are stored in memory (Redis index data is keys), that is, when vm-max When -memory is set to 0, all values ​​actually exist on disk. Default is 0
    vm-max-memory 0

  24. The Redis swap file is divided into many pages. An object can be stored on multiple pages, but a page cannot be shared by multiple objects. The vm-page-size should be set according to the size of the stored data. The author recommends that if To store many small objects, the page size is best set to 32 or 64 bytes; if you store very large objects, 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. Since the page table (a kind of bitmap indicating page free or used) is placed in memory, every 8 pages on disk will consume 1byte of memory.
    vm-pages 134217728

  26. Set the number of threads accessing the swap file, preferably not more than the number of cores of the machine. If it is set to 0, then all operations on the swap file are serial, which may cause a long delay. Default is 4
    vm-max-threads 4

  27. Set whether to combine smaller packets into one packet when replying to the client, the default is to enable
    glueoutputbuf yes


  28. Specifies to use a special hash algorithm hash-max-zipmap-entries 64 hash-max-zipmap-value 512 when it exceeds a certain number or the largest element exceeds a certain threshold

  29. Specifies whether to activate rehashing, the default is
    activerehashing yes

  30. Specify to include 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325949783&siteId=291194637