xref: /OK3568_Linux_fs/yocto/meta-openembedded/meta-oe/recipes-extended/redis/redis-7/redis.conf (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Redis configuration file example.
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Note that in order to read the configuration file, Redis must be
4*4882a593Smuzhiyun# started with the file path as first argument:
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# ./redis-server /path/to/redis.conf
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun# Note on units: when memory size is needed, it is possible to specify
9*4882a593Smuzhiyun# it in the usual form of 1k 5GB 4M and so forth:
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun# 1k => 1000 bytes
12*4882a593Smuzhiyun# 1kb => 1024 bytes
13*4882a593Smuzhiyun# 1m => 1000000 bytes
14*4882a593Smuzhiyun# 1mb => 1024*1024 bytes
15*4882a593Smuzhiyun# 1g => 1000000000 bytes
16*4882a593Smuzhiyun# 1gb => 1024*1024*1024 bytes
17*4882a593Smuzhiyun#
18*4882a593Smuzhiyun# units are case insensitive so 1GB 1Gb 1gB are all the same.
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun################################## INCLUDES ###################################
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun# Include one or more other config files here.  This is useful if you
23*4882a593Smuzhiyun# have a standard template that goes to all Redis servers but also need
24*4882a593Smuzhiyun# to customize a few per-server settings.  Include files can include
25*4882a593Smuzhiyun# other files, so use this wisely.
26*4882a593Smuzhiyun#
27*4882a593Smuzhiyun# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
28*4882a593Smuzhiyun# from admin or Redis Sentinel. Since Redis always uses the last processed
29*4882a593Smuzhiyun# line as value of a configuration directive, you'd better put includes
30*4882a593Smuzhiyun# at the beginning of this file to avoid overwriting config change at runtime.
31*4882a593Smuzhiyun#
32*4882a593Smuzhiyun# If instead you are interested in using includes to override configuration
33*4882a593Smuzhiyun# options, it is better to use include as the last line.
34*4882a593Smuzhiyun#
35*4882a593Smuzhiyun# include /path/to/local.conf
36*4882a593Smuzhiyun# include /path/to/other.conf
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun################################## MODULES #####################################
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun# Load modules at startup. If the server is not able to load modules
41*4882a593Smuzhiyun# it will abort. It is possible to use multiple loadmodule directives.
42*4882a593Smuzhiyun#
43*4882a593Smuzhiyun# loadmodule /path/to/my_module.so
44*4882a593Smuzhiyun# loadmodule /path/to/other_module.so
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun################################## NETWORK #####################################
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun# By default, if no "bind" configuration directive is specified, Redis listens
49*4882a593Smuzhiyun# for connections from all the network interfaces available on the server.
50*4882a593Smuzhiyun# It is possible to listen to just one or multiple selected interfaces using
51*4882a593Smuzhiyun# the "bind" configuration directive, followed by one or more IP addresses.
52*4882a593Smuzhiyun#
53*4882a593Smuzhiyun# Examples:
54*4882a593Smuzhiyun#
55*4882a593Smuzhiyun# bind 192.168.1.100 10.0.0.1
56*4882a593Smuzhiyun# bind 127.0.0.1 ::1
57*4882a593Smuzhiyun#
58*4882a593Smuzhiyun# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
59*4882a593Smuzhiyun# internet, binding to all the interfaces is dangerous and will expose the
60*4882a593Smuzhiyun# instance to everybody on the internet. So by default we uncomment the
61*4882a593Smuzhiyun# following bind directive, that will force Redis to listen only into
62*4882a593Smuzhiyun# the IPv4 lookback interface address (this means Redis will be able to
63*4882a593Smuzhiyun# accept connections only from clients running into the same computer it
64*4882a593Smuzhiyun# is running).
65*4882a593Smuzhiyun#
66*4882a593Smuzhiyun# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
67*4882a593Smuzhiyun# JUST COMMENT THE FOLLOWING LINE.
68*4882a593Smuzhiyun# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69*4882a593Smuzhiyunbind 127.0.0.1
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun# Protected mode is a layer of security protection, in order to avoid that
72*4882a593Smuzhiyun# Redis instances left open on the internet are accessed and exploited.
73*4882a593Smuzhiyun#
74*4882a593Smuzhiyun# When protected mode is on and if:
75*4882a593Smuzhiyun#
76*4882a593Smuzhiyun# 1) The server is not binding explicitly to a set of addresses using the
77*4882a593Smuzhiyun#    "bind" directive.
78*4882a593Smuzhiyun# 2) No password is configured.
79*4882a593Smuzhiyun#
80*4882a593Smuzhiyun# The server only accepts connections from clients connecting from the
81*4882a593Smuzhiyun# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
82*4882a593Smuzhiyun# sockets.
83*4882a593Smuzhiyun#
84*4882a593Smuzhiyun# By default protected mode is enabled. You should disable it only if
85*4882a593Smuzhiyun# you are sure you want clients from other hosts to connect to Redis
86*4882a593Smuzhiyun# even if no authentication is configured, nor a specific set of interfaces
87*4882a593Smuzhiyun# are explicitly listed using the "bind" directive.
88*4882a593Smuzhiyunprotected-mode yes
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun# Accept connections on the specified port, default is 6379 (IANA #815344).
91*4882a593Smuzhiyun# If port 0 is specified Redis will not listen on a TCP socket.
92*4882a593Smuzhiyunport 6379
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun# TCP listen() backlog.
95*4882a593Smuzhiyun#
96*4882a593Smuzhiyun# In high requests-per-second environments you need an high backlog in order
97*4882a593Smuzhiyun# to avoid slow clients connections issues. Note that the Linux kernel
98*4882a593Smuzhiyun# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
99*4882a593Smuzhiyun# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
100*4882a593Smuzhiyun# in order to get the desired effect.
101*4882a593Smuzhiyuntcp-backlog 511
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun# Unix socket.
104*4882a593Smuzhiyun#
105*4882a593Smuzhiyun# Specify the path for the Unix socket that will be used to listen for
106*4882a593Smuzhiyun# incoming connections. There is no default, so Redis will not listen
107*4882a593Smuzhiyun# on a unix socket when not specified.
108*4882a593Smuzhiyun#
109*4882a593Smuzhiyun# unixsocket /tmp/redis.sock
110*4882a593Smuzhiyun# unixsocketperm 700
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun# Close the connection after a client is idle for N seconds (0 to disable)
113*4882a593Smuzhiyuntimeout 0
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun# TCP keepalive.
116*4882a593Smuzhiyun#
117*4882a593Smuzhiyun# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
118*4882a593Smuzhiyun# of communication. This is useful for two reasons:
119*4882a593Smuzhiyun#
120*4882a593Smuzhiyun# 1) Detect dead peers.
121*4882a593Smuzhiyun# 2) Take the connection alive from the point of view of network
122*4882a593Smuzhiyun#    equipment in the middle.
123*4882a593Smuzhiyun#
124*4882a593Smuzhiyun# On Linux, the specified value (in seconds) is the period used to send ACKs.
125*4882a593Smuzhiyun# Note that to close the connection the double of the time is needed.
126*4882a593Smuzhiyun# On other kernels the period depends on the kernel configuration.
127*4882a593Smuzhiyun#
128*4882a593Smuzhiyun# A reasonable value for this option is 300 seconds, which is the new
129*4882a593Smuzhiyun# Redis default starting with Redis 3.2.1.
130*4882a593Smuzhiyuntcp-keepalive 300
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun################################# GENERAL #####################################
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun# OE: run as a daemon.
135*4882a593Smuzhiyundaemonize yes
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun# If you run Redis from upstart or systemd, Redis can interact with your
138*4882a593Smuzhiyun# supervision tree. Options:
139*4882a593Smuzhiyun#   supervised no      - no supervision interaction
140*4882a593Smuzhiyun#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
141*4882a593Smuzhiyun#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
142*4882a593Smuzhiyun#   supervised auto    - detect upstart or systemd method based on
143*4882a593Smuzhiyun#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
144*4882a593Smuzhiyun# Note: these supervision methods only signal "process is ready."
145*4882a593Smuzhiyun#       They do not enable continuous liveness pings back to your supervisor.
146*4882a593Smuzhiyunsupervised no
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun# If a pid file is specified, Redis writes it where specified at startup
149*4882a593Smuzhiyun# and removes it at exit.
150*4882a593Smuzhiyun#
151*4882a593Smuzhiyun# When the server runs non daemonized, no pid file is created if none is
152*4882a593Smuzhiyun# specified in the configuration. When the server is daemonized, the pid file
153*4882a593Smuzhiyun# is used even if not specified, defaulting to "/var/run/redis.pid".
154*4882a593Smuzhiyun#
155*4882a593Smuzhiyun# Creating a pid file is best effort: if Redis is not able to create it
156*4882a593Smuzhiyun# nothing bad happens, the server will start and run normally.
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
159*4882a593Smuzhiyun# default. You can specify a custom pid file location here.
160*4882a593Smuzhiyunpidfile /var/run/redis.pid
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun# Specify the server verbosity level.
163*4882a593Smuzhiyun# This can be one of:
164*4882a593Smuzhiyun# debug (a lot of information, useful for development/testing)
165*4882a593Smuzhiyun# verbose (many rarely useful info, but not a mess like the debug level)
166*4882a593Smuzhiyun# notice (moderately verbose, what you want in production probably)
167*4882a593Smuzhiyun# warning (only very important / critical messages are logged)
168*4882a593Smuzhiyunloglevel notice
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun# Specify the log file name. Also the empty string can be used to force
171*4882a593Smuzhiyun# Redis to log on the standard output. Note that if you use standard
172*4882a593Smuzhiyun# output for logging but daemonize, logs will be sent to /dev/null
173*4882a593Smuzhiyunlogfile ""
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun# To enable logging to the system logger, just set 'syslog-enabled' to yes,
176*4882a593Smuzhiyun# and optionally update the other syslog parameters to suit your needs.
177*4882a593Smuzhiyunsyslog-enabled yes
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun# Specify the syslog identity.
180*4882a593Smuzhiyunsyslog-ident redis
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
183*4882a593Smuzhiyun# syslog-facility local0
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun# Set the number of databases. The default database is DB 0, you can select
186*4882a593Smuzhiyun# a different one on a per-connection basis using SELECT <dbid> where
187*4882a593Smuzhiyun# dbid is a number between 0 and 'databases'-1
188*4882a593Smuzhiyundatabases 16
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun# By default Redis shows an ASCII art logo only when started to log to the
191*4882a593Smuzhiyun# standard output and if the standard output is a TTY. Basically this means
192*4882a593Smuzhiyun# that normally a logo is displayed only in interactive sessions.
193*4882a593Smuzhiyun#
194*4882a593Smuzhiyun# However it is possible to force the pre-4.0 behavior and always show a
195*4882a593Smuzhiyun# ASCII art logo in startup logs by setting the following option to yes.
196*4882a593Smuzhiyunalways-show-logo yes
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun################################ SNAPSHOTTING  ################################
199*4882a593Smuzhiyun#
200*4882a593Smuzhiyun# Save the DB on disk:
201*4882a593Smuzhiyun#
202*4882a593Smuzhiyun#   save <seconds> <changes>
203*4882a593Smuzhiyun#
204*4882a593Smuzhiyun#   Will save the DB if both the given number of seconds and the given
205*4882a593Smuzhiyun#   number of write operations against the DB occurred.
206*4882a593Smuzhiyun#
207*4882a593Smuzhiyun#   In the example below the behaviour will be to save:
208*4882a593Smuzhiyun#   after 900 sec (15 min) if at least 1 key changed
209*4882a593Smuzhiyun#   after 300 sec (5 min) if at least 10 keys changed
210*4882a593Smuzhiyun#   after 60 sec if at least 10000 keys changed
211*4882a593Smuzhiyun#
212*4882a593Smuzhiyun#   Note: you can disable saving completely by commenting out all "save" lines.
213*4882a593Smuzhiyun#
214*4882a593Smuzhiyun#   It is also possible to remove all the previously configured save
215*4882a593Smuzhiyun#   points by adding a save directive with a single empty string argument
216*4882a593Smuzhiyun#   like in the following example:
217*4882a593Smuzhiyun#
218*4882a593Smuzhiyun#   save ""
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun#save 900 1
221*4882a593Smuzhiyun#save 300 10
222*4882a593Smuzhiyun#save 60 10000
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun# OE: tune for a small embedded system with a limited # of keys.
225*4882a593Smuzhiyunsave 120 1
226*4882a593Smuzhiyunsave 60 100
227*4882a593Smuzhiyunsave 30 1000
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun# By default Redis will stop accepting writes if RDB snapshots are enabled
230*4882a593Smuzhiyun# (at least one save point) and the latest background save failed.
231*4882a593Smuzhiyun# This will make the user aware (in a hard way) that data is not persisting
232*4882a593Smuzhiyun# on disk properly, otherwise chances are that no one will notice and some
233*4882a593Smuzhiyun# disaster will happen.
234*4882a593Smuzhiyun#
235*4882a593Smuzhiyun# If the background saving process will start working again Redis will
236*4882a593Smuzhiyun# automatically allow writes again.
237*4882a593Smuzhiyun#
238*4882a593Smuzhiyun# However if you have setup your proper monitoring of the Redis server
239*4882a593Smuzhiyun# and persistence, you may want to disable this feature so that Redis will
240*4882a593Smuzhiyun# continue to work as usual even if there are problems with disk,
241*4882a593Smuzhiyun# permissions, and so forth.
242*4882a593Smuzhiyunstop-writes-on-bgsave-error yes
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun# Compress string objects using LZF when dump .rdb databases?
245*4882a593Smuzhiyun# For default that's set to 'yes' as it's almost always a win.
246*4882a593Smuzhiyun# If you want to save some CPU in the saving child set it to 'no' but
247*4882a593Smuzhiyun# the dataset will likely be bigger if you have compressible values or keys.
248*4882a593Smuzhiyunrdbcompression yes
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
251*4882a593Smuzhiyun# This makes the format more resistant to corruption but there is a performance
252*4882a593Smuzhiyun# hit to pay (around 10%) when saving and loading RDB files, so you can disable it
253*4882a593Smuzhiyun# for maximum performances.
254*4882a593Smuzhiyun#
255*4882a593Smuzhiyun# RDB files created with checksum disabled have a checksum of zero that will
256*4882a593Smuzhiyun# tell the loading code to skip the check.
257*4882a593Smuzhiyunrdbchecksum yes
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun# The filename where to dump the DB
260*4882a593Smuzhiyundbfilename dump.rdb
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun# The working directory.
263*4882a593Smuzhiyun#
264*4882a593Smuzhiyun# The DB will be written inside this directory, with the filename specified
265*4882a593Smuzhiyun# above using the 'dbfilename' configuration directive.
266*4882a593Smuzhiyun#
267*4882a593Smuzhiyun# The Append Only File will also be created inside this directory.
268*4882a593Smuzhiyun#
269*4882a593Smuzhiyun# Note that you must specify a directory here, not a file name.
270*4882a593Smuzhiyundir /var/lib/redis/
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun################################# REPLICATION #################################
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun# Master-Slave replication. Use slaveof to make a Redis instance a copy of
275*4882a593Smuzhiyun# another Redis server. A few things to understand ASAP about Redis replication.
276*4882a593Smuzhiyun#
277*4882a593Smuzhiyun# 1) Redis replication is asynchronous, but you can configure a master to
278*4882a593Smuzhiyun#    stop accepting writes if it appears to be not connected with at least
279*4882a593Smuzhiyun#    a given number of slaves.
280*4882a593Smuzhiyun# 2) Redis slaves are able to perform a partial resynchronization with the
281*4882a593Smuzhiyun#    master if the replication link is lost for a relatively small amount of
282*4882a593Smuzhiyun#    time. You may want to configure the replication backlog size (see the next
283*4882a593Smuzhiyun#    sections of this file) with a sensible value depending on your needs.
284*4882a593Smuzhiyun# 3) Replication is automatic and does not need user intervention. After a
285*4882a593Smuzhiyun#    network partition slaves automatically try to reconnect to masters
286*4882a593Smuzhiyun#    and resynchronize with them.
287*4882a593Smuzhiyun#
288*4882a593Smuzhiyun# slaveof <masterip> <masterport>
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun# If the master is password protected (using the "requirepass" configuration
291*4882a593Smuzhiyun# directive below) it is possible to tell the slave to authenticate before
292*4882a593Smuzhiyun# starting the replication synchronization process, otherwise the master will
293*4882a593Smuzhiyun# refuse the slave request.
294*4882a593Smuzhiyun#
295*4882a593Smuzhiyun# masterauth <master-password>
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun# When a slave loses its connection with the master, or when the replication
298*4882a593Smuzhiyun# is still in progress, the slave can act in two different ways:
299*4882a593Smuzhiyun#
300*4882a593Smuzhiyun# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
301*4882a593Smuzhiyun#    still reply to client requests, possibly with out of date data, or the
302*4882a593Smuzhiyun#    data set may just be empty if this is the first synchronization.
303*4882a593Smuzhiyun#
304*4882a593Smuzhiyun# 2) if slave-serve-stale-data is set to 'no' the slave will reply with
305*4882a593Smuzhiyun#    an error "SYNC with master in progress" to all the kind of commands
306*4882a593Smuzhiyun#    but to INFO and SLAVEOF.
307*4882a593Smuzhiyun#
308*4882a593Smuzhiyunslave-serve-stale-data yes
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun# You can configure a slave instance to accept writes or not. Writing against
311*4882a593Smuzhiyun# a slave instance may be useful to store some ephemeral data (because data
312*4882a593Smuzhiyun# written on a slave will be easily deleted after resync with the master) but
313*4882a593Smuzhiyun# may also cause problems if clients are writing to it because of a
314*4882a593Smuzhiyun# misconfiguration.
315*4882a593Smuzhiyun#
316*4882a593Smuzhiyun# Since Redis 2.6 by default slaves are read-only.
317*4882a593Smuzhiyun#
318*4882a593Smuzhiyun# Note: read only slaves are not designed to be exposed to untrusted clients
319*4882a593Smuzhiyun# on the internet. It's just a protection layer against misuse of the instance.
320*4882a593Smuzhiyun# Still a read only slave exports by default all the administrative commands
321*4882a593Smuzhiyun# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
322*4882a593Smuzhiyun# security of read only slaves using 'rename-command' to shadow all the
323*4882a593Smuzhiyun# administrative / dangerous commands.
324*4882a593Smuzhiyunslave-read-only yes
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun# Replication SYNC strategy: disk or socket.
327*4882a593Smuzhiyun#
328*4882a593Smuzhiyun# -------------------------------------------------------
329*4882a593Smuzhiyun# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
330*4882a593Smuzhiyun# -------------------------------------------------------
331*4882a593Smuzhiyun#
332*4882a593Smuzhiyun# New slaves and reconnecting slaves that are not able to continue the replication
333*4882a593Smuzhiyun# process just receiving differences, need to do what is called a "full
334*4882a593Smuzhiyun# synchronization". An RDB file is transmitted from the master to the slaves.
335*4882a593Smuzhiyun# The transmission can happen in two different ways:
336*4882a593Smuzhiyun#
337*4882a593Smuzhiyun# 1) Disk-backed: The Redis master creates a new process that writes the RDB
338*4882a593Smuzhiyun#                 file on disk. Later the file is transferred by the parent
339*4882a593Smuzhiyun#                 process to the slaves incrementally.
340*4882a593Smuzhiyun# 2) Diskless: The Redis master creates a new process that directly writes the
341*4882a593Smuzhiyun#              RDB file to slave sockets, without touching the disk at all.
342*4882a593Smuzhiyun#
343*4882a593Smuzhiyun# With disk-backed replication, while the RDB file is generated, more slaves
344*4882a593Smuzhiyun# can be queued and served with the RDB file as soon as the current child producing
345*4882a593Smuzhiyun# the RDB file finishes its work. With diskless replication instead once
346*4882a593Smuzhiyun# the transfer starts, new slaves arriving will be queued and a new transfer
347*4882a593Smuzhiyun# will start when the current one terminates.
348*4882a593Smuzhiyun#
349*4882a593Smuzhiyun# When diskless replication is used, the master waits a configurable amount of
350*4882a593Smuzhiyun# time (in seconds) before starting the transfer in the hope that multiple slaves
351*4882a593Smuzhiyun# will arrive and the transfer can be parallelized.
352*4882a593Smuzhiyun#
353*4882a593Smuzhiyun# With slow disks and fast (large bandwidth) networks, diskless replication
354*4882a593Smuzhiyun# works better.
355*4882a593Smuzhiyunrepl-diskless-sync no
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun# When diskless replication is enabled, it is possible to configure the delay
358*4882a593Smuzhiyun# the server waits in order to spawn the child that transfers the RDB via socket
359*4882a593Smuzhiyun# to the slaves.
360*4882a593Smuzhiyun#
361*4882a593Smuzhiyun# This is important since once the transfer starts, it is not possible to serve
362*4882a593Smuzhiyun# new slaves arriving, that will be queued for the next RDB transfer, so the server
363*4882a593Smuzhiyun# waits a delay in order to let more slaves arrive.
364*4882a593Smuzhiyun#
365*4882a593Smuzhiyun# The delay is specified in seconds, and by default is 5 seconds. To disable
366*4882a593Smuzhiyun# it entirely just set it to 0 seconds and the transfer will start ASAP.
367*4882a593Smuzhiyunrepl-diskless-sync-delay 5
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun# Slaves send PINGs to server in a predefined interval. It's possible to change
370*4882a593Smuzhiyun# this interval with the repl_ping_slave_period option. The default value is 10
371*4882a593Smuzhiyun# seconds.
372*4882a593Smuzhiyun#
373*4882a593Smuzhiyun# repl-ping-slave-period 10
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun# The following option sets the replication timeout for:
376*4882a593Smuzhiyun#
377*4882a593Smuzhiyun# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
378*4882a593Smuzhiyun# 2) Master timeout from the point of view of slaves (data, pings).
379*4882a593Smuzhiyun# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
380*4882a593Smuzhiyun#
381*4882a593Smuzhiyun# It is important to make sure that this value is greater than the value
382*4882a593Smuzhiyun# specified for repl-ping-slave-period otherwise a timeout will be detected
383*4882a593Smuzhiyun# every time there is low traffic between the master and the slave.
384*4882a593Smuzhiyun#
385*4882a593Smuzhiyun# repl-timeout 60
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun# Disable TCP_NODELAY on the slave socket after SYNC?
388*4882a593Smuzhiyun#
389*4882a593Smuzhiyun# If you select "yes" Redis will use a smaller number of TCP packets and
390*4882a593Smuzhiyun# less bandwidth to send data to slaves. But this can add a delay for
391*4882a593Smuzhiyun# the data to appear on the slave side, up to 40 milliseconds with
392*4882a593Smuzhiyun# Linux kernels using a default configuration.
393*4882a593Smuzhiyun#
394*4882a593Smuzhiyun# If you select "no" the delay for data to appear on the slave side will
395*4882a593Smuzhiyun# be reduced but more bandwidth will be used for replication.
396*4882a593Smuzhiyun#
397*4882a593Smuzhiyun# By default we optimize for low latency, but in very high traffic conditions
398*4882a593Smuzhiyun# or when the master and slaves are many hops away, turning this to "yes" may
399*4882a593Smuzhiyun# be a good idea.
400*4882a593Smuzhiyunrepl-disable-tcp-nodelay no
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun# Set the replication backlog size. The backlog is a buffer that accumulates
403*4882a593Smuzhiyun# slave data when slaves are disconnected for some time, so that when a slave
404*4882a593Smuzhiyun# wants to reconnect again, often a full resync is not needed, but a partial
405*4882a593Smuzhiyun# resync is enough, just passing the portion of data the slave missed while
406*4882a593Smuzhiyun# disconnected.
407*4882a593Smuzhiyun#
408*4882a593Smuzhiyun# The bigger the replication backlog, the longer the time the slave can be
409*4882a593Smuzhiyun# disconnected and later be able to perform a partial resynchronization.
410*4882a593Smuzhiyun#
411*4882a593Smuzhiyun# The backlog is only allocated once there is at least a slave connected.
412*4882a593Smuzhiyun#
413*4882a593Smuzhiyun# repl-backlog-size 1mb
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun# After a master has no longer connected slaves for some time, the backlog
416*4882a593Smuzhiyun# will be freed. The following option configures the amount of seconds that
417*4882a593Smuzhiyun# need to elapse, starting from the time the last slave disconnected, for
418*4882a593Smuzhiyun# the backlog buffer to be freed.
419*4882a593Smuzhiyun#
420*4882a593Smuzhiyun# Note that slaves never free the backlog for timeout, since they may be
421*4882a593Smuzhiyun# promoted to masters later, and should be able to correctly "partially
422*4882a593Smuzhiyun# resynchronize" with the slaves: hence they should always accumulate backlog.
423*4882a593Smuzhiyun#
424*4882a593Smuzhiyun# A value of 0 means to never release the backlog.
425*4882a593Smuzhiyun#
426*4882a593Smuzhiyun# repl-backlog-ttl 3600
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun# The slave priority is an integer number published by Redis in the INFO output.
429*4882a593Smuzhiyun# It is used by Redis Sentinel in order to select a slave to promote into a
430*4882a593Smuzhiyun# master if the master is no longer working correctly.
431*4882a593Smuzhiyun#
432*4882a593Smuzhiyun# A slave with a low priority number is considered better for promotion, so
433*4882a593Smuzhiyun# for instance if there are three slaves with priority 10, 100, 25 Sentinel will
434*4882a593Smuzhiyun# pick the one with priority 10, that is the lowest.
435*4882a593Smuzhiyun#
436*4882a593Smuzhiyun# However a special priority of 0 marks the slave as not able to perform the
437*4882a593Smuzhiyun# role of master, so a slave with priority of 0 will never be selected by
438*4882a593Smuzhiyun# Redis Sentinel for promotion.
439*4882a593Smuzhiyun#
440*4882a593Smuzhiyun# By default the priority is 100.
441*4882a593Smuzhiyunslave-priority 100
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun# It is possible for a master to stop accepting writes if there are less than
444*4882a593Smuzhiyun# N slaves connected, having a lag less or equal than M seconds.
445*4882a593Smuzhiyun#
446*4882a593Smuzhiyun# The N slaves need to be in "online" state.
447*4882a593Smuzhiyun#
448*4882a593Smuzhiyun# The lag in seconds, that must be <= the specified value, is calculated from
449*4882a593Smuzhiyun# the last ping received from the slave, that is usually sent every second.
450*4882a593Smuzhiyun#
451*4882a593Smuzhiyun# This option does not GUARANTEE that N replicas will accept the write, but
452*4882a593Smuzhiyun# will limit the window of exposure for lost writes in case not enough slaves
453*4882a593Smuzhiyun# are available, to the specified number of seconds.
454*4882a593Smuzhiyun#
455*4882a593Smuzhiyun# For example to require at least 3 slaves with a lag <= 10 seconds use:
456*4882a593Smuzhiyun#
457*4882a593Smuzhiyun# min-slaves-to-write 3
458*4882a593Smuzhiyun# min-slaves-max-lag 10
459*4882a593Smuzhiyun#
460*4882a593Smuzhiyun# Setting one or the other to 0 disables the feature.
461*4882a593Smuzhiyun#
462*4882a593Smuzhiyun# By default min-slaves-to-write is set to 0 (feature disabled) and
463*4882a593Smuzhiyun# min-slaves-max-lag is set to 10.
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun# A Redis master is able to list the address and port of the attached
466*4882a593Smuzhiyun# slaves in different ways. For example the "INFO replication" section
467*4882a593Smuzhiyun# offers this information, which is used, among other tools, by
468*4882a593Smuzhiyun# Redis Sentinel in order to discover slave instances.
469*4882a593Smuzhiyun# Another place where this info is available is in the output of the
470*4882a593Smuzhiyun# "ROLE" command of a master.
471*4882a593Smuzhiyun#
472*4882a593Smuzhiyun# The listed IP and address normally reported by a slave is obtained
473*4882a593Smuzhiyun# in the following way:
474*4882a593Smuzhiyun#
475*4882a593Smuzhiyun#   IP: The address is auto detected by checking the peer address
476*4882a593Smuzhiyun#   of the socket used by the slave to connect with the master.
477*4882a593Smuzhiyun#
478*4882a593Smuzhiyun#   Port: The port is communicated by the slave during the replication
479*4882a593Smuzhiyun#   handshake, and is normally the port that the slave is using to
480*4882a593Smuzhiyun#   list for connections.
481*4882a593Smuzhiyun#
482*4882a593Smuzhiyun# However when port forwarding or Network Address Translation (NAT) is
483*4882a593Smuzhiyun# used, the slave may be actually reachable via different IP and port
484*4882a593Smuzhiyun# pairs. The following two options can be used by a slave in order to
485*4882a593Smuzhiyun# report to its master a specific set of IP and port, so that both INFO
486*4882a593Smuzhiyun# and ROLE will report those values.
487*4882a593Smuzhiyun#
488*4882a593Smuzhiyun# There is no need to use both the options if you need to override just
489*4882a593Smuzhiyun# the port or the IP address.
490*4882a593Smuzhiyun#
491*4882a593Smuzhiyun# slave-announce-ip 5.5.5.5
492*4882a593Smuzhiyun# slave-announce-port 1234
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun################################## SECURITY ###################################
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun# Require clients to issue AUTH <PASSWORD> before processing any other
497*4882a593Smuzhiyun# commands.  This might be useful in environments in which you do not trust
498*4882a593Smuzhiyun# others with access to the host running redis-server.
499*4882a593Smuzhiyun#
500*4882a593Smuzhiyun# This should stay commented out for backward compatibility and because most
501*4882a593Smuzhiyun# people do not need auth (e.g. they run their own servers).
502*4882a593Smuzhiyun#
503*4882a593Smuzhiyun# Warning: since Redis is pretty fast an outside user can try up to
504*4882a593Smuzhiyun# 150k passwords per second against a good box. This means that you should
505*4882a593Smuzhiyun# use a very strong password otherwise it will be very easy to break.
506*4882a593Smuzhiyun#
507*4882a593Smuzhiyun# requirepass foobared
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun# Command renaming.
510*4882a593Smuzhiyun#
511*4882a593Smuzhiyun# It is possible to change the name of dangerous commands in a shared
512*4882a593Smuzhiyun# environment. For instance the CONFIG command may be renamed into something
513*4882a593Smuzhiyun# hard to guess so that it will still be available for internal-use tools
514*4882a593Smuzhiyun# but not available for general clients.
515*4882a593Smuzhiyun#
516*4882a593Smuzhiyun# Example:
517*4882a593Smuzhiyun#
518*4882a593Smuzhiyun# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
519*4882a593Smuzhiyun#
520*4882a593Smuzhiyun# It is also possible to completely kill a command by renaming it into
521*4882a593Smuzhiyun# an empty string:
522*4882a593Smuzhiyun#
523*4882a593Smuzhiyun# rename-command CONFIG ""
524*4882a593Smuzhiyun#
525*4882a593Smuzhiyun# Please note that changing the name of commands that are logged into the
526*4882a593Smuzhiyun# AOF file or transmitted to slaves may cause problems.
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun################################### CLIENTS ####################################
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun# Set the max number of connected clients at the same time. By default
531*4882a593Smuzhiyun# this limit is set to 10000 clients, however if the Redis server is not
532*4882a593Smuzhiyun# able to configure the process file limit to allow for the specified limit
533*4882a593Smuzhiyun# the max number of allowed clients is set to the current file limit
534*4882a593Smuzhiyun# minus 32 (as Redis reserves a few file descriptors for internal uses).
535*4882a593Smuzhiyun#
536*4882a593Smuzhiyun# Once the limit is reached Redis will close all the new connections sending
537*4882a593Smuzhiyun# an error 'max number of clients reached'.
538*4882a593Smuzhiyun#
539*4882a593Smuzhiyun# maxclients 10000
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun############################## MEMORY MANAGEMENT ################################
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun# Set a memory usage limit to the specified amount of bytes.
544*4882a593Smuzhiyun# When the memory limit is reached Redis will try to remove keys
545*4882a593Smuzhiyun# according to the eviction policy selected (see maxmemory-policy).
546*4882a593Smuzhiyun#
547*4882a593Smuzhiyun# If Redis can't remove keys according to the policy, or if the policy is
548*4882a593Smuzhiyun# set to 'noeviction', Redis will start to reply with errors to commands
549*4882a593Smuzhiyun# that would use more memory, like SET, LPUSH, and so on, and will continue
550*4882a593Smuzhiyun# to reply to read-only commands like GET.
551*4882a593Smuzhiyun#
552*4882a593Smuzhiyun# This option is usually useful when using Redis as an LRU or LFU cache, or to
553*4882a593Smuzhiyun# set a hard memory limit for an instance (using the 'noeviction' policy).
554*4882a593Smuzhiyun#
555*4882a593Smuzhiyun# WARNING: If you have slaves attached to an instance with maxmemory on,
556*4882a593Smuzhiyun# the size of the output buffers needed to feed the slaves are subtracted
557*4882a593Smuzhiyun# from the used memory count, so that network problems / resyncs will
558*4882a593Smuzhiyun# not trigger a loop where keys are evicted, and in turn the output
559*4882a593Smuzhiyun# buffer of slaves is full with DELs of keys evicted triggering the deletion
560*4882a593Smuzhiyun# of more keys, and so forth until the database is completely emptied.
561*4882a593Smuzhiyun#
562*4882a593Smuzhiyun# In short... if you have slaves attached it is suggested that you set a lower
563*4882a593Smuzhiyun# limit for maxmemory so that there is some free RAM on the system for slave
564*4882a593Smuzhiyun# output buffers (but this is not needed if the policy is 'noeviction').
565*4882a593Smuzhiyun#
566*4882a593Smuzhiyun# maxmemory <bytes>
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
569*4882a593Smuzhiyun# is reached. You can select among five behaviors:
570*4882a593Smuzhiyun#
571*4882a593Smuzhiyun# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
572*4882a593Smuzhiyun# allkeys-lru -> Evict any key using approximated LRU.
573*4882a593Smuzhiyun# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
574*4882a593Smuzhiyun# allkeys-lfu -> Evict any key using approximated LFU.
575*4882a593Smuzhiyun# volatile-random -> Remove a random key among the ones with an expire set.
576*4882a593Smuzhiyun# allkeys-random -> Remove a random key, any key.
577*4882a593Smuzhiyun# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
578*4882a593Smuzhiyun# noeviction -> Don't evict anything, just return an error on write operations.
579*4882a593Smuzhiyun#
580*4882a593Smuzhiyun# LRU means Least Recently Used
581*4882a593Smuzhiyun# LFU means Least Frequently Used
582*4882a593Smuzhiyun#
583*4882a593Smuzhiyun# Both LRU, LFU and volatile-ttl are implemented using approximated
584*4882a593Smuzhiyun# randomized algorithms.
585*4882a593Smuzhiyun#
586*4882a593Smuzhiyun# Note: with any of the above policies, Redis will return an error on write
587*4882a593Smuzhiyun#       operations, when there are no suitable keys for eviction.
588*4882a593Smuzhiyun#
589*4882a593Smuzhiyun#       At the date of writing these commands are: set setnx setex append
590*4882a593Smuzhiyun#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
591*4882a593Smuzhiyun#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
592*4882a593Smuzhiyun#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
593*4882a593Smuzhiyun#       getset mset msetnx exec sort
594*4882a593Smuzhiyun#
595*4882a593Smuzhiyun# The default is:
596*4882a593Smuzhiyun#
597*4882a593Smuzhiyun# maxmemory-policy noeviction
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
600*4882a593Smuzhiyun# algorithms (in order to save memory), so you can tune it for speed or
601*4882a593Smuzhiyun# accuracy. For default Redis will check five keys and pick the one that was
602*4882a593Smuzhiyun# used less recently, you can change the sample size using the following
603*4882a593Smuzhiyun# configuration directive.
604*4882a593Smuzhiyun#
605*4882a593Smuzhiyun# The default of 5 produces good enough results. 10 Approximates very closely
606*4882a593Smuzhiyun# true LRU but costs more CPU. 3 is faster but not very accurate.
607*4882a593Smuzhiyun#
608*4882a593Smuzhiyun# maxmemory-samples 5
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun############################# LAZY FREEING ####################################
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun# Redis has two primitives to delete keys. One is called DEL and is a blocking
613*4882a593Smuzhiyun# deletion of the object. It means that the server stops processing new commands
614*4882a593Smuzhiyun# in order to reclaim all the memory associated with an object in a synchronous
615*4882a593Smuzhiyun# way. If the key deleted is associated with a small object, the time needed
616*4882a593Smuzhiyun# in order to execute the DEL command is very small and comparable to most other
617*4882a593Smuzhiyun# O(1) or O(log_N) commands in Redis. However if the key is associated with an
618*4882a593Smuzhiyun# aggregated value containing millions of elements, the server can block for
619*4882a593Smuzhiyun# a long time (even seconds) in order to complete the operation.
620*4882a593Smuzhiyun#
621*4882a593Smuzhiyun# For the above reasons Redis also offers non blocking deletion primitives
622*4882a593Smuzhiyun# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and
623*4882a593Smuzhiyun# FLUSHDB commands, in order to reclaim memory in background. Those commands
624*4882a593Smuzhiyun# are executed in constant time. Another thread will incrementally free the
625*4882a593Smuzhiyun# object in the background as fast as possible.
626*4882a593Smuzhiyun#
627*4882a593Smuzhiyun# DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.
628*4882a593Smuzhiyun# It's up to the design of the application to understand when it is a good
629*4882a593Smuzhiyun# idea to use one or the other. However the Redis server sometimes has to
630*4882a593Smuzhiyun# delete keys or flush the whole database as a side effect of other operations.
631*4882a593Smuzhiyun# Specifically Redis deletes objects independently of a user call in the
632*4882a593Smuzhiyun# following scenarios:
633*4882a593Smuzhiyun#
634*4882a593Smuzhiyun# 1) On eviction, because of the maxmemory and maxmemory policy configurations,
635*4882a593Smuzhiyun#    in order to make room for new data, without going over the specified
636*4882a593Smuzhiyun#    memory limit.
637*4882a593Smuzhiyun# 2) Because of expire: when a key with an associated time to live (see the
638*4882a593Smuzhiyun#    EXPIRE command) must be deleted from memory.
639*4882a593Smuzhiyun# 3) Because of a side effect of a command that stores data on a key that may
640*4882a593Smuzhiyun#    already exist. For example the RENAME command may delete the old key
641*4882a593Smuzhiyun#    content when it is replaced with another one. Similarly SUNIONSTORE
642*4882a593Smuzhiyun#    or SORT with STORE option may delete existing keys. The SET command
643*4882a593Smuzhiyun#    itself removes any old content of the specified key in order to replace
644*4882a593Smuzhiyun#    it with the specified string.
645*4882a593Smuzhiyun# 4) During replication, when a slave performs a full resynchronization with
646*4882a593Smuzhiyun#    its master, the content of the whole database is removed in order to
647*4882a593Smuzhiyun#    load the RDB file just transfered.
648*4882a593Smuzhiyun#
649*4882a593Smuzhiyun# In all the above cases the default is to delete objects in a blocking way,
650*4882a593Smuzhiyun# like if DEL was called. However you can configure each case specifically
651*4882a593Smuzhiyun# in order to instead release memory in a non-blocking way like if UNLINK
652*4882a593Smuzhiyun# was called, using the following configuration directives:
653*4882a593Smuzhiyun
654*4882a593Smuzhiyunlazyfree-lazy-eviction no
655*4882a593Smuzhiyunlazyfree-lazy-expire no
656*4882a593Smuzhiyunlazyfree-lazy-server-del no
657*4882a593Smuzhiyunslave-lazy-flush no
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun############################## APPEND ONLY MODE ###############################
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun# By default Redis asynchronously dumps the dataset on disk. This mode is
662*4882a593Smuzhiyun# good enough in many applications, but an issue with the Redis process or
663*4882a593Smuzhiyun# a power outage may result into a few minutes of writes lost (depending on
664*4882a593Smuzhiyun# the configured save points).
665*4882a593Smuzhiyun#
666*4882a593Smuzhiyun# The Append Only File is an alternative persistence mode that provides
667*4882a593Smuzhiyun# much better durability. For instance using the default data fsync policy
668*4882a593Smuzhiyun# (see later in the config file) Redis can lose just one second of writes in a
669*4882a593Smuzhiyun# dramatic event like a server power outage, or a single write if something
670*4882a593Smuzhiyun# wrong with the Redis process itself happens, but the operating system is
671*4882a593Smuzhiyun# still running correctly.
672*4882a593Smuzhiyun#
673*4882a593Smuzhiyun# AOF and RDB persistence can be enabled at the same time without problems.
674*4882a593Smuzhiyun# If the AOF is enabled on startup Redis will load the AOF, that is the file
675*4882a593Smuzhiyun# with the better durability guarantees.
676*4882a593Smuzhiyun#
677*4882a593Smuzhiyun# Please check http://redis.io/topics/persistence for more information.
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun# OE: changed default to enable this
680*4882a593Smuzhiyunappendonly yes
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun# The name of the append only file (default: "appendonly.aof")
683*4882a593Smuzhiyun
684*4882a593Smuzhiyunappendfilename "appendonly.aof"
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun# The fsync() call tells the Operating System to actually write data on disk
687*4882a593Smuzhiyun# instead of waiting for more data in the output buffer. Some OS will really flush
688*4882a593Smuzhiyun# data on disk, some other OS will just try to do it ASAP.
689*4882a593Smuzhiyun#
690*4882a593Smuzhiyun# Redis supports three different modes:
691*4882a593Smuzhiyun#
692*4882a593Smuzhiyun# no: don't fsync, just let the OS flush the data when it wants. Faster.
693*4882a593Smuzhiyun# always: fsync after every write to the append only log. Slow, Safest.
694*4882a593Smuzhiyun# everysec: fsync only one time every second. Compromise.
695*4882a593Smuzhiyun#
696*4882a593Smuzhiyun# The default is "everysec", as that's usually the right compromise between
697*4882a593Smuzhiyun# speed and data safety. It's up to you to understand if you can relax this to
698*4882a593Smuzhiyun# "no" that will let the operating system flush the output buffer when
699*4882a593Smuzhiyun# it wants, for better performances (but if you can live with the idea of
700*4882a593Smuzhiyun# some data loss consider the default persistence mode that's snapshotting),
701*4882a593Smuzhiyun# or on the contrary, use "always" that's very slow but a bit safer than
702*4882a593Smuzhiyun# everysec.
703*4882a593Smuzhiyun#
704*4882a593Smuzhiyun# More details please check the following article:
705*4882a593Smuzhiyun# http://antirez.com/post/redis-persistence-demystified.html
706*4882a593Smuzhiyun#
707*4882a593Smuzhiyun# If unsure, use "everysec".
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun# appendfsync always
710*4882a593Smuzhiyunappendfsync everysec
711*4882a593Smuzhiyun# appendfsync no
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun# When the AOF fsync policy is set to always or everysec, and a background
714*4882a593Smuzhiyun# saving process (a background save or AOF log background rewriting) is
715*4882a593Smuzhiyun# performing a lot of I/O against the disk, in some Linux configurations
716*4882a593Smuzhiyun# Redis may block too long on the fsync() call. Note that there is no fix for
717*4882a593Smuzhiyun# this currently, as even performing fsync in a different thread will block
718*4882a593Smuzhiyun# our synchronous write(2) call.
719*4882a593Smuzhiyun#
720*4882a593Smuzhiyun# In order to mitigate this problem it's possible to use the following option
721*4882a593Smuzhiyun# that will prevent fsync() from being called in the main process while a
722*4882a593Smuzhiyun# BGSAVE or BGREWRITEAOF is in progress.
723*4882a593Smuzhiyun#
724*4882a593Smuzhiyun# This means that while another child is saving, the durability of Redis is
725*4882a593Smuzhiyun# the same as "appendfsync none". In practical terms, this means that it is
726*4882a593Smuzhiyun# possible to lose up to 30 seconds of log in the worst scenario (with the
727*4882a593Smuzhiyun# default Linux settings).
728*4882a593Smuzhiyun#
729*4882a593Smuzhiyun# If you have latency problems turn this to "yes". Otherwise leave it as
730*4882a593Smuzhiyun# "no" that is the safest pick from the point of view of durability.
731*4882a593Smuzhiyun
732*4882a593Smuzhiyunno-appendfsync-on-rewrite no
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun# Automatic rewrite of the append only file.
735*4882a593Smuzhiyun# Redis is able to automatically rewrite the log file implicitly calling
736*4882a593Smuzhiyun# BGREWRITEAOF when the AOF log size grows by the specified percentage.
737*4882a593Smuzhiyun#
738*4882a593Smuzhiyun# This is how it works: Redis remembers the size of the AOF file after the
739*4882a593Smuzhiyun# latest rewrite (if no rewrite has happened since the restart, the size of
740*4882a593Smuzhiyun# the AOF at startup is used).
741*4882a593Smuzhiyun#
742*4882a593Smuzhiyun# This base size is compared to the current size. If the current size is
743*4882a593Smuzhiyun# bigger than the specified percentage, the rewrite is triggered. Also
744*4882a593Smuzhiyun# you need to specify a minimal size for the AOF file to be rewritten, this
745*4882a593Smuzhiyun# is useful to avoid rewriting the AOF file even if the percentage increase
746*4882a593Smuzhiyun# is reached but it is still pretty small.
747*4882a593Smuzhiyun#
748*4882a593Smuzhiyun# Specify a percentage of zero in order to disable the automatic AOF
749*4882a593Smuzhiyun# rewrite feature.
750*4882a593Smuzhiyun
751*4882a593Smuzhiyunauto-aof-rewrite-percentage 100
752*4882a593Smuzhiyunauto-aof-rewrite-min-size 64mb
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun# An AOF file may be found to be truncated at the end during the Redis
755*4882a593Smuzhiyun# startup process, when the AOF data gets loaded back into memory.
756*4882a593Smuzhiyun# This may happen when the system where Redis is running
757*4882a593Smuzhiyun# crashes, especially when an ext4 filesystem is mounted without the
758*4882a593Smuzhiyun# data=ordered option (however this can't happen when Redis itself
759*4882a593Smuzhiyun# crashes or aborts but the operating system still works correctly).
760*4882a593Smuzhiyun#
761*4882a593Smuzhiyun# Redis can either exit with an error when this happens, or load as much
762*4882a593Smuzhiyun# data as possible (the default now) and start if the AOF file is found
763*4882a593Smuzhiyun# to be truncated at the end. The following option controls this behavior.
764*4882a593Smuzhiyun#
765*4882a593Smuzhiyun# If aof-load-truncated is set to yes, a truncated AOF file is loaded and
766*4882a593Smuzhiyun# the Redis server starts emitting a log to inform the user of the event.
767*4882a593Smuzhiyun# Otherwise if the option is set to no, the server aborts with an error
768*4882a593Smuzhiyun# and refuses to start. When the option is set to no, the user requires
769*4882a593Smuzhiyun# to fix the AOF file using the "redis-check-aof" utility before to restart
770*4882a593Smuzhiyun# the server.
771*4882a593Smuzhiyun#
772*4882a593Smuzhiyun# Note that if the AOF file will be found to be corrupted in the middle
773*4882a593Smuzhiyun# the server will still exit with an error. This option only applies when
774*4882a593Smuzhiyun# Redis will try to read more data from the AOF file but not enough bytes
775*4882a593Smuzhiyun# will be found.
776*4882a593Smuzhiyunaof-load-truncated yes
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun# When rewriting the AOF file, Redis is able to use an RDB preamble in the
779*4882a593Smuzhiyun# AOF file for faster rewrites and recoveries. When this option is turned
780*4882a593Smuzhiyun# on the rewritten AOF file is composed of two different stanzas:
781*4882a593Smuzhiyun#
782*4882a593Smuzhiyun#   [RDB file][AOF tail]
783*4882a593Smuzhiyun#
784*4882a593Smuzhiyun# When loading Redis recognizes that the AOF file starts with the "REDIS"
785*4882a593Smuzhiyun# string and loads the prefixed RDB file, and continues loading the AOF
786*4882a593Smuzhiyun# tail.
787*4882a593Smuzhiyun#
788*4882a593Smuzhiyun# This is currently turned off by default in order to avoid the surprise
789*4882a593Smuzhiyun# of a format change, but will at some point be used as the default.
790*4882a593Smuzhiyunaof-use-rdb-preamble no
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun################################ LUA SCRIPTING  ###############################
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun# Max execution time of a Lua script in milliseconds.
795*4882a593Smuzhiyun#
796*4882a593Smuzhiyun# If the maximum execution time is reached Redis will log that a script is
797*4882a593Smuzhiyun# still in execution after the maximum allowed time and will start to
798*4882a593Smuzhiyun# reply to queries with an error.
799*4882a593Smuzhiyun#
800*4882a593Smuzhiyun# When a long running script exceeds the maximum execution time only the
801*4882a593Smuzhiyun# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
802*4882a593Smuzhiyun# used to stop a script that did not yet called write commands. The second
803*4882a593Smuzhiyun# is the only way to shut down the server in the case a write command was
804*4882a593Smuzhiyun# already issued by the script but the user doesn't want to wait for the natural
805*4882a593Smuzhiyun# termination of the script.
806*4882a593Smuzhiyun#
807*4882a593Smuzhiyun# Set it to 0 or a negative value for unlimited execution without warnings.
808*4882a593Smuzhiyunlua-time-limit 5000
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun################################ REDIS CLUSTER  ###############################
811*4882a593Smuzhiyun#
812*4882a593Smuzhiyun# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
813*4882a593Smuzhiyun# WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however
814*4882a593Smuzhiyun# in order to mark it as "mature" we need to wait for a non trivial percentage
815*4882a593Smuzhiyun# of users to deploy it in production.
816*4882a593Smuzhiyun# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
817*4882a593Smuzhiyun#
818*4882a593Smuzhiyun# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
819*4882a593Smuzhiyun# started as cluster nodes can. In order to start a Redis instance as a
820*4882a593Smuzhiyun# cluster node enable the cluster support uncommenting the following:
821*4882a593Smuzhiyun#
822*4882a593Smuzhiyun# cluster-enabled yes
823*4882a593Smuzhiyun
824*4882a593Smuzhiyun# Every cluster node has a cluster configuration file. This file is not
825*4882a593Smuzhiyun# intended to be edited by hand. It is created and updated by Redis nodes.
826*4882a593Smuzhiyun# Every Redis Cluster node requires a different cluster configuration file.
827*4882a593Smuzhiyun# Make sure that instances running in the same system do not have
828*4882a593Smuzhiyun# overlapping cluster configuration file names.
829*4882a593Smuzhiyun#
830*4882a593Smuzhiyun# cluster-config-file nodes-6379.conf
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun# Cluster node timeout is the amount of milliseconds a node must be unreachable
833*4882a593Smuzhiyun# for it to be considered in failure state.
834*4882a593Smuzhiyun# Most other internal time limits are multiple of the node timeout.
835*4882a593Smuzhiyun#
836*4882a593Smuzhiyun# cluster-node-timeout 15000
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun# A slave of a failing master will avoid to start a failover if its data
839*4882a593Smuzhiyun# looks too old.
840*4882a593Smuzhiyun#
841*4882a593Smuzhiyun# There is no simple way for a slave to actually have an exact measure of
842*4882a593Smuzhiyun# its "data age", so the following two checks are performed:
843*4882a593Smuzhiyun#
844*4882a593Smuzhiyun# 1) If there are multiple slaves able to failover, they exchange messages
845*4882a593Smuzhiyun#    in order to try to give an advantage to the slave with the best
846*4882a593Smuzhiyun#    replication offset (more data from the master processed).
847*4882a593Smuzhiyun#    Slaves will try to get their rank by offset, and apply to the start
848*4882a593Smuzhiyun#    of the failover a delay proportional to their rank.
849*4882a593Smuzhiyun#
850*4882a593Smuzhiyun# 2) Every single slave computes the time of the last interaction with
851*4882a593Smuzhiyun#    its master. This can be the last ping or command received (if the master
852*4882a593Smuzhiyun#    is still in the "connected" state), or the time that elapsed since the
853*4882a593Smuzhiyun#    disconnection with the master (if the replication link is currently down).
854*4882a593Smuzhiyun#    If the last interaction is too old, the slave will not try to failover
855*4882a593Smuzhiyun#    at all.
856*4882a593Smuzhiyun#
857*4882a593Smuzhiyun# The point "2" can be tuned by user. Specifically a slave will not perform
858*4882a593Smuzhiyun# the failover if, since the last interaction with the master, the time
859*4882a593Smuzhiyun# elapsed is greater than:
860*4882a593Smuzhiyun#
861*4882a593Smuzhiyun#   (node-timeout * slave-validity-factor) + repl-ping-slave-period
862*4882a593Smuzhiyun#
863*4882a593Smuzhiyun# So for example if node-timeout is 30 seconds, and the slave-validity-factor
864*4882a593Smuzhiyun# is 10, and assuming a default repl-ping-slave-period of 10 seconds, the
865*4882a593Smuzhiyun# slave will not try to failover if it was not able to talk with the master
866*4882a593Smuzhiyun# for longer than 310 seconds.
867*4882a593Smuzhiyun#
868*4882a593Smuzhiyun# A large slave-validity-factor may allow slaves with too old data to failover
869*4882a593Smuzhiyun# a master, while a too small value may prevent the cluster from being able to
870*4882a593Smuzhiyun# elect a slave at all.
871*4882a593Smuzhiyun#
872*4882a593Smuzhiyun# For maximum availability, it is possible to set the slave-validity-factor
873*4882a593Smuzhiyun# to a value of 0, which means, that slaves will always try to failover the
874*4882a593Smuzhiyun# master regardless of the last time they interacted with the master.
875*4882a593Smuzhiyun# (However they'll always try to apply a delay proportional to their
876*4882a593Smuzhiyun# offset rank).
877*4882a593Smuzhiyun#
878*4882a593Smuzhiyun# Zero is the only value able to guarantee that when all the partitions heal
879*4882a593Smuzhiyun# the cluster will always be able to continue.
880*4882a593Smuzhiyun#
881*4882a593Smuzhiyun# cluster-slave-validity-factor 10
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun# Cluster slaves are able to migrate to orphaned masters, that are masters
884*4882a593Smuzhiyun# that are left without working slaves. This improves the cluster ability
885*4882a593Smuzhiyun# to resist to failures as otherwise an orphaned master can't be failed over
886*4882a593Smuzhiyun# in case of failure if it has no working slaves.
887*4882a593Smuzhiyun#
888*4882a593Smuzhiyun# Slaves migrate to orphaned masters only if there are still at least a
889*4882a593Smuzhiyun# given number of other working slaves for their old master. This number
890*4882a593Smuzhiyun# is the "migration barrier". A migration barrier of 1 means that a slave
891*4882a593Smuzhiyun# will migrate only if there is at least 1 other working slave for its master
892*4882a593Smuzhiyun# and so forth. It usually reflects the number of slaves you want for every
893*4882a593Smuzhiyun# master in your cluster.
894*4882a593Smuzhiyun#
895*4882a593Smuzhiyun# Default is 1 (slaves migrate only if their masters remain with at least
896*4882a593Smuzhiyun# one slave). To disable migration just set it to a very large value.
897*4882a593Smuzhiyun# A value of 0 can be set but is useful only for debugging and dangerous
898*4882a593Smuzhiyun# in production.
899*4882a593Smuzhiyun#
900*4882a593Smuzhiyun# cluster-migration-barrier 1
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun# By default Redis Cluster nodes stop accepting queries if they detect there
903*4882a593Smuzhiyun# is at least an hash slot uncovered (no available node is serving it).
904*4882a593Smuzhiyun# This way if the cluster is partially down (for example a range of hash slots
905*4882a593Smuzhiyun# are no longer covered) all the cluster becomes, eventually, unavailable.
906*4882a593Smuzhiyun# It automatically returns available as soon as all the slots are covered again.
907*4882a593Smuzhiyun#
908*4882a593Smuzhiyun# However sometimes you want the subset of the cluster which is working,
909*4882a593Smuzhiyun# to continue to accept queries for the part of the key space that is still
910*4882a593Smuzhiyun# covered. In order to do so, just set the cluster-require-full-coverage
911*4882a593Smuzhiyun# option to no.
912*4882a593Smuzhiyun#
913*4882a593Smuzhiyun# cluster-require-full-coverage yes
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun# In order to setup your cluster make sure to read the documentation
916*4882a593Smuzhiyun# available at http://redis.io web site.
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun########################## CLUSTER DOCKER/NAT support  ########################
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun# In certain deployments, Redis Cluster nodes address discovery fails, because
921*4882a593Smuzhiyun# addresses are NAT-ted or because ports are forwarded (the typical case is
922*4882a593Smuzhiyun# Docker and other containers).
923*4882a593Smuzhiyun#
924*4882a593Smuzhiyun# In order to make Redis Cluster working in such environments, a static
925*4882a593Smuzhiyun# configuration where each node knows its public address is needed. The
926*4882a593Smuzhiyun# following two options are used for this scope, and are:
927*4882a593Smuzhiyun#
928*4882a593Smuzhiyun# * cluster-announce-ip
929*4882a593Smuzhiyun# * cluster-announce-port
930*4882a593Smuzhiyun# * cluster-announce-bus-port
931*4882a593Smuzhiyun#
932*4882a593Smuzhiyun# Each instruct the node about its address, client port, and cluster message
933*4882a593Smuzhiyun# bus port. The information is then published in the header of the bus packets
934*4882a593Smuzhiyun# so that other nodes will be able to correctly map the address of the node
935*4882a593Smuzhiyun# publishing the information.
936*4882a593Smuzhiyun#
937*4882a593Smuzhiyun# If the above options are not used, the normal Redis Cluster auto-detection
938*4882a593Smuzhiyun# will be used instead.
939*4882a593Smuzhiyun#
940*4882a593Smuzhiyun# Note that when remapped, the bus port may not be at the fixed offset of
941*4882a593Smuzhiyun# clients port + 10000, so you can specify any port and bus-port depending
942*4882a593Smuzhiyun# on how they get remapped. If the bus-port is not set, a fixed offset of
943*4882a593Smuzhiyun# 10000 will be used as usually.
944*4882a593Smuzhiyun#
945*4882a593Smuzhiyun# Example:
946*4882a593Smuzhiyun#
947*4882a593Smuzhiyun# cluster-announce-ip 10.1.1.5
948*4882a593Smuzhiyun# cluster-announce-port 6379
949*4882a593Smuzhiyun# cluster-announce-bus-port 6380
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun################################## SLOW LOG ###################################
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun# The Redis Slow Log is a system to log queries that exceeded a specified
954*4882a593Smuzhiyun# execution time. The execution time does not include the I/O operations
955*4882a593Smuzhiyun# like talking with the client, sending the reply and so forth,
956*4882a593Smuzhiyun# but just the time needed to actually execute the command (this is the only
957*4882a593Smuzhiyun# stage of command execution where the thread is blocked and can not serve
958*4882a593Smuzhiyun# other requests in the meantime).
959*4882a593Smuzhiyun#
960*4882a593Smuzhiyun# You can configure the slow log with two parameters: one tells Redis
961*4882a593Smuzhiyun# what is the execution time, in microseconds, to exceed in order for the
962*4882a593Smuzhiyun# command to get logged, and the other parameter is the length of the
963*4882a593Smuzhiyun# slow log. When a new command is logged the oldest one is removed from the
964*4882a593Smuzhiyun# queue of logged commands.
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun# The following time is expressed in microseconds, so 1000000 is equivalent
967*4882a593Smuzhiyun# to one second. Note that a negative number disables the slow log, while
968*4882a593Smuzhiyun# a value of zero forces the logging of every command.
969*4882a593Smuzhiyunslowlog-log-slower-than 10000
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun# There is no limit to this length. Just be aware that it will consume memory.
972*4882a593Smuzhiyun# You can reclaim memory used by the slow log with SLOWLOG RESET.
973*4882a593Smuzhiyunslowlog-max-len 128
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun################################ LATENCY MONITOR ##############################
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun# The Redis latency monitoring subsystem samples different operations
978*4882a593Smuzhiyun# at runtime in order to collect data related to possible sources of
979*4882a593Smuzhiyun# latency of a Redis instance.
980*4882a593Smuzhiyun#
981*4882a593Smuzhiyun# Via the LATENCY command this information is available to the user that can
982*4882a593Smuzhiyun# print graphs and obtain reports.
983*4882a593Smuzhiyun#
984*4882a593Smuzhiyun# The system only logs operations that were performed in a time equal or
985*4882a593Smuzhiyun# greater than the amount of milliseconds specified via the
986*4882a593Smuzhiyun# latency-monitor-threshold configuration directive. When its value is set
987*4882a593Smuzhiyun# to zero, the latency monitor is turned off.
988*4882a593Smuzhiyun#
989*4882a593Smuzhiyun# By default latency monitoring is disabled since it is mostly not needed
990*4882a593Smuzhiyun# if you don't have latency issues, and collecting data has a performance
991*4882a593Smuzhiyun# impact, that while very small, can be measured under big load. Latency
992*4882a593Smuzhiyun# monitoring can easily be enabled at runtime using the command
993*4882a593Smuzhiyun# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
994*4882a593Smuzhiyunlatency-monitor-threshold 0
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun############################# EVENT NOTIFICATION ##############################
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun# Redis can notify Pub/Sub clients about events happening in the key space.
999*4882a593Smuzhiyun# This feature is documented at http://redis.io/topics/notifications
1000*4882a593Smuzhiyun#
1001*4882a593Smuzhiyun# For instance if keyspace events notification is enabled, and a client
1002*4882a593Smuzhiyun# performs a DEL operation on key "foo" stored in the Database 0, two
1003*4882a593Smuzhiyun# messages will be published via Pub/Sub:
1004*4882a593Smuzhiyun#
1005*4882a593Smuzhiyun# PUBLISH __keyspace@0__:foo del
1006*4882a593Smuzhiyun# PUBLISH __keyevent@0__:del foo
1007*4882a593Smuzhiyun#
1008*4882a593Smuzhiyun# It is possible to select the events that Redis will notify among a set
1009*4882a593Smuzhiyun# of classes. Every class is identified by a single character:
1010*4882a593Smuzhiyun#
1011*4882a593Smuzhiyun#  K     Keyspace events, published with __keyspace@<db>__ prefix.
1012*4882a593Smuzhiyun#  E     Keyevent events, published with __keyevent@<db>__ prefix.
1013*4882a593Smuzhiyun#  g     Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
1014*4882a593Smuzhiyun#  $     String commands
1015*4882a593Smuzhiyun#  l     List commands
1016*4882a593Smuzhiyun#  s     Set commands
1017*4882a593Smuzhiyun#  h     Hash commands
1018*4882a593Smuzhiyun#  z     Sorted set commands
1019*4882a593Smuzhiyun#  x     Expired events (events generated every time a key expires)
1020*4882a593Smuzhiyun#  e     Evicted events (events generated when a key is evicted for maxmemory)
1021*4882a593Smuzhiyun#  A     Alias for g$lshzxe, so that the "AKE" string means all the events.
1022*4882a593Smuzhiyun#
1023*4882a593Smuzhiyun#  The "notify-keyspace-events" takes as argument a string that is composed
1024*4882a593Smuzhiyun#  of zero or multiple characters. The empty string means that notifications
1025*4882a593Smuzhiyun#  are disabled.
1026*4882a593Smuzhiyun#
1027*4882a593Smuzhiyun#  Example: to enable list and generic events, from the point of view of the
1028*4882a593Smuzhiyun#           event name, use:
1029*4882a593Smuzhiyun#
1030*4882a593Smuzhiyun#  notify-keyspace-events Elg
1031*4882a593Smuzhiyun#
1032*4882a593Smuzhiyun#  Example 2: to get the stream of the expired keys subscribing to channel
1033*4882a593Smuzhiyun#             name __keyevent@0__:expired use:
1034*4882a593Smuzhiyun#
1035*4882a593Smuzhiyun#  notify-keyspace-events Ex
1036*4882a593Smuzhiyun#
1037*4882a593Smuzhiyun#  By default all notifications are disabled because most users don't need
1038*4882a593Smuzhiyun#  this feature and the feature has some overhead. Note that if you don't
1039*4882a593Smuzhiyun#  specify at least one of K or E, no events will be delivered.
1040*4882a593Smuzhiyunnotify-keyspace-events ""
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun############################### ADVANCED CONFIG ###############################
1043*4882a593Smuzhiyun
1044*4882a593Smuzhiyun# Hashes are encoded using a memory efficient data structure when they have a
1045*4882a593Smuzhiyun# small number of entries, and the biggest entry does not exceed a given
1046*4882a593Smuzhiyun# threshold. These thresholds can be configured using the following directives.
1047*4882a593Smuzhiyunhash-max-ziplist-entries 512
1048*4882a593Smuzhiyunhash-max-ziplist-value 64
1049*4882a593Smuzhiyun
1050*4882a593Smuzhiyun# Lists are also encoded in a special way to save a lot of space.
1051*4882a593Smuzhiyun# The number of entries allowed per internal list node can be specified
1052*4882a593Smuzhiyun# as a fixed maximum size or a maximum number of elements.
1053*4882a593Smuzhiyun# For a fixed maximum size, use -5 through -1, meaning:
1054*4882a593Smuzhiyun# -5: max size: 64 Kb  <-- not recommended for normal workloads
1055*4882a593Smuzhiyun# -4: max size: 32 Kb  <-- not recommended
1056*4882a593Smuzhiyun# -3: max size: 16 Kb  <-- probably not recommended
1057*4882a593Smuzhiyun# -2: max size: 8 Kb   <-- good
1058*4882a593Smuzhiyun# -1: max size: 4 Kb   <-- good
1059*4882a593Smuzhiyun# Positive numbers mean store up to _exactly_ that number of elements
1060*4882a593Smuzhiyun# per list node.
1061*4882a593Smuzhiyun# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
1062*4882a593Smuzhiyun# but if your use case is unique, adjust the settings as necessary.
1063*4882a593Smuzhiyunlist-max-ziplist-size -2
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun# Lists may also be compressed.
1066*4882a593Smuzhiyun# Compress depth is the number of quicklist ziplist nodes from *each* side of
1067*4882a593Smuzhiyun# the list to *exclude* from compression.  The head and tail of the list
1068*4882a593Smuzhiyun# are always uncompressed for fast push/pop operations.  Settings are:
1069*4882a593Smuzhiyun# 0: disable all list compression
1070*4882a593Smuzhiyun# 1: depth 1 means "don't start compressing until after 1 node into the list,
1071*4882a593Smuzhiyun#    going from either the head or tail"
1072*4882a593Smuzhiyun#    So: [head]->node->node->...->node->[tail]
1073*4882a593Smuzhiyun#    [head], [tail] will always be uncompressed; inner nodes will compress.
1074*4882a593Smuzhiyun# 2: [head]->[next]->node->node->...->node->[prev]->[tail]
1075*4882a593Smuzhiyun#    2 here means: don't compress head or head->next or tail->prev or tail,
1076*4882a593Smuzhiyun#    but compress all nodes between them.
1077*4882a593Smuzhiyun# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
1078*4882a593Smuzhiyun# etc.
1079*4882a593Smuzhiyunlist-compress-depth 0
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun# Sets have a special encoding in just one case: when a set is composed
1082*4882a593Smuzhiyun# of just strings that happen to be integers in radix 10 in the range
1083*4882a593Smuzhiyun# of 64 bit signed integers.
1084*4882a593Smuzhiyun# The following configuration setting sets the limit in the size of the
1085*4882a593Smuzhiyun# set in order to use this special memory saving encoding.
1086*4882a593Smuzhiyunset-max-intset-entries 512
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun# Similarly to hashes and lists, sorted sets are also specially encoded in
1089*4882a593Smuzhiyun# order to save a lot of space. This encoding is only used when the length and
1090*4882a593Smuzhiyun# elements of a sorted set are below the following limits:
1091*4882a593Smuzhiyunzset-max-ziplist-entries 128
1092*4882a593Smuzhiyunzset-max-ziplist-value 64
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun# HyperLogLog sparse representation bytes limit. The limit includes the
1095*4882a593Smuzhiyun# 16 bytes header. When an HyperLogLog using the sparse representation crosses
1096*4882a593Smuzhiyun# this limit, it is converted into the dense representation.
1097*4882a593Smuzhiyun#
1098*4882a593Smuzhiyun# A value greater than 16000 is totally useless, since at that point the
1099*4882a593Smuzhiyun# dense representation is more memory efficient.
1100*4882a593Smuzhiyun#
1101*4882a593Smuzhiyun# The suggested value is ~ 3000 in order to have the benefits of
1102*4882a593Smuzhiyun# the space efficient encoding without slowing down too much PFADD,
1103*4882a593Smuzhiyun# which is O(N) with the sparse encoding. The value can be raised to
1104*4882a593Smuzhiyun# ~ 10000 when CPU is not a concern, but space is, and the data set is
1105*4882a593Smuzhiyun# composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
1106*4882a593Smuzhiyunhll-sparse-max-bytes 3000
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
1109*4882a593Smuzhiyun# order to help rehashing the main Redis hash table (the one mapping top-level
1110*4882a593Smuzhiyun# keys to values). The hash table implementation Redis uses (see dict.c)
1111*4882a593Smuzhiyun# performs a lazy rehashing: the more operation you run into a hash table
1112*4882a593Smuzhiyun# that is rehashing, the more rehashing "steps" are performed, so if the
1113*4882a593Smuzhiyun# server is idle the rehashing is never complete and some more memory is used
1114*4882a593Smuzhiyun# by the hash table.
1115*4882a593Smuzhiyun#
1116*4882a593Smuzhiyun# The default is to use this millisecond 10 times every second in order to
1117*4882a593Smuzhiyun# actively rehash the main dictionaries, freeing memory when possible.
1118*4882a593Smuzhiyun#
1119*4882a593Smuzhiyun# If unsure:
1120*4882a593Smuzhiyun# use "activerehashing no" if you have hard latency requirements and it is
1121*4882a593Smuzhiyun# not a good thing in your environment that Redis can reply from time to time
1122*4882a593Smuzhiyun# to queries with 2 milliseconds delay.
1123*4882a593Smuzhiyun#
1124*4882a593Smuzhiyun# use "activerehashing yes" if you don't have such hard requirements but
1125*4882a593Smuzhiyun# want to free memory asap when possible.
1126*4882a593Smuzhiyunactiverehashing yes
1127*4882a593Smuzhiyun
1128*4882a593Smuzhiyun# The client output buffer limits can be used to force disconnection of clients
1129*4882a593Smuzhiyun# that are not reading data from the server fast enough for some reason (a
1130*4882a593Smuzhiyun# common reason is that a Pub/Sub client can't consume messages as fast as the
1131*4882a593Smuzhiyun# publisher can produce them).
1132*4882a593Smuzhiyun#
1133*4882a593Smuzhiyun# The limit can be set differently for the three different classes of clients:
1134*4882a593Smuzhiyun#
1135*4882a593Smuzhiyun# normal -> normal clients including MONITOR clients
1136*4882a593Smuzhiyun# slave  -> slave clients
1137*4882a593Smuzhiyun# pubsub -> clients subscribed to at least one pubsub channel or pattern
1138*4882a593Smuzhiyun#
1139*4882a593Smuzhiyun# The syntax of every client-output-buffer-limit directive is the following:
1140*4882a593Smuzhiyun#
1141*4882a593Smuzhiyun# client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
1142*4882a593Smuzhiyun#
1143*4882a593Smuzhiyun# A client is immediately disconnected once the hard limit is reached, or if
1144*4882a593Smuzhiyun# the soft limit is reached and remains reached for the specified number of
1145*4882a593Smuzhiyun# seconds (continuously).
1146*4882a593Smuzhiyun# So for instance if the hard limit is 32 megabytes and the soft limit is
1147*4882a593Smuzhiyun# 16 megabytes / 10 seconds, the client will get disconnected immediately
1148*4882a593Smuzhiyun# if the size of the output buffers reach 32 megabytes, but will also get
1149*4882a593Smuzhiyun# disconnected if the client reaches 16 megabytes and continuously overcomes
1150*4882a593Smuzhiyun# the limit for 10 seconds.
1151*4882a593Smuzhiyun#
1152*4882a593Smuzhiyun# By default normal clients are not limited because they don't receive data
1153*4882a593Smuzhiyun# without asking (in a push way), but just after a request, so only
1154*4882a593Smuzhiyun# asynchronous clients may create a scenario where data is requested faster
1155*4882a593Smuzhiyun# than it can read.
1156*4882a593Smuzhiyun#
1157*4882a593Smuzhiyun# Instead there is a default limit for pubsub and slave clients, since
1158*4882a593Smuzhiyun# subscribers and slaves receive data in a push fashion.
1159*4882a593Smuzhiyun#
1160*4882a593Smuzhiyun# Both the hard or the soft limit can be disabled by setting them to zero.
1161*4882a593Smuzhiyunclient-output-buffer-limit normal 0 0 0
1162*4882a593Smuzhiyunclient-output-buffer-limit slave 256mb 64mb 60
1163*4882a593Smuzhiyunclient-output-buffer-limit pubsub 32mb 8mb 60
1164*4882a593Smuzhiyun
1165*4882a593Smuzhiyun# Client query buffers accumulate new commands. They are limited to a fixed
1166*4882a593Smuzhiyun# amount by default in order to avoid that a protocol desynchronization (for
1167*4882a593Smuzhiyun# instance due to a bug in the client) will lead to unbound memory usage in
1168*4882a593Smuzhiyun# the query buffer. However you can configure it here if you have very special
1169*4882a593Smuzhiyun# needs, such us huge multi/exec requests or alike.
1170*4882a593Smuzhiyun#
1171*4882a593Smuzhiyun# client-query-buffer-limit 1gb
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun# In the Redis protocol, bulk requests, that are, elements representing single
1174*4882a593Smuzhiyun# strings, are normally limited ot 512 mb. However you can change this limit
1175*4882a593Smuzhiyun# here.
1176*4882a593Smuzhiyun#
1177*4882a593Smuzhiyun# proto-max-bulk-len 512mb
1178*4882a593Smuzhiyun
1179*4882a593Smuzhiyun# Redis calls an internal function to perform many background tasks, like
1180*4882a593Smuzhiyun# closing connections of clients in timeout, purging expired keys that are
1181*4882a593Smuzhiyun# never requested, and so forth.
1182*4882a593Smuzhiyun#
1183*4882a593Smuzhiyun# Not all tasks are performed with the same frequency, but Redis checks for
1184*4882a593Smuzhiyun# tasks to perform according to the specified "hz" value.
1185*4882a593Smuzhiyun#
1186*4882a593Smuzhiyun# By default "hz" is set to 10. Raising the value will use more CPU when
1187*4882a593Smuzhiyun# Redis is idle, but at the same time will make Redis more responsive when
1188*4882a593Smuzhiyun# there are many keys expiring at the same time, and timeouts may be
1189*4882a593Smuzhiyun# handled with more precision.
1190*4882a593Smuzhiyun#
1191*4882a593Smuzhiyun# The range is between 1 and 500, however a value over 100 is usually not
1192*4882a593Smuzhiyun# a good idea. Most users should use the default of 10 and raise this up to
1193*4882a593Smuzhiyun# 100 only in environments where very low latency is required.
1194*4882a593Smuzhiyunhz 10
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun# When a child rewrites the AOF file, if the following option is enabled
1197*4882a593Smuzhiyun# the file will be fsync-ed every 32 MB of data generated. This is useful
1198*4882a593Smuzhiyun# in order to commit the file to the disk more incrementally and avoid
1199*4882a593Smuzhiyun# big latency spikes.
1200*4882a593Smuzhiyunaof-rewrite-incremental-fsync yes
1201*4882a593Smuzhiyun
1202*4882a593Smuzhiyun# Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good
1203*4882a593Smuzhiyun# idea to start with the default settings and only change them after investigating
1204*4882a593Smuzhiyun# how to improve the performances and how the keys LFU change over time, which
1205*4882a593Smuzhiyun# is possible to inspect via the OBJECT FREQ command.
1206*4882a593Smuzhiyun#
1207*4882a593Smuzhiyun# There are two tunable parameters in the Redis LFU implementation: the
1208*4882a593Smuzhiyun# counter logarithm factor and the counter decay time. It is important to
1209*4882a593Smuzhiyun# understand what the two parameters mean before changing them.
1210*4882a593Smuzhiyun#
1211*4882a593Smuzhiyun# The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis
1212*4882a593Smuzhiyun# uses a probabilistic increment with logarithmic behavior. Given the value
1213*4882a593Smuzhiyun# of the old counter, when a key is accessed, the counter is incremented in
1214*4882a593Smuzhiyun# this way:
1215*4882a593Smuzhiyun#
1216*4882a593Smuzhiyun# 1. A random number R between 0 and 1 is extracted.
1217*4882a593Smuzhiyun# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).
1218*4882a593Smuzhiyun# 3. The counter is incremented only if R < P.
1219*4882a593Smuzhiyun#
1220*4882a593Smuzhiyun# The default lfu-log-factor is 10. This is a table of how the frequency
1221*4882a593Smuzhiyun# counter changes with a different number of accesses with different
1222*4882a593Smuzhiyun# logarithmic factors:
1223*4882a593Smuzhiyun#
1224*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1225*4882a593Smuzhiyun# | factor | 100 hits   | 1000 hits  | 100K hits  | 1M hits    | 10M hits   |
1226*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1227*4882a593Smuzhiyun# | 0      | 104        | 255        | 255        | 255        | 255        |
1228*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1229*4882a593Smuzhiyun# | 1      | 18         | 49         | 255        | 255        | 255        |
1230*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1231*4882a593Smuzhiyun# | 10     | 10         | 18         | 142        | 255        | 255        |
1232*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1233*4882a593Smuzhiyun# | 100    | 8          | 11         | 49         | 143        | 255        |
1234*4882a593Smuzhiyun# +--------+------------+------------+------------+------------+------------+
1235*4882a593Smuzhiyun#
1236*4882a593Smuzhiyun# NOTE: The above table was obtained by running the following commands:
1237*4882a593Smuzhiyun#
1238*4882a593Smuzhiyun#   redis-benchmark -n 1000000 incr foo
1239*4882a593Smuzhiyun#   redis-cli object freq foo
1240*4882a593Smuzhiyun#
1241*4882a593Smuzhiyun# NOTE 2: The counter initial value is 5 in order to give new objects a chance
1242*4882a593Smuzhiyun# to accumulate hits.
1243*4882a593Smuzhiyun#
1244*4882a593Smuzhiyun# The counter decay time is the time, in minutes, that must elapse in order
1245*4882a593Smuzhiyun# for the key counter to be divided by two (or decremented if it has a value
1246*4882a593Smuzhiyun# less <= 10).
1247*4882a593Smuzhiyun#
1248*4882a593Smuzhiyun# The default value for the lfu-decay-time is 1. A Special value of 0 means to
1249*4882a593Smuzhiyun# decay the counter every time it happens to be scanned.
1250*4882a593Smuzhiyun#
1251*4882a593Smuzhiyun# lfu-log-factor 10
1252*4882a593Smuzhiyun# lfu-decay-time 1
1253*4882a593Smuzhiyun
1254*4882a593Smuzhiyun########################### ACTIVE DEFRAGMENTATION #######################
1255*4882a593Smuzhiyun#
1256*4882a593Smuzhiyun# WARNING THIS FEATURE IS EXPERIMENTAL. However it was stress tested
1257*4882a593Smuzhiyun# even in production and manually tested by multiple engineers for some
1258*4882a593Smuzhiyun# time.
1259*4882a593Smuzhiyun#
1260*4882a593Smuzhiyun# What is active defragmentation?
1261*4882a593Smuzhiyun# -------------------------------
1262*4882a593Smuzhiyun#
1263*4882a593Smuzhiyun# Active (online) defragmentation allows a Redis server to compact the
1264*4882a593Smuzhiyun# spaces left between small allocations and deallocations of data in memory,
1265*4882a593Smuzhiyun# thus allowing to reclaim back memory.
1266*4882a593Smuzhiyun#
1267*4882a593Smuzhiyun# Fragmentation is a natural process that happens with every allocator (but
1268*4882a593Smuzhiyun# less so with Jemalloc, fortunately) and certain workloads. Normally a server
1269*4882a593Smuzhiyun# restart is needed in order to lower the fragmentation, or at least to flush
1270*4882a593Smuzhiyun# away all the data and create it again. However thanks to this feature
1271*4882a593Smuzhiyun# implemented by Oran Agra for Redis 4.0 this process can happen at runtime
1272*4882a593Smuzhiyun# in an "hot" way, while the server is running.
1273*4882a593Smuzhiyun#
1274*4882a593Smuzhiyun# Basically when the fragmentation is over a certain level (see the
1275*4882a593Smuzhiyun# configuration options below) Redis will start to create new copies of the
1276*4882a593Smuzhiyun# values in contiguous memory regions by exploiting certain specific Jemalloc
1277*4882a593Smuzhiyun# features (in order to understand if an allocation is causing fragmentation
1278*4882a593Smuzhiyun# and to allocate it in a better place), and at the same time, will release the
1279*4882a593Smuzhiyun# old copies of the data. This process, repeated incrementally for all the keys
1280*4882a593Smuzhiyun# will cause the fragmentation to drop back to normal values.
1281*4882a593Smuzhiyun#
1282*4882a593Smuzhiyun# Important things to understand:
1283*4882a593Smuzhiyun#
1284*4882a593Smuzhiyun# 1. This feature is disabled by default, and only works if you compiled Redis
1285*4882a593Smuzhiyun#    to use the copy of Jemalloc we ship with the source code of Redis.
1286*4882a593Smuzhiyun#    This is the default with Linux builds.
1287*4882a593Smuzhiyun#
1288*4882a593Smuzhiyun# 2. You never need to enable this feature if you don't have fragmentation
1289*4882a593Smuzhiyun#    issues.
1290*4882a593Smuzhiyun#
1291*4882a593Smuzhiyun# 3. Once you experience fragmentation, you can enable this feature when
1292*4882a593Smuzhiyun#    needed with the command "CONFIG SET activedefrag yes".
1293*4882a593Smuzhiyun#
1294*4882a593Smuzhiyun# The configuration parameters are able to fine tune the behavior of the
1295*4882a593Smuzhiyun# defragmentation process. If you are not sure about what they mean it is
1296*4882a593Smuzhiyun# a good idea to leave the defaults untouched.
1297*4882a593Smuzhiyun
1298*4882a593Smuzhiyun# Enabled active defragmentation
1299*4882a593Smuzhiyun# activedefrag yes
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun# Minimum amount of fragmentation waste to start active defrag
1302*4882a593Smuzhiyun# active-defrag-ignore-bytes 100mb
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun# Minimum percentage of fragmentation to start active defrag
1305*4882a593Smuzhiyun# active-defrag-threshold-lower 10
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun# Maximum percentage of fragmentation at which we use maximum effort
1308*4882a593Smuzhiyun# active-defrag-threshold-upper 100
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun# Minimal effort for defrag in CPU percentage
1311*4882a593Smuzhiyun# active-defrag-cycle-min 25
1312*4882a593Smuzhiyun
1313*4882a593Smuzhiyun# Maximal effort for defrag in CPU percentage
1314*4882a593Smuzhiyun# active-defrag-cycle-max 75
1315