Redis configuration (3)

1. Redis configuration

The configuration file of Redis is located in the Redis installation directory, and the file name is redis.conf.

You can view or set configuration items through the CONFIG command.  

Syntax
The Redis CONFIG command format is as follows:

redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME

  Example

redis 127.0.0.1:6379> CONFIG GET loglevel

 "loglevel"
 "notice"

 Use  *  to get all configuration items:

Example

redis 127.0.0.1:6379> CONFIG GET *

  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"
  8) ""
  9) "logfile"
 10) ""
 11) "pidfile"
 12) "/var/run/redis.pid"
 13) "maxmemory"
 14) "0"
 15) "maxmemory-samples"
 16) "3"
 17) "timeout"
 18) "0"
 19) "tcp-keepalive"
 20) "0"
 21) "auto-aof-rewrite-percentage"
 22) "100"
 23) "auto-aof-rewrite-min-size"
 24) "67108864"
 25) "hash-max-ziplist-entries"
 26) "512"
 27) "hash-max-ziplist-value"
 28) "64"
 29) "list-max-ziplist-entries"
 30) "512"
 31) "list-max-ziplist-value"
 32) "64"
 33) "set-max-intset-entries"
 34) "512"
 35) "zset-max-ziplist-entries"
 36) "128"
 37) "zset-max-ziplist-value"
 38) "64"
 39) "hll-sparse-max-bytes"
 40) "3000"
 41) "lua-time-limit"
 42) "5000"
 43) "slowlog-log-slower-than"
 44) "10000"
 45) "latency-monitor-threshold"
 46) "0"
 47) "slowlog-max-len"
 48) "128"
 49) "port"
 50) "6379"
 51) "tcp-backlog"
 52) "511"
 53) "databases"
 54) "16"
 55) "repl-ping-slave-period"
 56) "10"
 57) "repl-timeout"
 58) "60"
 59) "repl-backlog-size"
 60) "1048576"
 61) "repl-backlog-ttl"
 62) "3600"
 63) "maxclients"
 64) "4064"
 65) "watchdog-period"
 66) "0"
 67) "slave-priority"
 68) "100"
 69) "min-slaves-to-write"
 70) "0"
 71) "min-slaves-max-lag"
 72) "10"
 73) "hz"
 74) "10"
 75) "no-appendfsync-on-rewrite"
 76) "no"
 77) "slave-serve-stale-data"
 78) "yes"
 79) "slave-read-only"
 80) "yes"
 81) "stop-writes-on-bgsave-error"
 82) "yes"
 83) "daemonize"
 84) "no"
 85) "rdbcompression"
 86) "yes"
 87) "rdbchecksum"
 88) "yes"
 89) "activerehashing"
 90) "yes"
 91) "repl-disable-tcp-nodelay"
 92) "no"
 93) "aof-rewrite-incremental-fsync"
 94) "yes"
 95) "appendonly"
 96) "no"
 97) "you"
 98) "/home/deepak/Downloads/redis-2.8.13/src"
 99) "maxmemory-policy"
100) "volatile-lru"
101) "appendfsync"
102) "everysec"
103) "save"
104) "3600 1 300 100 60 10000"
105) "loglevel"
106) "notice"
107) "client-output-buffer-limit"
108) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
109) "unixsocketperm"
110) "0"
111) "slaveof"
112) ""
113) "notify-keyspace-events"
114) ""
115) "bind"
116) ""

 Editing the configuration
You can modify the configuration by modifying the redis.conf file or using the CONFIG set command.
Syntax
The basic syntax of the CONFIG SET command:

 

 

 

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

 Example

redis 127.0.0.1:6379> CONFIG SET loglevel "notice"
OK
redis 127.0.0.1:6379> CONFIG GET loglevel

"loglevel"
"notice"

 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 and use yes to enable the daemon process
    daemonize no
2. When Redis runs as a daemon process, Redis will write the pid to the /var/run/redis.pid file by default, which can be specified by pidfile
    pidfile /var/run/redis.pid
3. Specify the Redis listening port. The default port is 6379. The author explained in his blog post why 6379 was chosen as the default port, because 6379 is the number corresponding to MERZ on the phone button, and MERZ is taken from the name of Italian singer Alessia Merz
    port 6379
4. Binding host address
    bind 127.0.0.1
5. When the client is idle for how long, the connection is closed. If it is specified as 0, it means that the function is closed.
    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 <dbid> 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, which can be matched with multiple conditions
    save <seconds> <changes>
    Three conditions are provided in the Redis 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. Specify whether to compress the data when storing to 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
    to you ./
13. Set the IP address and port of the master service when the machine is the slav service. When Redis starts, it will automatically synchronize data from the master
    slaveof <masterip> <masterport>
14. When the master service is password protected, the password for the slave service to connect to the master
    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, which is disabled by default.
    requirepass foobared
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 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 the 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 is still reached. set, write operations are no longer possible, but read operations are still possible. The new vm mechanism of Redis will store the Key in memory and the Value in the swap area
    maxmemory <bytes>
18. Specify 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. Default is 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 waiting for the operating system to synchronize the data cache to the disk (fast)
    always: Indicates that fsync() is manually called to write data to disk after each update operation (slow, safe)
    everysec: means sync once per second (compromise, default)
    appendfsync everysec
 
21. Specify whether to enable the virtual memory mechanism. The default value is no. To briefly introduce, the VM mechanism stores data in pages, and Redis swaps the pages with less access, that is, cold data, to the disk, and the pages that are accessed more are automatically stored by the disk. Swap out to memory (I will analyze Redis' VM mechanism carefully in a later article)
     vm-enabled no
22. The 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 are stored in memory (Redis index data is keys), that is, when vm When -max-memory is set to 0, all values ​​actually exist on disk. Default value 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 is set according to the size of the stored data. The author It is recommended that if you 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 bitmap indicating page free or used) is placed in memory, every 8 pages on the 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 to send when replying to the client, the default is ON
    glueoutputbuf yes
28. Specify a special hash algorithm to be used when a certain number or the largest element exceeds a certain threshold
    hash-max-zipmap-entries 64
    hash-max-zipmap-value 512
29. Specify whether to activate the reset hash, the default is ON (the details will be introduced later when the Redis hash algorithm is introduced)
    activerehashing yes
30. 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

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326890169&siteId=291194637