English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Configuration

Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf(Windows 名为 redis.windows.conf)。

你可以通过 CONFIG 命令查看或设置配置项。

Syntax

Redis CONFIG 命令格式如下:

redis 127.0.0.1:6379>  CONFIG  GET  CONFIG_SETTING_NAME

Online example

redis 127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"

使用 * 号获取所有配置项:

Online 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 Command syntax:

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

Online 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 is the description of redis.conf configuration items:

Serial numberConfiguration itemDescription
1
daemonize no
Redis does not run by default as a daemon process, and this configuration item can be modified to use yes to enable daemon mode (Windows does not support the configuration of no for daemon threads)
2
pidfile /var/run/redis.pid
When Redis runs as a daemon process, Redis will default to writing the pid to /var/run/redis.pid file, which can be specified by pidfile
3
port 6379
Specify the Redis listening port, the default port is 6379, the author explained in his blog post why this choice was made 6379 As the default port, because 6379 The number corresponding to MERZ on the mobile phone key, and MERZ is derived from the name of the Italian singer Alessia Merz
4
bind 127.0.0.1
Bound host address
5
timeout 300
When the client is idle for how many seconds before closing the connection, if specified as 0, it means to disable this feature
6
loglevel notice
Specify 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 the log recording method is configured as standard output here, 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>

Three conditions are provided in the default Redis configuration file:

save 900 1

save 300 10

save 60 10000

respectively mean 900 seconds (15 minutes) within 1 changes,300 seconds (5 minutes) within 10 changes and 6Within 0 seconds 10000 changes.

Specify how often, in how many update operations, the data is synchronized to the data file, which can be combined with multiple conditions
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 very large
11
dbfilename dump.rdb
Specify the local database filename, the default value is dump.rdb
12
dir ./
Specify the directory where the local database is stored
13
slaveof <masterip> <masterport>
Set the IP address and port of the master service when this machine is a slave service, and Redis will automatically synchronize data from the master when it starts up
14
masterauth <master-password>
When the master service is set with password protection, the password for the slave service to connect to the master
15
requirepass foobared
Set the password for Redis connections. If a connection password is configured, the client needs to provide the password through the AUTH <password> command when connecting to Redis, and the default is disabled
16
 maxclients 128
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 new connections and return the error message 'max number of clients reached' to the client
17
maxmemory <bytes>
specifies 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 expired or about-to-expire keys, after this method is processed, if the maximum memory setting is still reached, the write operation cannot be performed anymore, but the read operation can still be performed. Redis's new vm mechanism will store keys in memory, and values will be stored in the swap area
18
appendonly no
specifies whether to log the update operation after each update, by default, Redis asynchronously writes data to disk. If it is not enabled, data loss may occur for a period of time during power failure. Because the redis itself synchronizes the data file is according to the above save conditions, so some data may only exist in memory for a period of time. The default is no
19
appendfilename appendonly.aof
specifies the update log file name, the default is appendonly.aof
20
appendfsync everysec

specifies the update log condition, there are 3 optional values:

  • no: means wait for the operating system to synchronize data caching to disk (fast)

  • always: means manually call fsync() after each update operation to write data to disk (slow, safe)

  • everysec: means synchronize once per second (compromise, default value)

21
vm-enabled no
specifies whether to enable the virtual memory mechanism, the default value is no, let me briefly introduce it, the VM mechanism stores data in pages, Redis swaps the less frequently accessed pages, i.e., cold data, to disk, and the pages accessed more frequently are automatically swapped out to memory from disk (I will analyze Redis's VM mechanism in detail in the following article)
22
vm-swap-file /tmp/redis.swap
the path of the virtual memory file, the default value is /tmp/redis.swap, cannot be shared by multiple Redis instances
23
vm-max-memory 0
all pages larger than vm-max-memory data is stored in virtual memory, regardless of vm-max-memory is set to be how small, all index data are stored in memory (Redis's index data is the keys), that is to say, when vm-max-When the memory setting is 0, it actually means that all values exist on disk. The default value is 0
24
vm-page-size 32
Redis swap files are divided into many pages, an object can be stored on multiple pages, but a page cannot be shared by multiple objects, vm-page-the size should be set according to the size of the stored data, the author suggests that if many small objects are stored, the page size is best set to 32 or 64bytes; if storing very large objects, larger pages can be used, if unsure, use the default value
25
vm-pages 134217728
Set the number of pages in the swap file, since the page table (a bitmap representing the free or used status of pages) is placed in memory, on disk every 8 pages will consume 1byte memory.
26
vm-max-threads 4
Set the number of threads to access the swap file, it is best not to exceed the number of cores of the machine, if set to 0, then all operations on the swap file are serial, which may cause a relatively long delay. The default value is4
27
glueoutputbuf yes
Set whether to merge smaller packets into one packet when responding to the client, the default is enabled
28
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
Specify that a special hash algorithm is used when the number of elements exceeds a certain quantity or the maximum element exceeds a certain critical value
29
activerehashing yes
Specify whether to activate the reset hash, the default is enabled (specifically introduced later when introducing Redis hash algorithms)
30
include /path/to/local.conf
Specify a configuration file to include others, so that the same configuration file can be used between multiple Redis instances on the same host, while each instance also has its own specific configuration file