Redis configuration
The Redis configuration file 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
Instance
redis 127.0.0.1:6379> CONFIG GET loglevel 1) "loglevel" 2) "notice"
Use the * number to obtain All configuration items:
Instance
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) "dir" 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) ""
Edit configuration
You can modify it by modifying the redis.conf file or using the CONFIG set command configuration.
Syntax
CONFIG SET Basic command syntax:
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 1) "loglevel" 2) "notice"
Parameter description
redis.conf Configuration item description is as follows:
1. Redis does not run as a daemon process by default. You can modify 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 through pidfile
pidfile /var/run/redis.pid
3. Specify the Redis listening port. The default port is 6379. The author stated in one of his blog posts Explains why 6379 is 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 the Italian singer Alessia Merz
port 6379
4. Bind host address
bind 127.0.0.1
5. How long will the client be idle for? Then close the connection, if 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 <dbid> command to specify the database id on the connection.
databases 16
9. Specify the period of time and how many update operations there are to synchronize the data to the data file. Multiple conditions can be used
save <seconds> <changes>
Redis default configuration file provides three conditions:
save 900 1
save 300 10
save 60 10000
Represents 900 seconds respectively ( 1 change in 15 minutes), 10 changes in 300 seconds (5 minutes) and 10000 changes in 60 seconds.
10. Specify whether to compress the 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 The 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 when the local machine serves slave, set the IP address and port of the master 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 slav 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. It is closed 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. It is the maximum number of file descriptors that can be opened by the Redis process. 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 clientmaxclients 128
17. Specify the maximum memory limit of Redis. Redis will load data into the memory when it starts. After reaching the maximum memory, Redis will first try to clear the expired or about to expire Key. When this method is processed, it will still Once the maximum memory setting is reached, writes are no longer possible, but reads are still possible. Redis's new vm mechanism will store Key in memory and Value in swap areamaxmemory <bytes>
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 during a power outage. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. The default is no
appendonly no
19. Specify the update log file name, the default is appendonly.aof
appendfilename appendonly.aof
20. Specify update log conditions, there are 3 optional values:
no : Indicates waiting for the operating system to synchronize the data cache to the disk (fast)
always: Indicates manually calling fsync() to write the data to the disk after each update operation (slow, Security)
everysec: Indicates synchronization once per second (compromise, default value)
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 will use pages with less access as cold data. Swap to the disk, and pages that are accessed frequently are automatically swapped out from the disk to the memory (I will carefully analyze the VM mechanism of Redis in a later 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 in virtual memory. No matter how small vm-max-memory is set, all index data is in memory. Stored (the index data of Redis is keys), that is to say, when vm-max-memory is set to 0, all values actually exist on the disk. The default value is 0vm-max-memory 0
24. Redis swap file is divided into many pages, and an object can be saved in On multiple pages, but one page cannot be shared by multiple objects. vm-page-size is set according to the size of the stored data. The author recommends that if many small objects are stored, 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 valuevm-page-size 32
25. Set the number of pages in the swap file. Since the page table (a bitmap indicating that a page is free 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 to access the swap file. It is best not to exceed the number of cores of the machine. If it is set to 0, then All operations on swap files are serial and may cause a long delay. The default value is 4
vm-max-threads 4
27. Set whether to send smaller packets when responding to the client Combined into one package and sent, the default is on When the critical value is reached, a special hash algorithm is used
hash-max-zipmap-entries 64
hash-max-zipmap-value 51229. Specify whether to activate the reset hash, the default is on (details will be introduced later when introducing the Redis hash algorithm)
activerehashing yes
30. Specify other configuration files, and you can use the same configuration file between multiple Redis instances on the same host, and at the same time Each instance has its own specific configuration file
include /path/to/local.conf