Redis Configuration
The Redis configuration file is located in the Redis installation directory, named redis.conf (named redis.windows.conf on Windows).
You can use CONFIG command to view or set configuration items.
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) ""
Edit Configuration
You can modify the redis.conf file or use CONFIG set command to modify the configuration.
Syntax
CONFIG SET The basic syntax of the 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 redis.conf configuration items are described as follows:
| No. | Configuration Item | Description |
|---|---|---|
| 1 |
daemonize no |
By default Redis does not run as a daemon. This can be changed via this option; set to yes to enable the daemon (Windows does not support daemon mode, so it is set to no) |
| 2 |
pidfile /var/run/redis.pid |
When Redis runs as a daemon, it writes the pid to /var/run/redis.pid by default; this can be specified via pidfile |
| 3 |
port 6379 |
Specifies the port Redis listens on; the default port is 6379. The author explained in a blog post why 6379 was chosen as the default port: 6379 corresponds to MERZ on phone keypad, and MERZ comes from the name of Italian showgirl Alessia Merz |
| 4 |
bind 127.0.0.1 |
Bound host address |
| 5 |
timeout 300 |
Number of seconds after which the client is closed when idle; if set to 0, this feature is disabled |
| 6 |
loglevel notice |
Specifies the logging level. Redis supports four levels in total: debug, verbose, notice, warning; the default is notice |
| 7 |
logfile stdout |
Logging method, default is standard output. If Redis is configured to run as a daemon and logging is set to standard output here, logs will be sent to /dev/null |
| 8 |
databases 16 |
Sets the number of databases; the default database is 0. You can use SELECT |
| 9 |
save The default Redis configuration file provides three conditions: save 900 1 save 300 10 save 60 10000 meaning 1 change within 900 seconds (15 minutes), 10 changes within 300 seconds (5 minutes), and 10000 changes within 60 seconds. |
Specifies that within a given time, a certain number of update operations will trigger synchronization of data to the data file; multiple conditions can be combined |
| 10 |
rdbcompression yes |
Specifies whether to compress data when storing to the local database; default is yes. Redis uses LZF compression. To save CPU time you can disable this option, but it will make the database file very large |
| 11 |
dbfilename dump.rdb |
Specifies the local database file name; the default value is dump.rdb |
| 12 |
dir ./ |
Specifies the local database storage directory |
| 13 |
slaveof |
When this machine is a slave, sets the IP address and port of the master service. At startup Redis automatically synchronizes data from the master |
| 14 |
masterauth |
The password for the slave to connect to the master when the master has password protection enabled |
| 15 |
requirepass foobared |
Sets the Redis connection password. If a connection password is configured, the client must provide it via the AUTH |
| 16 |
maxclients 128 |
Sets the maximum number of simultaneous client connections; unlimited by default. The number of client connections Redis can open simultaneously is the maximum number of file descriptors the Redis process can open. Setting maxclients to 0 means no limit. When the client connection count reaches the limit, Redis closes the new connection and returns the "max number of clients reached" error message to the client |
| 17 |
maxmemory |
Specifies the maximum memory limit for Redis. Redis loads data into memory at startup. After reaching the maximum memory, Redis first tries to clear expired or about-to-expire keys. If the maximum memory limit is still reached after this, write operations can no longer be performed, 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 |
Specifies whether to log after each update operation. By default Redis writes data to disk asynchronously; if not enabled, data may be lost during a power outage. Because Redis itself synchronizes the data file according to the save conditions above, some data will only exist in memory for a period of time. Default is no |
| 19 |
appendfilename appendonly.aof |
Specifies the update log file name; default is appendonly.aof |
| 20 |
appendfsync everysec |
Specifies the update log condition; there are 3 optional values: |
vm-enabled no| Specifies whether to enable the virtual memory mechanism; default is no. Briefly, the VM mechanism stores data in pages, and Redis swaps less-accessed pages (cold data) to disk, while frequently accessed pages are automatically swapped from disk back into memory (I will analyze Redis's VM mechanism in detail in a later article) | | 22 |
vm-swap-file /tmp/redis.swap| Virtual memory file path; default is /tmp/redis.swap; cannot be shared by multiple Redis instances | | 23 |
vm-max-memory 0| 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 the keys). That is, when vm-max-memory is set to 0, all values actually reside on disk. Default is 0 | | 24 |
vm-page-size 32| The Redis swap file is divided into many pages. One object can be stored across multiple pages, but one page cannot be shared by multiple objects. vm-page-size should be set based on the size of stored data. The author suggests setting the page size to 32 or 64 bytes if storing many small objects; for very large objects, a larger page can be used; if unsure, use the default value | | 25 |
vm-pages 134217728| Sets the number of pages in the swap file. Since the page table (a bitmap indicating whether pages are free or used) is kept in memory, every 8 pages on disk consumes 1 byte of memory. | | 26 |
vm-max-threads 4| Sets the number of threads accessing the swap file; it is best not to exceed the number of machine cores. If set to 0, all operations on the swap file are serial, which may cause relatively long delays. Default is 4 | | 27 |
glueoutputbuf yes| Sets whether to merge smaller packets into one packet when responding to the client; enabled by default | | 28 |
hash-max-zipmap-entries 64 hash-max-zipmap-value 512| Specifies using a special hash algorithm when the number of elements or the maximum element exceeds a certain threshold | | 29 |
activerehashing yes| Specifies whether to activate rehashing; enabled by default (I will introduce Redis's hash algorithm in detail later) | | 30 |
include /path/to/local.conf| Specifies including other configuration files, allowing multiple Redis instances on the same host to share a common configuration file while each instance also has its own specific configuration file |