Redis Configuration

The Redis configuration file is located in the Redis installation directory, with the filenameredis.conf(Windows named redis.windows.conf).

You can useCONFIGcommand to view or set configuration items.


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

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 configuration by editing the redis.conf file or usingCONFIG setcommand to modify the configuration.

Syntax

CONFIG SETThe 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:

Serial numberConfiguration itemDescription
1
daemonize no
Redis does not run as a daemon process by default. You can modify this configuration item and use yes to enable the daemon process (Windows does not support daemon threads; the configuration is 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 via 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 MERZ on a phone keypad, and MERZ is taken from the name of Italian singer Alessia Merz.
4
bind 127.0.0.1
Bound host address
5
timeout 300
Close the connection after how many seconds the client is idle. If set to 0, this feature is disabled.
6
loglevel notice
Specify the logging level. Redis supports a total of four levels: debug, verbose, notice, warning. The default is notice.
7
logfile stdout
The logging method defaults to standard output. If Redis is configured to run as a daemon process and the logging method here is also configured as standard output, the logs will be sent to /dev/null.
8
databases 16
Set the number of databases. The default database is 0. You can use SELECTcommand to specify the database id on the connection.
9
save <seconds> <changes>

The Redis default configuration file provides three conditions:

save 900 1

save 300 10

save 60 10000

They respectively mean 1 change within 900 seconds (15 minutes), 10 changes within 300 seconds (5 minutes), and 10000 changes within 60 seconds.

Specify how many update operations within a certain period will trigger 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. 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 file name. The default value is dump.rdb.
12
dir ./
Specify the directory where the local database is stored.
13
slaveof <masterip> <masterport>
When this machine is 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 must provide the password via the AUTH <password> command when connecting to Redis. It is disabled by default.
16
 maxclients 128
Set the maximum number of client connections at the same time. There is no limit by default. The number of client connections Redis can open simultaneously is the maximum number of file descriptors that the Redis process can open. If maxclients is set to 0, it means no limit. When the number of client connections reaches the limit, Redis will close new connections and return the error message "max number of clients reached" to the client.
17
maxmemory <bytes>
Specify the maximum memory limit for Redis. Redis loads data into memory at startup. After reaching the maximum memory, Redis will first try to clear expired or about-to-expire keys. When this method is processed, if the maximum memory setting is still reached, write operations can no longer be performed, but read operations are still possible. Redis's new vm mechanism stores keys in memory and values in the swap area.
18
appendonly no
Specify whether to perform logging after each update operation. By default, Redis writes data to disk asynchronously. If this is not enabled, power failure may cause data loss for a period of time. Because Redis itself synchronizes data files according to the save conditions above, some data may only exist in memory for a period of time. The default is no.
19
appendfilename appendonly.aof
Specify the update log file name. The 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 synchronize data cache to disk (fast).
  • always: Indicates manually calling fsync() after each update operation to write data to disk (slow, safe).
  • everysec: Indicates syncing once per second (compromise, default value).
21
vm-enabled no
Specify whether to enable the virtual memory mechanism. The default value is no. Briefly, the VM mechanism stores data in pages. Redis swaps pages with less access, that is, cold data, to disk. Pages with more access are automatically swapped from disk to 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. The default value is /tmp/redis.swap. It cannot be shared by multiple Redis instances.
23
vm-max-memory 0
Store all data larger than vm-max-memory in virtual memory. No matter how small vm-max-memory is set, all index data is stored in memory (Redis's index data is keys). That is to say, when vm-max-memory is set to 0, in fact all values exist on disk. The default value is 0.
24
vm-page-size 32
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. vm-page-size should be set according to the size of stored data. The author suggests 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 unsure, use the default value.
25
vm-pages 134217728
Set the number of pages in the swap file. Since the page table (a bitmap indicating whether pages are free or used) 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 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 a relatively long delay. The default value is 4.
27
glueoutputbuf yes
Set whether to merge smaller packets into one packet when responding to clients. It is enabled by default.
28
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
Specify that when a certain quantity is exceeded or the maximum element exceeds a certain threshold, a special hash algorithm is used.
29
activerehashing yes
Specify whether to activate rehashing. It is enabled by default (details will be introduced later when introducing Redis's hash algorithm).
30
include /path/to/local.conf
Specify to include other configuration files. You can use the same configuration file among multiple Redis instances on the same host, while each instance also has its own specific configuration file.
Other extensions