1 # Note on units: when memory size is needed, it is possible to specifiy
2 # it in the usual form of 1k 5GB 4M and so forth:
3 #
4 # 1k => 1000 bytes
5 # 1kb => 1024 bytes
6 # 1m => 1000000 bytes
7 # 1mb => 1024*1024 bytes
8 # 1g => 1000000000 bytes
9 # 1gb => 1024*1024*1024 bytes
10 #
11 # units are case insensitive so 1GB 1Gb 1gB are all the same.
12
13 # Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
14 # 启用守护进程后,Redis会把pid写到一个pidfile中,在/var/run/redis.pid
15 daemonize no
16
17 # 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定
18 pidfile /var/run/redis.pid
19
20 # 指定Redis监听端口,默认端口为6379
21 # 如果指定0端口,表示Redis不监听TCP连接
22 port 6379
23
24 # 绑定的主机地址
25 # 你可以绑定单一接口,如果没有绑定,所有接口都会监听到来的连接
26 # bind 127.0.0.1
27
28 # Specify the path for the unix socket that will be used to listen for
29 # incoming connections. There is no default, so Redis will not listen
30 # on a unix socket when not specified.
31 #
32 # unixsocket /tmp/redis.sock
33 # unixsocketperm 755
34
35 # 当客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
36 timeout 0
37
38 # 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
39 # debug (很多信息, 对开发/测试比较有用)
40 # verbose (many rarely useful info, but not a mess like the debug level)
41 # notice (moderately verbose, what you want in production probably)
42 # warning (only very important / critical messages are logged)
43 loglevel verbose
44
45 # 日志记录方式,默认为标准输出,如果配置为redis为守护进程方式运行,而这里又配置为标准输出,则日志将会发送给/dev/null
46 logfile stdout
47
48 # To enable logging to the system logger, just set 'syslog-enabled' to yes,
49 # and optionally update the other syslog parameters to suit your needs.
50 # syslog-enabled no
51
52 # Specify the syslog identity.
53 # syslog-ident redis
54
55 # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
56 # syslog-facility local0
57
58 # 设置数据库的数量,默认数据库为0,可以使用select <dbid>命令在连接上指定数据库id
59 # dbid是从0到‘databases’-1的数目
60 databases 16
61
62 ################################ SNAPSHOTTING #################################
63 # 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
64 # Save the DB on disk:
65 #
66 # save <seconds> <changes>
67 #
68 # Will save the DB if both the given number of seconds and the given
69 # number of write operations against the DB occurred.
70 #
71 # 满足以下条件将会同步数据:
72 # 900秒(15分钟)内有1个更改
73 # 300秒(5分钟)内有10个更改
74 # 60秒内有10000个更改
75 # Note: 可以把所有“save”行注释掉,这样就取消同步操作了
76
77 save 900 1
78 save 300 10
79 save 60 10000
80
81 # 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大
82 rdbcompression yes
83
84 # 指定本地数据库文件名,默认值为dump.rdb
85 dbfilename dump.rdb
86
87 # 工作目录.
88 # 指定本地数据库存放目录,文件名由上一个dbfilename配置项指定
89 #
90 # Also the Append Only File will be created inside this directory.
91 #
92 # 注意,这里只能指定一个目录,不能指定文件名
93 dir ./
94
95 ################################# REPLICATION #################################
96
97 # 主从复制。使用slaveof从 Redis服务器复制一个Redis实例。注意,该配置仅限于当前slave有效
98 # so for example it is possible to configure the slave to save the DB with a
99 # different interval, or to listen to another port, and so on.
100 # 设置当本机为slav服务时,设置master服务的ip地址及端口,在Redis启动时,它会自动从master进行数据同步
101 # slaveof <masterip> <masterport>
102
103
104 # 当master服务设置了密码保护时,slav服务连接master的密码
105 # 下文的“requirepass”配置项可以指定密码
106 # masterauth <master-password>
107
108 # When a slave lost the connection with the master, or when the replication
109 # is still in progress, the slave can act in two different ways:
110 #
111 # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
112 # still reply to client requests, possibly with out of data data, or the
113 # data set may just be empty if this is the first synchronization.
114 #
115 # 2) if slave-serve-stale data is set to 'no' the slave will reply with
116 # an error "SYNC with master in progress" to all the kind of commands
117 # but to INFO and SLAVEOF.
118 #
119 slave-serve-stale-data yes
120
121 # Slaves send PINGs to server in a predefined interval. It's possible to change
122 # this interval with the repl_ping_slave_period option. The default value is 10
123 # seconds.
124 #
125 # repl-ping-slave-period 10
126
127 # The following option sets a timeout for both Bulk transfer I/O timeout and
128 # master data or ping response timeout. The default value is 60 seconds.
129 #
130 # It is important to make sure that this value is greater than the value
131 # specified for repl-ping-slave-period otherwise a timeout will be detected
132 # every time there is low traffic between the master and the slave.
133 #
134 # repl-timeout 60
135
136 ################################## SECURITY ###################################
137
138 # Warning: since Redis is pretty fast an outside user can try up to
139 # 150k passwords per second against a good box. This means that you should
140 # use a very strong password otherwise it will be very easy to break.
141 # 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过auth <password>命令提供密码,默认关闭
142 # requirepass foobared
143
144 # Command renaming.
145 #
146 # It is possilbe to change the name of dangerous commands in a shared
147 # environment. For instance the CONFIG command may be renamed into something
148 # of hard to guess so that it will be still available for internal-use
149 # tools but not available for general clients.
150 #
151 # Example:
152 #
153 # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
154 #
155 # It is also possilbe to completely kill a command renaming it into
156 # an empty string:
157 #
158 # rename-command CONFIG ""
159
160 ################################### LIMITS ####################################
161
162 # 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,
163 # 如果设置maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max Number of clients reached错误信息
164 # maxclients 128
165
166 # Don't use more memory than the specified amount of bytes.
167 # When the memory limit is reached Redis will try to remove keys with an
168 # EXPIRE set. It will try to start freeing keys that are going to expire
169 # in little time and preserve keys with a longer time to live.
170 # Redis will also try to remove objects from free lists if possible.
171 #
172 # If all this fails, Redis will start to reply with errors to commands
173 # that will use more memory, like SET, LPUSH, and so on, and will continue
174 # to reply to most read-only commands like GET.
175 #
176 # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
177 # 'state' server or cache, not as a real DB. When Redis is used as a real
178 # database the memory usage will grow over the weeks, it will be obvious if
179 # it is going to use too much memory in the long run, and you'll have the time
180 # to upgrade. With maxmemory after the limit is reached you'll start to get
181 # errors for write operations, and this may even lead to DB inconsistency.
182 # 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,
183 # 当此方法处理后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。
184 # Redis新的vm机制,会把Key存放内存,Value会存放在swap区
185 # maxmemory <bytes>
186
187 # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
188 # is reached? You can select among five behavior:
189 #
190 # volatile-lru -> remove the key with an expire set using an LRU algorithm
191 # allkeys-lru -> remove any key accordingly to the LRU algorithm
192 # volatile-random -> remove a random key with an expire set
193 # allkeys->random -> remove a random key, any key
194 # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
195 # noeviction -> don't expire at all, just return an error on write operations
196 #
197 # Note: with all the kind of policies, Redis will return an error on write
198 # operations, when there are not suitable keys for eviction.
199 #
200 # At the date of writing this commands are: set setnx setex append
201 # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
202 # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
203 # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
204 # getset mset msetnx exec sort
205 #
206 # The default is:
207 #
208 # maxmemory-policy volatile-lru
209
210 # LRU and minimal TTL algorithms are not precise algorithms but approximated
211 # algorithms (in order to save memory), so you can select as well the sample
212 # size to check. For instance for default Redis will check three keys and
213 # pick the one that was used less recently, you can change the sample size
214 # using the following configuration directive.
215 #
216 # maxmemory-samples 3
217
218 ############################## APPEND ONLY MODE ###############################
219
220 #
221 # Note that you can have both the async dumps and the append only file if you
222 # like (you have to comment the "save" statements above to disable the dumps).
223 # Still if append only mode is enabled Redis will load the data from the
224 # log file at startup ignoring the dump.rdb file.
225 # 指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。
226 # 因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no
227 # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
228 # log file in background when it gets too big.
229
230 appendonly no
231
232 # 指定更新日志文件名,默认为appendonly.aof
233 # appendfilename appendonly.aof
234
235 # The fsync() call tells the Operating System to actually write data on disk
236 # instead to wait for more data in the output buffer. Some OS will really flush
237 # data on disk, some other OS will just try to do it ASAP.
238
239 # 指定更新日志条件,共有3个可选值:
240 # no:表示等操作系统进行数据缓存同步到磁盘(快)
241 # always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)
242 # everysec:表示每秒同步一次(折衷,默认值)
243
244 appendfsync everysec
245 # appendfsync no
246
247 # When the AOF fsync policy is set to always or everysec, and a background
248 # saving process (a background save or AOF log background rewriting) is
249 # performing a lot of I/O against the disk, in some Linux configurations
250 # Redis may block too long on the fsync() call. Note that there is no fix for
251 # this currently, as even performing fsync in a different thread will block
252 # our synchronous write(2) call.
253 #
254 # In order to mitigate this problem it's possible to use the following option
255 # that will prevent fsync() from being called in the main process while a
256 # BGSAVE or BGREWRITEAOF is in progress.
257 #
258 # This means that while another child is saving the durability of Redis is
259 # the same as "appendfsync none", that in pratical terms means that it is
260 # possible to lost up to 30 seconds of log in the worst scenario (with the
261 # default Linux settings).
262 #
263 # If you have latency problems turn this to "yes". Otherwise leave it as
264 # "no" that is the safest pick from the point of view of durability.
265 no-appendfsync-on-rewrite no
266
267 # Automatic rewrite of the append only file.
268 # Redis is able to automatically rewrite the log file implicitly calling
269 # BGREWRITEAOF when the AOF log size will growth by the specified percentage.
270 #
271 # This is how it works: Redis remembers the size of the AOF file after the
272 # latest rewrite (or if no rewrite happened since the restart, the size of
273 # the AOF at startup is used).
274 #
275 # This base size is compared to the current size. If the current size is
276 # bigger than the specified percentage, the rewrite is triggered. Also
277 # you need to specify a minimal size for the AOF file to be rewritten, this
278 # is useful to avoid rewriting the AOF file even if the percentage increase
279 # is reached but it is still pretty small.
280 #
281 # Specify a precentage of zero in order to disable the automatic AOF
282 # rewrite feature.
283
284 auto-aof-rewrite-percentage 100
285 auto-aof-rewrite-min-size 64mb
286
287 ################################## SLOW LOG ###################################
288
289 # The Redis Slow Log is a system to log queries that exceeded a specified
290 # execution time. The execution time does not include the I/O operations
291 # like talking with the client, sending the reply and so forth,
292 # but just the time needed to actually execute the command (this is the only
293 # stage of command execution where the thread is blocked and can not serve
294 # other requests in the meantime).
295 #
296 # You can configure the slow log with two parameters: one tells Redis
297 # what is the execution time, in microseconds, to exceed in order for the
298 # command to get logged, and the other parameter is the length of the
299 # slow log. When a new command is logged the oldest one is removed from the
300 # queue of logged commands.
301
302 # The following time is expressed in microseconds, so 1000000 is equivalent
303 # to one second. Note that a negative number disables the slow log, while
304 # a value of zero forces the logging of every command.
305 slowlog-log-slower-than 10000
306
307 # There is no limit to this length. Just be aware that it will consume memory.
308 # You can reclaim memory used by the slow log with SLOWLOG RESET.
309 slowlog-max-len 1024
310
311 ################################ VIRTUAL MEMORY ###############################
312
313 ### WARNING! Virtual Memory is deprecated in Redis 2.4
314 ### The use of Virtual Memory is strongly discouraged.
315
316 ### WARNING! Virtual Memory is deprecated in Redis 2.4
317 ### The use of Virtual Memory is strongly discouraged.
318
319 # Virtual Memory allows Redis to work with datasets bigger than the actual
320 # amount of RAM needed to hold the whole dataset in memory.
321 # In order to do so very used keys are taken in memory while the other keys
322 # are swapped into a swap file, similarly to what operating systems do
323 # with memory pages.
324 # 指定是否启用虚拟内存机制,默认值为no,
325 # VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中
326 # 把vm-enabled设置为yes,根据需要设置好接下来的三个VM参数,就可以启动VM了
327 vm-enabled no
328 # vm-enabled yes
329
330 # This is the path of the Redis swap file. As you can guess, swap files
331 # can't be shared by different Redis instances, so make sure to use a swap
332 # file for every redis process you are running. Redis will complain if the
333 # swap file is already in use.
334 #
335 # Redis交换文件最好的存储是SSD(固态硬盘)
336 # 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
337 # *** WARNING *** if you are using a shared hosting the default of putting
338 # the swap file under /tmp is not secure. Create a dir with access granted
339 # only to Redis user and configure Redis to create the swap file there.
340 vm-swap-file /tmp/redis.swap
341
342 # With vm-max-memory 0 the system will swap everything it can. Not a good
343 # default, just specify the max amount of RAM you can in bytes, but it's
344 # better to leave some margin. For instance specify an amount of RAM
345 # that's more or less between 60 and 80% of your free RAM.
346 # 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多少,所有索引数据都是内存存储的(Redis的索引数据就是keys)
347 # 也就是说当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0
348 vm-max-memory 0
349
350 # Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的数据大小来设定的。
351 # 建议如果存储很多小对象,page大小最后设置为32或64bytes;如果存储很大的对象,则可以使用更大的page,如果不确定,就使用默认值
352 vm-page-size 32
353
354 # 设置swap文件中的page数量由于页表(一种表示页面空闲或使用的bitmap)是存放在内存中的,在磁盘上每8个pages将消耗1byte的内存
355 # swap空间总容量为 vm-page-size * vm-pages
356 #
357 # With the default of 32-bytes memory pages and 134217728 pages Redis will
358 # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
359 #
360 # It's better to use the smallest acceptable value for your application,
361 # but the default is large in order to work in most conditions.
362 vm-pages 134217728
363
364 # Max number of VM I/O threads running at the same time.
365 # This threads are used to read/write data from/to swap file, since they
366 # also encode and decode objects from disk to memory or the reverse, a bigger
367 # number of threads can help with big objects even if they can't help with
368 # I/O itself as the physical device may not be able to couple with many
369 # reads/writes operations at the same time.
370 # 设置访问swap文件的I/O线程数,最后不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟,默认值为4
371 vm-max-threads 4
372
373 ############################### ADVANCED CONFIG ###############################
374
375 # Hashes are encoded in a special way (much more memory efficient) when they
376 # have at max a given numer of elements, and the biggest element does not
377 # exceed a given threshold. You can configure this limits with the following
378 # configuration directives.
379 # 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法
380 hash-max-zipmap-entries 512
381 hash-max-zipmap-value 64
382
383 # Similarly to hashes, small lists are also encoded in a special way in order
384 # to save a lot of space. The special representation is only used when
385 # you are under the following limits:
386 list-max-ziplist-entries 512
387 list-max-ziplist-value 64
388
389 # Sets have a special encoding in just one case: when a set is composed
390 # of just strings that happens to be integers in radix 10 in the range
391 # of 64 bit signed integers.
392 # The following configuration setting sets the limit in the size of the
393 # set in order to use this special memory saving encoding.
394 set-max-intset-entries 512
395
396 # Similarly to hashes and lists, sorted sets are also specially encoded in
397 # order to save a lot of space. This encoding is only used when the length and
398 # elements of a sorted set are below the following limits:
399 zset-max-ziplist-entries 128
400 zset-max-ziplist-value 64
401
402 # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
403 # order to help rehashing the main Redis hash table (the one mapping top-level
404 # keys to values). The hash table implementation redis uses (see dict.c)
405 # performs a lazy rehashing: the more operation you run into an hash table
406 # that is rhashing, the more rehashing "steps" are performed, so if the
407 # server is idle the rehashing is never complete and some more memory is used
408 # by the hash table.
409 #
410 # The default is to use this millisecond 10 times every second in order to
411 # active rehashing the main dictionaries, freeing memory when possible.
412 #
413 # If unsure:
414 # use "activerehashing no" if you have hard latency requirements and it is
415 # not a good thing in your environment that Redis can reply form time to time
416 # to queries with 2 milliseconds delay.
417 # 指定是否激活重置哈希,默认为开启
418 activerehashing yes
419
420 ################################## INCLUDES ###################################
421
422 # 指定包含其他的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各实例又拥有自己的特定配置文件
423 # include /path/to/local.conf
424 # include /path/to/other.conf