Redis Configuration | Novice Tutorial
The configuration file for Redis is located in the Redis installation directory, with the filename redis.conf (on Windows it is named redis.windows.conf).
You can view or set configuration items using the CONFIG command.
Syntax
The format of the Redis CONFIG command is as follows:
redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME
Example
redis 127.0.0.1:6379> CONFIG GET loglevel 1) "loglevel"2) "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) "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) ""
Editing Configuration
You can modify the configuration by editing 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 1) "loglevel"2) "notice"
Parameter Description
The following are descriptions of the redis.conf configuration items:
| No. | Configuration Item | Description |
|---|---|---|
| 1 | daemonize no | Redis does not run as a daemon process by default. This can be modified through this configuration item. Use 'yes' to enable the daemon process (Windows does not support daemon thread configuration, set to 'no') |
| 2 | pidfile /var/run/redis.pid | When Redis runs as a daemon process, Redis will write the pid to the /var/run/redis.pid file by default. You can specify it through pidfile |
| 3 | port 6379 | Specify the Redis listening port. The default port is 6379. The author explained in one of his blog posts why 6379 was chosen as the default port, because 6379 corresponds to the numbers on mobile phone keys for MERZ, and MERZ comes from the name of Italian singer Alessia Merz |
| 4 | bind 127.0.0.1 | Binds the host address |
| 5 | timeout 300 | Closes the connection after how many seconds of client inactivity. If specified as 0, it means closing this function |
| 6 | loglevel notice | Specifies the log recording level. Redis supports four levels in total: debug, verbose, notice, warning. The default is notice |
| 7 | logfile stdout | Log recording method. The default is standard output. If Redis is configured to run as a daemon process, and here the log recording method is configured as standard output, then the logs will be sent to /dev/null |
| 8 | databases 16 | Set the number of databases. The default database is 0. You can use the SELECT command to specify the database id on the connection |
| 9 | save <seconds> <changes> Redis provides three conditions in the default configuration file: save 900 1 save 300 10 save 60 10000 which represent 1 change within 900 seconds (15 minutes), 10 changes within 300 seconds (5 minutes), and 10000 changes within 60 seconds respectively. | Specify how long and how many update operations there should be before synchronizing data to the data file. Multiple conditions can be combined |
| 10 | rdbcompression yes | Specify whether to compress 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 |
| 11 | dbfilename dump.rdb | Specify the local database filename. The default value is dump.rdb |
| 12 | dir ./ | Specify the local database storage directory |
| 13 | slaveof <masterip> <masterport> | When this machine serves as a slave service, set the IP address and port of the master service. When Redis starts, it will automatically synchronize data from the master |
| 14 | masterauth <master-password> | When the master service has password protection enabled, this is the password for the slave service to connect to the master |
| 15 | requirepass foobared | Set the Redis connection password. If a connection password is configured, the client needs to provide the password through the AUTH <password> command when connecting to Redis. It is disabled by default |
| 16 | maxclients 128 | Set the maximum number of concurrent client connections. There is no limit by default. The number of concurrent client connections that Redis can open is equal to the maximum number of file descriptors that the Redis process can open. If maxclients 0 is set, it means no limit. When the number of client connections reaches the limit, Redis will close new connections and return an error message "max number of clients reached" to the client |
| 17 | maxmemory <bytes> | Specify the maximum memory limit for Redis. When Redis starts, it loads data into memory. After reaching the maximum memory, Redis will first try to clear expired or about-to-expire Keys. After this method is processed, if the maximum memory setting is still reached, write operations will no longer be possible, but read operations can still be performed. Redis's new VM mechanism stores Keys in memory and Values in the swap area |
| 18 | appendonly no | Specify whether to record logs after each update operation. By default, Redis asynchronously writes data to disk. If not enabled, data loss may occur during power outages. Because redis itself synchronizes data files according to the above save conditions, some data exists only in memory for a period of time. Default is no |
| 19 | appendfilename appendonly.aof | Specify the update log filename. Default is appendonly.aof |
| 20 | appendfsync everysec | Specify the update log condition. There are 3 optional values: * no: indicates waiting for the operating system to perform data cache synchronization to disk (fast) * always: indicates manually calling fsync() after each update operation to write data to disk (slow, safe) * everysec: indicates synchronizing once per second (compromise, default value) |
| 21 | vm-enabled no | 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 pages with less access, i.e., cold data, to the disk, while frequently accessed pages are automatically swapped out from the disk to memory (I will carefully analyze Redis's VM mechanism in later articles) |
| 22 | vm-swap-file /tmp/redis.swap | Virtual memory file path. Default value is /tmp/redis.swap. Multiple Redis instances cannot share this |
| 23 | vm-max-memory 0 | Store all data larger than vm-max-memory in virtual memory. Regardless of how small vm-max-memory is set, all index data is stored in memory (Redis's index data are keys). In other words, when vm-max-memory is set to 0, actually all values exist on disk. Default value is 0 |
| 24 | vm-page-size 32 | Redis swap file is divided into many pages. An object can be saved on multiple pages, but a page cannot be shared by multiple objects. vm-page-size should be set according to the size of the stored data. The author suggests that if storing many small objects, the page size should be best set to 32 or 64 bytes; if storing large objects, a larger page can be used. If uncertain, use the default value |
| 25 | vm-pages 134217728 | Set the number of pages in the swap file. Since the page table (a bitmap indicating page availability) is stored in memory, every 8 pages on disk will consume 1 byte of memory. |
| 26 | vm-max-threads 4 | Set the number of threads accessing the swap file. It's best not to exceed the number of machine cores. If set to 0, all operations on the swap file will be sequential, which may cause considerable delays. The default value is 4 |
| 27 | glueoutputbuf yes | Set whether to merge smaller packets into one packet when responding to clients. Default is enabled |
| 28 | hash-max-zipmap-entries 64 hash-max-zipmap-value 512 | Specify that when exceeding a certain number or the maximum element exceeds a certain threshold, a special hash algorithm is adopted |
| 29 | activerehashing yes | Specify whether to activate rehashing. Default is enabled (later when introducing Redis's hash algorithm |
YouTip