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