redis.conf(v3.2.8)(已迁移)

来源:互联网 发布:mac软件怎么关闭 编辑:程序博客网 时间:2024/06/06 21:06

本文已迁移到: http://liucw.cn/2017/11/10/redis/redis-conf-v3-2-8/
以后不再维护本文


1.redis server启动

  建议把redis.conf放到一个新建的etc目录里,这样便于管理。redis数据库也一样,放到一个新建的db目录里管理。
  如果需要指定配置文件路径,需要在第1个参数指定配置文件路径

# Redis configuration file example.  Redis配置文件例子.## Note that in order to read the configuration file, Redis must be# started with the file path as first argument:  注意:为了能读取到配置文件,Redis服务必须以配置文件的路径作为第一个参数启动## ./redis-server /path/to/redis.conf

2.units内存大小单位

  1.配置大小单位,开头定义了一些基本的度量单位,只支持byte,不支持bit。(byte字节, 存储空间的基本计量单位,bit位, 一个二进制数据0或1。 一般1 byte = 8 bit)
  2.对大小写不敏感

# Note on units: when memory size is needed, it is possible to specify# it in the usual form of 1k 5GB 4M and so forth:  关于单位,当你需要指定内存的大小时,可以使用如下的单位来指定## 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 bytes# 1gb => 1024*1024*1024 bytes## units are case insensitive so 1GB 1Gb 1gB are all the same.  单位是大小写不敏感的 所以 1GB 1Gb 1gB 是一样的

3.includes

  通过includes包含,redis.conf可以作为总闸,包含其他
  允许include其他配置文件,为了避免覆盖,最好是在最后一行include额外的配置
  不能通过”CONFIG REWRITE”修改include内容

################################## INCLUDES #################################### Include one or more other config files here.  This is useful if you# have a standard template that goes to all Redis servers but also need# to customize a few per-server settings.  Include files can include# other files, so use this wisely.  在这里添加一个或多个其他配置文件。   如果你需要设置一个统一的配置文件模板,又需要对一些配置文件进行个性化设置,那么这个配置方式对你非常有用。  这个配置文件可以包含其他配置文件,所以聪明地使用。## Notice option "include" won't be rewritten by command "CONFIG REWRITE"# from admin or Redis Sentinel. Since Redis always uses the last processed# line as value of a configuration directive, you'd better put includes# at the beginning of this file to avoid overwriting config change at runtime.  注意选项“include”不会被来自admin或Redis Sentinel的命令“CONFIG REWRITE”重写。  由于Redis总是使用最后的处理line作为配置指令的值,最好放入include在此文件的开头,以避免在运行时覆盖配置更改。## If instead you are interested in using includes to override configuration# options, it is better to use include as the last line.  如果不是您有兴趣使用include来覆盖配置选项,最好使用include作为最后一行。#配置文件有顺序,后面的配置文件会覆盖前面的配置文件。## include /path/to/local.conf# include /path/to/other.conf

4.network

################################## NETWORK #####################################1 bind命令 # By default, if no "bind" configuration directive is specified, Redis listens# for connections from all the network interfaces available on the server.# It is possible to listen to just one or multiple selected interfaces using# the "bind" configuration directive, followed by one or more IP addresses.  默认情况下,如果没有指定“绑定”配置指令,则Redis监听用于从服务器上可用的所有网络接口连接。  可以使用“绑定”配置指令监听一个或多个选定的接口,后跟一个或多个IP地址。## Examples:## bind 192.168.1.100 10.0.0.1# bind 127.0.0.1 ::1## ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the# internet, binding to all the interfaces is dangerous and will expose the# instance to everybody on the internet. So by default we uncomment the# following bind directive, that will force Redis to listen only into# the IPv4 lookback interface address (this means Redis will be able to# accept connections only from clients running into the same computer it# is running).    ~~~ WARNING ~~~ 如果运行Redis服务的机器直接暴漏在Internet中,那么绑定所有的接口是一件危险的事。因为这样会将Redis服务暴漏给Internet中的每一个人。所以默认情况下,使用bind 127.0.0.1命令强制Redis监听IPv4环回接口地址,也就是说Redis仅接受本机的客户端请求。    服务器可以有一个网络接口(通常表述为网卡),或者多个。假设某机器上有两个网卡,分别为192.168.205.5192.168.205.6,如果bind 192.168.205.5,那么只有该网卡地址接受外部请求,如果不绑定,则两个网卡口都接受请求。## IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES# JUST COMMENT THE FOLLOWING LINE.       如果需要进行外网访问则需注销该命令行。在配置文件中,“#”代表注释# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bind 127.0.0.12.保护模式# Protected mode is a layer of security protection, in order to avoid that# Redis instances left open on the internet are accessed and exploited.  保护模式是Redis提供的安全防护层。设立该层是为了避免网络对未关闭Redis实例的随意访问。## When protected mode is on and if:## 1) The server is not binding explicitly to a set of addresses using the#    "bind" directive.# 2) No password is configured.  该模式需要开启,当:  1) 没有使用“bind”命令明确需要绑定的地址;  2) 没有配置密码。## The server only accepts connections from clients connecting from the# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain# sockets.  该模式启动后,服务器仅能接受使用IPv4、IPv6环回地址(127.0.0.1或::1)和本地Socket的客户端的连接请求。## By default protected mode is enabled. You should disable it only if# you are sure you want clients from other hosts to connect to Redis# even if no authentication is configured, nor a specific set of interfaces# are explicitly listed using the "bind" directive.protected-mode yes  默认情况下,保护模式是开启的。建议只有在已明确待连接的客户端无需授权或无需使用bind指定特定的接口时才关闭该模式。----- 3 端口# Accept connections on the specified port, default is 6379 (IANA #815344).# If port 0 is specified Redis will not listen on a TCP socket.port 6379  在指定的端口上进行监听,默认是 6379。  当端口设置为0时,Redis就不会在TCP socket上进行监听。----- 4 TCP listen() backlog设置# TCP listen() backlog.## In high requests-per-second environments you need an high backlog in order# to avoid slow clients connections issues. Note that the Linux kernel# will silently truncate it to the value of /proc/sys/net/core/somaxconn so# make sure to raise both the value of somaxconn and tcp_max_syn_backlog# in order to get the desired effect.tcp-backlog 511  设置tcp的backlog,backlog其实是一个连接队列,backlog队列总和=未完成三次握手队列 + 已经完成三次握手队列。  在一个并发量高的环境中,需要指定一个比较大的backlog值来避免慢连接情况的发生。注意,linux内核会默认使用/proc/sys/net/core/somaxconn值来减小backlog实际值。因此为了获得期望的值,需要确保增大 somaxconn 和 tcp_max_syn_backlog 这两个值。  在高并发环境下你需要一个高backlog值来避免慢客户端连接问题。注意Linux内核会将这个值减小到/proc/sys/net/core/somaxconn的值,所以需要确认增大somaxconn和tcp_max_syn_backlog两个值来达到想要的效果  backlog详情:http://blog.csdn.net/oChangWen/article/details/78318149----- 5 Unix socket# Unix socket.## Specify the path for the Unix socket that will be used to listen for# incoming connections. There is no default, so Redis will not listen# on a unix socket when not specified.  指定Unix socket路径来进行连接监听。默认是不指定,因此redis不会在Unix socket上进行监听。## unixsocket /tmp/redis.sock# unixsocketperm 700----- 6 Client timeout# Close the connection after a client is idle for N seconds (0 to disable)timeout 0  当client在空闲N秒后,关闭该连接(0表示不处理空闲连接,默认方式)  单位为秒,如果设置为0,则不会进行Keepalive检测,建议设置成60 ----- 7 TCP keepalive时间# TCP keepalive.## If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence# of communication. This is useful for two reasons:  当该值非零时,如果通信缺失,Redis会使用SO_KEEPALIVE发送TCP ACKs给客户端。这样做的好处有二个:## 1) Detect dead peers.# 2) Take the connection alive from the point of view of network#    equipment in the middle.  1)检测已经死亡对端。(TCP关闭存在无法完成4次握手的情况,如断电,断网,数据丢失等等)  2)保存已有连接的活性。## On Linux, the specified value (in seconds) is the period used to send ACKs.# Note that to close the connection the double of the time is needed.# On other kernels the period depends on the kernel configuration.  在Linux中,该指定时间是一次发送ACKs的时间片。对于其他内核系统,其时间片大小与内核配置有关。## A reasonable value for this option is 300 seconds, which is the new# Redis default starting with Redis 3.2.1.tcp-keepalive 300  一个比较合理的值是300 seconds。Redis 3.2.1版本之后默认指定该值为300 seconds。

5.general-通用配置

################################# GENERAL #####################################----- 1 daemon# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.daemonize no  默认情况下,Redis并不是一个守护进程,如果需要将Redis设置成守护进程,则可以使用daemonize yes进行配置。  注意:当Redis作为守护进程时, 其pid 文件为 /var/run/redis.pid。---- 2 supervision ----# If you run Redis from upstart or systemd, Redis can interact with your# supervision tree. Options:#   supervised no      - no supervision interaction#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET#   supervised auto    - detect upstart or systemd method based on#                        UPSTART_JOB or NOTIFY_SOCKET environment variables# Note: these supervision methods only signal "process is ready."#       They do not enable continuous liveness pings back to your supervisor.supervised no  如果需要在机器启动(upstart模式 或systemd模式)时就启动Redis服务器,可以通过该选项来配置Redis。(Redis 3.2新增命令)  支持的模式:  supervised no – 无,不会与supervised tree进行交互  supervised upstart – 将Redis服务器添加到SIGSTOP 模式中  supervised systemd – 将READY=1 写入 $NOTIFY_SOCKET  supervised auto – 根据环境变量UPSTART_JOB 或NOTIFY_SOCKET检测upstart 还是 systemd  注意,上述supervision方法(upstart或systemd)仅发出“程序已就绪”信号,不会继续给supervisor返回ping回复。  默认是不开启:-------- 3 pid文件# If a pid file is specified, Redis writes it where specified at startup# and removes it at exit.  如果指定了pid文件,Redis会在启动时写该pid文件,在退出时删除该文件。## When the server runs non daemonized, no pid file is created if none is# specified in the configuration. When the server is daemonized, the pid file# is used even if not specified, defaulting to "/var/run/redis.pid".  当Redis服务器已守护进程启动时,如果指定了配置文件,则直接使用,如果没有指定,则创建/var/run/redis.pid作为配置文件。## Creating a pid file is best effort: if Redis is not able to create it# nothing bad happens, the server will start and run normally.pidfile /var/run/redis_6379.pid---- 4 日志级别# Specify the server verbosity level.# This can be one of:# debug (a lot of information, useful for development/testing)# verbose (many rarely useful info, but not a mess like the debug level)# notice (moderately verbose, what you want in production probably)# warning (only very important / critical messages are logged)loglevel notice  指定服务器的verbosity级别。Redis提供四种级别:  debug —- 包含大量信息,用于开发和测试  verbose —- 包含一些稀有的有用信息,但没有debug级别混乱  notice —- 适量提示信息,用于生产环境  warning —- 只包含非常重要和关键的信息  默认是notice级别:----- 5 日志文件名称# Specify the log file name. Also the empty string can be used to force# Redis to log on the standard output. Note that if you use standard# output for logging but daemonize, logs will be sent to /dev/nulllogfile ""  指定日志文件名称。指定为空时将输出到标准输出设备中。如果Redis以守护进程启动,当日志文件名称为空时,日志将会输出到 /dev/null----- 6 写系统日志----- 6.1允许写系统日志# To enable logging to the system logger, just set 'syslog-enabled' to yes,# and optionally update the other syslog parameters to suit your needs.# syslog-enabled no  将syslog-enabled设置为yes时, 允许将Redis服务日志记录到系统日志中。  此外,还可以使用更多的日志参数来满足特定要求。----- 6.2.指定在系统日志身份# Specify the syslog identity.# syslog-ident redis  一旦enable写入系统日志,可以指定服务在系统日志身份。----- 6.2.指定系统日志能力级别# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.# syslog-facility local0  系统日志级别必须是 LOCAL0 到 LOCAL7 之间(闭区间)的值。----- 7 数据库数量# Set the number of databases. The default database is DB 0, you can select# a different one on a per-connection basis using SELECT <dbid> where# dbid is a number between 0 and 'databases'-1databases 16 设置数据库的数量。默认使用0号数据库。可以在每一个连接上使用SELECT <dbid> 来指定另外的数据库,但是这个值必须在 0到 ‘database’-1之间。

6.snapshotting 快照

################################ SNAPSHOTTING  #################################------ 1 DB持久化# Save the DB on disk:     将DB数据保存到磁盘。格式为:##   save <seconds> <changes>##   Will save the DB if both the given number of seconds and the given#   number of write operations against the DB occurred.    当在规定的时间内seconds,如果写磁盘的次数超过了changes,则将DB数据保存到磁盘。 ##   In the example below the behaviour will be to save:#   after 900 sec (15 min) if at least 1 key changed#   after 300 sec (5 min) if at least 10 keys changed#   after 60 sec if at least 10000 keys changed    默认    save 900(15 min) 1    save 300(5 min) 10    save 60 10000     如save 900 1表示在900秒内,如果对DB进行了至少一次写操作,则将DB数据持久化到磁盘上。##   Note: you can disable saving completely by commenting out all "save" lines    注意,可以通过注销所有save命令或将在所有save命令后追加save置空(save “”)命令    来禁用save功能。#   It is also possible to remove all the previously configured save#   points by adding a save directive with a single empty string argument#   like in the following example:##   save ""  如果想禁用RDB持久化的策略,只要不设置任何save指令,或者给save传入一个空字符串参数也可以----- 2 bgsave-error# By default Redis will stop accepting writes if RDB snapshots are enabled# (at least one save point) and the latest background save failed.# This will make the user aware (in a hard way) that data is not persisting# on disk properly, otherwise chances are that no one will notice and some# disaster will happen.    默认情况下,在发生RDB快照或BGSAVE执行失败的那一刻,Redi是执行接收写请求。     这会使用户察觉(通常比较困难)到数据没有正确的持久化到磁盘。否则有可能出现不被察觉的灾难性后果。## If the background saving process will start working again Redis will# automatically allow writes again.  当后台BGSAVE程序可以再次开始工作时,Reidis会再次自动允许写入。## However if you have setup your proper monitoring of the Redis server# and persistence, you may want to disable this feature so that Redis will# continue to work as usual even if there are problems with disk,# permissions, and so forth.stop-writes-on-bgsave-error yes  如果已经对Server和服务器持久化建立了正确的监控,那么当你禁用该功能后,   即使磁盘、持久化等出现问题,Redis也能继续提供服务。  (如果配置成no,表示你不在乎数据不一致或者有其他的手段发现和控制)----- 3 rdbcompression# Compress string objects using LZF when dump .rdb databases?# For default that's set to 'yes' as it's almost always a win.# If you want to save some CPU in the saving child set it to 'no' but# the dataset will likely be bigger if you have compressible values or keys.rdbcompression yes  默认情况下,在dump RDB文件时,Redis采用LZF(一种高效的压缩算法)算法   进行字符串对象数据的压缩,其性能较高。虽然LZF算法会消耗部分CPU性能,   但是其数据压缩能够较高,所以建议不要关闭:# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.# This makes the format more resistant to corruption but there is a performance# hit to pay (around 10%) when saving and loading RDB files, so you can disable it# for maximum performances.## RDB files created with checksum disabled have a checksum of zero that will# tell the loading code to skip the check.rdbchecksum yes    rdbchecksum:在存储快照后,还可以让redis使用CRC64算法来进行数据校验,     但是这样做会增加大约10%的性能消耗,如果希望获取到最大的性能提升,可以关闭此功能----- 4 RDB文件名称# The filename where to dump the DBdbfilename dump.rdb----- 5 工作目录# The working directory.## The DB will be written inside this directory, with the filename specified# above using the 'dbfilename' configuration directive.## The Append Only File will also be created inside this directory.## Note that you must specify a directory here, not a file name.dir ./    指定RDB文件所在目录。该目录也是AOF文件所在目录。     注意,这里是指定一个目录而不是文件名。默认是当前目录

7.replication 复制

################################# REPLICATION #################################----- 1 主从关系建立# Master-Slave replication. Use slaveof to make a Redis instance a copy of# another Redis server. A few things to understand ASAP about Redis replication.  Redis主从复制。单机模式下,Redis支持使用slaveof命令从另一个Redis服务器的拷贝中来创建一个实例。集群模式下则使用cluster replicate <master-id>命令。Redis复制使用前须知:## 1) Redis replication is asynchronous, but you can configure a master to#    stop accepting writes if it appears to be not connected with at least#    a given number of slaves.# 2) Redis slaves are able to perform a partial resynchronization with the#    master if the replication link is lost for a relatively small amount of#    time. You may want to configure the replication backlog size (see the next#    sections of this file) with a sensible value depending on your needs.# 3) Replication is automatic and does not need user intervention. After a#    network partition slaves automatically try to reconnect to masters#    and resynchronize with them.## slaveof <masterip> <masterport>  1)    Redis复制是异步复制,但是可以配置连接的从节点数量。  2)    当连接断开,Redis从节点支持部分重同步(psync)功能来保证主从节点数据同步。  3)    复制过程是一个自动化过程,无需人工干预。当出现网络分区后,从节点会自动尝试建立与主节点的连接,并尝试同步。  建立主从连接的命令如下:  slaveof <masterip> <masterport>------ 2 授权密码# If the master is password protected (using the "requirepass" configuration# directive below) it is possible to tell the slave to authenticate before# starting the replication synchronization process, otherwise the master will# refuse the slave request.  当主节点开启密码保护时(通过配置"requirepass" 命令),从节点必须在开始复制同步前进行授权操作,否则其请求不会被接受。## masterauth <master-password>  注意,该命令只有在主节点开启密码保护时才生效。------ 3 从节点是否支持脏读# When a slave loses its connection with the master, or when the replication# is still in progress, the slave can act in two different ways:  当主从断开连接或主从进行复制时,从节点对外拥有两种策略:## 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will#    still reply to client requests, possibly with out of date data, or the#    data set may just be empty if this is the first synchronization.  1)如果“slave-serve-stale-data”参数设置成“yes”(默认情况下),则从节点可以响应客户端请求,尽管可能会恢复过期数据或空数据(如果主从第一次进行同步)。## 2) if slave-serve-stale-data is set to 'no' the slave will reply with#    an error "SYNC with master in progress" to all the kind of commands#    but to INFO and SLAVEOF.  2)如果“slave-serve-stale-data”参数设置成“no”,则从节点会对除INFO 和SLAVEOF之外的命令返回"SYNC with master in progress"信息。#slave-serve-stale-data yes----- 4 从节点是否支持写入# You can configure a slave instance to accept writes or not. Writing against# a slave instance may be useful to store some ephemeral data (because data# written on a slave will be easily deleted after resync with the master) but# may also cause problems if clients are writing to it because of a# misconfiguration.  指定从节点是否支持写操作。当需要存储一些临时数据时,让从节点支持写操作很有用。这样一来,就可以通过主从同步轻松的将已写入从节点的数据删除。但是,如果配置出错,也会出现客户端写入出错等问题。## Since Redis 2.6 by default slaves are read-only.  注意,从Redis 2.6之后,从节点默认是只读的。## Note: read only slaves are not designed to be exposed to untrusted clients# on the internet. It's just a protection layer against misuse of the instance.# Still a read only slave exports by default all the administrative commands# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve# security of read only slaves using 'rename-command' to shadow all the# administrative / dangerous commands.slave-read-only yes    提示,只读的从服务器并不是设计给非信任的互联网客户端提供服务。这种模式的服务器设置只是一个用来防止对服务器实例进行误操作的保护层。默认情况下,只读从服务器能够输出管理员命令,如CONFIG、 DEBUG等。如果想限制只读从节点输出的管理型命令,可以通过'rename-command' 命令来隐藏这些管理员命令或危险命令。    提高它的安全性,使得她作为一个影子来执行管理或者危险的命令。----- 5 复制策略:有无磁盘# Replication SYNC strategy: disk or socket.    主从节点的数据同步策略有两种:磁盘同步、套接字同步。## -------------------------------------------------------# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY  WARNING: 无磁盘复制(DISKLESS REPLICATION I)当前仍处于实验阶段# -------------------------------------------------------## New slaves and reconnecting slaves that are not able to continue the replication# process just receiving differences, need to do what is called a "full# synchronization". An RDB file is transmitted from the master to the slaves.# The transmission can happen in two different ways:  对于新连接的slaves或断开重连的slaves将无法执行“部分同步”,需要进行一次完全同# 步。当进行完全同步时,主节点将传播一个RDB文件给从节点。该RDB文件的传播方式# 有两种:## 1) Disk-backed: The Redis master creates a new process that writes the RDB#                 file on disk. Later the file is transferred by the parent#                 process to the slaves incrementally.# 2) Diskless: The Redis master creates a new process that directly writes the#              RDB file to slave sockets, without touching the disk at all.    1)基于磁盘:Redis主节点创建一个新进程将RDB文件写到磁盘,然后将生成的RDB文件传播给从节点。    2)无磁盘:Redis主节点创建一个新进程直接将RDB文件写到slaves的套接字中,RDB文件无需落盘。## With disk-backed replication, while the RDB file is generated, more slaves# can be queued and served with the RDB file as soon as the current child producing# the RDB file finishes its work. With diskless replication instead once# the transfer starts, new slaves arriving will be queued and a new transfer# will start when the current one terminates.    基于磁盘的复制,一旦RDB文件生成,多个slaves将排队等待并可以共享该文件。而无磁盘复制一旦开始传输数据,新slaves到来后将会排队等待。## When diskless replication is used, the master waits a configurable amount of# time (in seconds) before starting the transfer in the hope that multiple slaves# will arrive and the transfer can be parallelized.    在使用无磁盘复制时,主节点在开始传输同步数据前将根据配置的时间进行等待,从而实现多个从节点的并发传输。## With slow disks and fast (large bandwidth) networks, diskless replication# works better.repl-diskless-sync no    在磁盘速度缓慢且网络速度很快(高带宽)时,无磁盘复制效率更高。默认情况下,无磁盘复制同步关闭。------ 6 无磁盘复制等待时间# When diskless replication is enabled, it is possible to configure the delay# the server waits in order to spawn the child that transfers the RDB via socket# to the slaves.## This is important since once the transfer starts, it is not possible to serve# new slaves arriving, that will be queued for the next RDB transfer, so the server# waits a delay in order to let more slaves arrive.## The delay is specified in seconds, and by default is 5 seconds. To disable# it entirely just set it to 0 seconds and the transfer will start ASAP.repl-diskless-sync-delay 5  无磁盘复制前,主节点需要等待的时间。该配置在启用无磁盘复制时将生效。  由于一旦开启一次数据传输,其余slaves将排队等待,所以最好让主节点等待一段时间,这样主节点就可对多个slaves并发传播数据。  等待的单位是秒(second),默认是5秒。一旦将其设置为0,主节点将会马上开始数据传输。 ------ 7 slaves定时向master发送PING的时间片 # Slaves send PINGs to server in a predefined interval. It's possible to change# this interval with the repl_ping_slave_period option. The default value is 10# seconds.## repl-ping-slave-period 10    默认情况下,slaves每10秒向master发送一次PING消息。可以根据网络等因素进行设置。该配置默认在配置文件中关闭:------ 8 复制超时阈值# The following option sets the replication timeout for:## 1) Bulk transfer I/O during SYNC, from the point of view of slave.# 2) Master timeout from the point of view of slaves (data, pings).# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).## It is important to make sure that this value is greater than the value# specified for repl-ping-slave-period otherwise a timeout will be detected# every time there is low traffic between the master and the slave.## repl-timeout 60    以下情境将使用到复制超时阈值:    1) 从节点在执行SYNC期间,检测块文件传输超时    2) 从节点检测主节点离线(data、pings)    3) 主节点检测从节点离线(REPLCONF ACK)    必须要确保复制超时阈值(repl-timeout)大于slaves定时向master发送PING的时间片(repl-ping-slave-period),否则将总会检测到复制超时(当slave发送PING的时间片大于复制超时阈值时,slave还未发送ping就会被定性为复制超时)。------ 9 TCP_NODELAY功能# Disable TCP_NODELAY on the slave socket after SYNC?## If you select "yes" Redis will use a smaller number of TCP packets and# less bandwidth to send data to slaves. But this can add a delay for# the data to appear on the slave side, up to 40 milliseconds with# Linux kernels using a default configuration.## If you select "no" the delay for data to appear on the slave side will# be reduced but more bandwidth will be used for replication.## By default we optimize for low latency, but in very high traffic conditions# or when the master and slaves are many hops away, turning this to "yes" may# be a good idea.repl-disable-tcp-nodelay no    执行完SYNC后,是否要禁用TCP_NODELAY。    当禁用该功能后,Redis会使用占用更少带宽的小TCP包向从节点发送数据。但是这样做将会增大从节点端数据传输延时。在Linux下禁用TCP_NODELAY功能将导致40 微秒的延迟。    当启动该功能后,在进行复制时将会减少数据传输延迟,但是会占用更大的带宽。    默认情况下,我们优先选择低延迟,但是在高速网络或主从节点存在多hops路径时,建议禁用TCP_NODELAY功能。    默认开启TCP_NODELAY功能。格式如下:------ 10 复制积压缓冲区大小# Set the replication backlog size. The backlog is a buffer that accumulates# slave data when slaves are disconnected for some time, so that when a slave# wants to reconnect again, often a full resync is not needed, but a partial# resync is enough, just passing the portion of data the slave missed while# disconnected.## The bigger the replication backlog, the longer the time the slave can be# disconnected and later be able to perform a partial resynchronization.## The backlog is only allocated once there is at least a slave connected.## repl-backlog-size 1mb    设置复制积压缓冲区(replication backlog)大小。当slaves断开与节点连接后,Redis使用复制积压缓冲区记录需要未发送给slave的数据。当从节点重连后,仅需执行一次部分同步,将从节点缺失数据补全。    复制积压缓冲区(replication backlog)越大,Redis可以支持的slave离线时间就越长。复制积压缓冲区用于部分重同步。    复制缓冲区只有在有slave连接时才分配内存。没有slave时,该内存会被释放出来,默认大小为1m。格式如下:------ 11 复制积压缓冲区释放时间片# After a master has no longer connected slaves for some time, the backlog# will be freed. The following option configures the amount of seconds that# need to elapse, starting from the time the last slave disconnected, for# the backlog buffer to be freed.## A value of 0 means to never release the backlog.## repl-backlog-ttl 3600    当主节点不再有新连接的从节点后,复制积压缓冲区将会被释放。为避免因从节点频繁掉线后上线而频繁的进行复制积压缓冲区的释放与申请,Redis提供复制积压缓冲区释放时间片(repl-backlog-ttl)参数,保证主节点在检测到从节点掉线后的规定时间内不会释放该缓冲区。    值为零时表示不会释放该复制积压缓冲区。    单位为秒,配置如下:------ 12 从节点优先级# The slave priority is an integer number published by Redis in the INFO output.# It is used by Redis Sentinel in order to select a slave to promote into a# master if the master is no longer working correctly.## A slave with a low priority number is considered better for promotion, so# for instance if there are three slaves with priority 10, 100, 25 Sentinel will# pick the one with priority 10, that is the lowest.## However a special priority of 0 marks the slave as not able to perform the# role of master, so a slave with priority of 0 will never be selected by# Redis Sentinel for promotion.## By default the priority is 100.slave-priority 100    使用整数表示从节点优先级。    当主节点无法正常工作后,Sentinel将使用该优先级在从节点中推选出新的主节点。    优先级对应的整数值越小,被推选成主节点的可能性更大。但是当优先级的值为零时表示该从节点不具备成为主节点的身份。    默认优先级为100。配置形式如下:------ 13 从节点连接数及从节点延时设置# It is possible for a master to stop accepting writes if there are less than# N slaves connected, having a lag less or equal than M seconds.## The N slaves need to be in "online" state.## The lag in seconds, that must be <= the specified value, is calculated from# the last ping received from the slave, that is usually sent every second.## This option does not GUARANTEE that N replicas will accept the write, but# will limit the window of exposure for lost writes in case not enough slaves# are available, to the specified number of seconds.## For example to require at least 3 slaves with a lag <= 10 seconds use:## min-slaves-to-write 3# min-slaves-max-lag 10## Setting one or the other to 0 disables the feature.## By default min-slaves-to-write is set to 0 (feature disabled) and# min-slaves-max-lag is set to 10.    当主节点的已连接从节点数小于N且这些从节点延迟均大于M秒,该主节点将停止接收写请求。    从节点处于“online”状态,当且仅当延迟(通过计算距离上一次接收从节点的ping消息的时间间隔获得)小于指定的阈值。    这个选项配置不是用来保证N个部分接收写信息,而是为了在没有足够的从节点可用时,限制写丢失。    如需要至少需要3个从节点并在10s内可用,则设置:  min-slaves-to-write 3  min-slaves-max-lag 10    一旦对这两个中的一个赋值为零,则该功能失效。    默认min-slaves-to-write 参数设置为0,即该功能默认不启用。------ 14 从节点指定的IP和port# A Redis master is able to list the address and port of the attached# slaves in different ways. For example the "INFO replication" section# offers this information, which is used, among other tools, by# Redis Sentinel in order to discover slave instances.# Another place where this info is available is in the output of the# "ROLE" command of a masteer.## The listed IP and address normally reported by a slave is obtained# in the following way:##   IP: The address is auto detected by checking the peer address#   of the socket used by the slave to connect with the master.##   Port: The port is communicated by the slave during the replication#   handshake, and is normally the port that the slave is using to#   list for connections.## However when port forwarding or Network Address Translation (NAT) is# used, the slave may be actually reachable via different IP and port# pairs. The following two options can be used by a slave in order to# report to its master a specific set of IP and port, so that both INFO# and ROLE will report those values.## There is no need to use both the options if you need to override just# the port or the IP address.## slave-announce-ip 5.5.5.5# slave-announce-port 1234    Redis主节点可以通过多种途径显示已连接从节点的IP和port。如Sentinel 可以使用“INFO replication”命令来发现从节点实例;Master可以使用“ROLE”命令显示从节点IP和port信息等。    slave获取IP和port的方式是:        IP:自动检测获取。当从节点连接主节点时,通过检查对应套接字地址获取。        Port:从节点在复制中和主节点握手时需要使用到port。通常情况下,port即为连接时的port。    但是,当发生端口转发(port forwarding,转发一个网络端口从一个网络节点到另一个网络节点的行为)或使用NAT(Network Address Translation,网络地址转换)技术是,从节点需要被分配不同IP和port后才能被访问。    接下来的两个配置用来设置从节点的IP和port,用来告知主节点所指定的IP和port,这样INFO和ROLE 才能继续返回结果。    当需要重写IP和port时,则无需配置该选项。

8.security 安全

################################## SECURITY ###################################------ 1 认证密码# Require clients to issue AUTH <PASSWORD> before processing any other# commands.  This might be useful in environments in which you do not trust# others with access to the host running redis-server.## This should stay commented out for backward compatibility and because most# people do not need auth (e.g. they run their own servers).## Warning: since Redis is pretty fast an outside user can try up to# 150k passwords per second against a good box. This means that you should# use a very strong password otherwise it will be very easy to break.## requirepass foobared    Server在处理客户端命令前,该客户端需要提供提供认证密码。这在非可信网络环境中很有用。    为减少后台执行复杂度,这个选项一般都会被注释掉。因为大多数用户不需要授权。(如用户使用自己的服务器)    Warning: 由于Redis执行高效,所以外部用户每秒可以尝试认证15w次。也就是说,为避免密码被快送攻破,用户需要使用一个极其复杂的密码。----- 2 命令重命名# Command renaming.## It is possible to change the name of dangerous commands in a shared# environment. For instance the CONFIG command may be renamed into something# hard to guess so that it will still be available for internal-use tools# but not available for general clients.## Example:## rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52## It is also possible to completely kill a command by renaming it into# an empty string:## rename-command CONFIG ""## Please note that changing the name of commands that are logged into the# AOF file or transmitted to slaves may cause problems.    重命名命令。    在一个共享环境中有必要对危险命令进行重命令,从而避免危险命令的滥用、无用。    如给CONFIG命令重新设置一个难以猜测的命令,这样这个命令就很难被普通用户使用的,但仍能被内部工具使用。    如:        rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52    当然,有时需要禁用一些命令。可以通过将命令置空实现:  rename-command CONFIG ""    注意,一定要避免重命名那些写AOF文件或传输数据给slaves的命令,否则将会导致各种难以预料的错误。

9.limits

################################### LIMITS ####################################------ 1 最大客户端连接数# Set the max number of connected clients at the same time. By default# this limit is set to 10000 clients, however if the Redis server is not# able to configure the process file limit to allow for the specified limit# the max number of allowed clients is set to the current file limit# minus 32 (as Redis reserves a few file descriptors for internal uses).## Once the limit is reached Redis will close all the new connections sending# an error 'max number of clients reached'.## maxclients 10000    设置某一时刻客户端的并发连接数。默认情况下,限制上限是1w。但是,如果Redis服务器没有配置进程文件limit,那么可允许连接的最大客户端个数将被设置为当前文件限制的最小值32(Redis会保留一部分文件给内部用户)。    一旦得到了连接上限,Redis将关闭所有新连接并发送错误“max number of clients reached”提示。设置redis同时可以与多少个客户端进行连接。默认情况下为10000个客户端。当你无法设置进程文件句柄限制时,redis会设置为当前的文件句柄限制值减去32,因为redis会为自身内部处理逻辑留一些句柄出来。如果达到了此限制,redis则会拒绝新的连接请求,并且向这些连接请求方发出“max number of clients reached”以作回应。------ 2 最大可用内存# Don't use more memory than the specified amount of bytes.# When the memory limit is reached Redis will try to remove keys# according to the eviction policy selected (see maxmemory-policy).## If Redis can't remove keys according to the policy, or if the policy is# set to 'noeviction', Redis will start to reply with errors to commands# that would use more memory, like SET, LPUSH, and so on, and will continue# to reply to read-only commands like GET.## This option is usually useful when using Redis as an LRU cache, or to set# a hard memory limit for an instance (using the 'noeviction' policy).## WARNING: If you have slaves attached to an instance with maxmemory on,# the size of the output buffers needed to feed the slaves are subtracted# from the used memory count, so that network problems / resyncs will# not trigger a loop where keys are evicted, and in turn the output# buffer of slaves is full with DELs of keys evicted triggering the deletion# of more keys, and so forth until the database is completely emptied.## In short... if you have slaves attached it is suggested that you set a lower# limit for maxmemory so that there is some free RAM on the system for slave# output buffers (but this is not needed if the policy is 'noeviction').## maxmemory <bytes>    不要再内存超过指定限制时仍然使用内存。    当达到内存上限时,Redis会根据选定的过期键策略移除一些key。    如果根据过期键策略仍不能移除一些键或者过期键策略设置成“noeviction”(不启用过期键策略),那么Redis会向如SET、LPUSH等使用内存的命令返回错误,向诸如GET等读命令正常返回结果。    这个配置通常在将Redis当过LRU 缓存或对以设置硬性的内存上限的Redis很适用。    WARNING: slaves的输出缓冲区不在主节点的maxmemory计算中,所以设置的maxmemory不宜过大。如果过大,可能导致主机的剩余内存过小,从而不能预留足够的内存用于创建slaves的输出缓冲区。    简言之,如果当前节点存在已连接的从节点,建立设置一个较小的maxmemory上限,这样系统就可以有多余的RAM用与创建从节点输出缓存。(当过期键策略设置成'noeviction'时,则没有必要这么做)------ 3 内存淘汰策略# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory# is reached. You can select among five behaviors:## volatile-lru -> remove the key with an expire set using an LRU algorithm# allkeys-lru -> remove any key according to the LRU algorithm# volatile-random -> remove a random key with an expire set# allkeys-random -> remove a random key, any key# volatile-ttl -> remove the key with the nearest expire time (minor TTL)# noeviction -> don't expire at all, just return an error on write operations## Note: with any of the above policies, Redis will return an error on write#       operations, when there are no suitable keys for eviction.##       At the date of writing these commands are: set setnx setex append#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby#       getset mset msetnx exec sort## The default is:## maxmemory-policy noeviction     MAXMEMORY POLICY: 当达到maxmemory时,可以采用的内存淘汰策略。    Redis提供五种内存淘汰策略:(1)volatile-lru:使用LRU算法移除key,只对设置了过期时间的键(2)allkeys-lru:使用LRU算法移除key(3)volatile-random:在过期集合中移除随机的key,只对设置了过期时间的键(4)allkeys-random:移除随机的key(5)volatile-ttl:移除那些TTL值最小的key,即那些最近要过期的key(6)noeviction:不进行移除。针对写操作,只是返回错误信息    Note: 不管采用了上述何种淘汰策略,当没有合适的键进行移除时,Redis仍会返回写错误。        这些写命令是: set setnx setex append        incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd        sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby        zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby        getset mset msetnx exec sort    默认内存淘汰策略是’noeviction’。----- 4 最大样例检测数# LRU and minimal TTL algorithms are not precise algorithms but approximated# algorithms (in order to save memory), so you can tune it for speed or# accuracy. For default Redis will check five keys and pick the one that was# used less recently, you can change the sample size using the following# configuration directive.## The default of 5 produces good enough results. 10 Approximates very closely# true LRU but costs a bit more CPU. 3 is very fast but not very accurate.## maxmemory-samples 5    LRU算法和最小TTL算法都不是精确算法,所以可以对其进行执行速度或精确度上的判定。    默认情况下,Redis会从五个键中选择一个最近最久未使用的键进行淘汰。可以通过配置该选择设置检测基数。    一般情况下,五个检测样本可以获得足够好的结果。10个样本的结果更接近LRU算法,但是会消耗更多的CPU。3个样本可以获得较高的执行速度但是不够精确。

10.append only mode

############################## APPEND ONLY MODE ###############################----- 1 是否开启AOF持久化功能# By default Redis asynchronously dumps the dataset on disk. This mode is# good enough in many applications, but an issue with the Redis process or# a power outage may result into a few minutes of writes lost (depending on# the configured save points).## The Append Only File is an alternative persistence mode that provides# much better durability. For instance using the default data fsync policy# (see later in the config file) Redis can lose just one second of writes in a# dramatic event like a server power outage, or a single write if something# wrong with the Redis process itself happens, but the operating system is# still running correctly.## AOF and RDB persistence can be enabled at the same time without problems.# If the AOF is enabled on startup Redis will load the AOF, that is the file# with the better durability guarantees.## Please check http://redis.io/topics/persistence for more information.appendonly no    默认情况下,Redis会异步将数据集快照到磁盘上。尽管这种模式对许多应用友好,但是当Redis进程崩溃或发生掉电时,几分钟内的写信息将丢失(根据快照执行的粒度)。    AOF作为一种可替换的持久化策略,能够提供更好的耐久性。如使用默认的fsync策略,Redis仅会丢失1s的写信息,当发生突发事件(服务器掉电、服务器进程崩溃但OS运行正常)    AOF持久化和RDB持久化可以同时开启。如果在启动Redis时已经存在AOF文件,则会直接加载AOF文件(考虑到AOF文件相比RDB文件有更好的耐久性)。    关于AOF的更多讯息见: http://redis.io/topics/persistence ----- 2 指定AOF文件名称# The name of the append only file (default: "appendonly.aof")appendfilename "appendonly.aof"    指定AOF文件名称,默认是appendonly.aof。------ 3 fsync()系统函数调用频率# The fsync() call tells the Operating System to actually write data on disk# instead of waiting for more data in the output buffer. Some OS will really flush# data on disk, some other OS will just try to do it ASAP.## Redis supports three different modes:## no: don't fsync, just let the OS flush the data when it wants. Faster.# always: fsync after every write to the append only log. Slow, Safest.# everysec: fsync only one time every second. Compromise.## The default is "everysec", as that's usually the right compromise between# speed and data safety. It's up to you to understand if you can relax this to# "no" that will let the operating system flush the output buffer when# it wants, for better performances (but if you can live with the idea of# some data loss consider the default persistence mode that's snapshotting),# or on the contrary, use "always" that's very slow but a bit safer than# everysec.## More details please check the following article:# http://antirez.com/post/redis-persistence-demystified.html## If unsure, use "everysec".    调用fsync()系统函数用来告知OS将数据写入磁盘,而不是在输出缓冲区等待数据。有些OS将直接flush数据到磁盘,有些其他的OS仅会尝试去flush。    Redis支持三种fsync()调用模式:        no:不执行fsync,由OS决定flush数据的频率。高效。Linux下默认是每30s执行一次flush。        always:每写入一次AOF就调用一次fsync。慢,最安全。        everysec:每秒调用一次fsync。适中。    默认fsync的调用频率是“everysec”,这种策略在执行速度和数据安全进行折中。    当可以容忍一定程度数据丢失并期望更高的性能时,可以使用“no”策略(由操作系统决定flush的频率)。相反的,如果不能容忍数据丢失,可以使用“always”获得更好的安全性,尽管执行更慢。    更多AOF信息可以参考:    http://antirez.com/post/redis-persistence-demystified.html    在无法确定fsync调用频率时,推荐使用“everysec”策略。    在开启AOF持久化功能后,该配置才会生效。# appendfsync alwaysappendfsync everysec# appendfsync noalways:同步持久化 每次发生数据变更会被立即记录到磁盘  性能较差但数据完整性比较好everysec:出厂默认推荐,异步操作,每秒记录   如果一秒内宕机,有数据丢失----- 4 AOF rewrite与fsync# When the AOF fsync policy is set to always or everysec, and a background# saving process (a background save or AOF log background rewriting) is# performing a lot of I/O against the disk, in some Linux configurations# Redis may block too long on the fsync() call. Note that there is no fix for# this currently, as even performing fsync in a different thread will block# our synchronous write(2) call.## In order to mitigate this problem it's possible to use the following option# that will prevent fsync() from being called in the main process while a# BGSAVE or BGREWRITEAOF is in progress.## This means that while another child is saving, the durability of Redis is# the same as "appendfsync none". In practical terms, this means that it is# possible to lose up to 30 seconds of log in the worst scenario (with the# default Linux settings).## If you have latency problems turn this to "yes". Otherwise leave it as# "no" that is the safest pick from the point of view of durability.no-appendfsync-on-rewrite no    当AOF执行fsync的策略是always和everysec时,如果此时有一个后台进程(BGSAVE进程或AOF rewrite进程)正在执行大量的I/O操作到磁盘,在一些Linux系统中,执行fsync会造成较长的阻塞。当前对这种情况还没有很好的解决策略,即使在不同的线程中执行fsync也会导致调用同步write(2)阻塞。    为了缓解上述问题,可以通过配置下述选项来避免在主线程调用fsync()时执行BGSAVE或 BGREWRITEAOF带来的阻塞。    也就是说,默认情况下,当子进程执行BGSAVE或BGREWRITEAOF时,Redis的耐久性将默认转变成"appendfsync none"。在实际的应用中就意味着在最坏的场景下将丢失30s的数据,即使配置了fsync调用频率为always或everysec。(默认情况下,Linux每30s自动调用一次fsync将缓存数据flush到磁盘)    如果当前应用已考虑延迟问题,则将该配置设置成“yes”。否则使用默认配置(“no”),这是从耐久性角度考虑的最安全的选择。no-appendfsync-on-rewrite no     上述配置等价于appendfsync-on-rewrite(在rewrite时仍执行fsync)----- 4 AOF rewrite触发时机# Automatic rewrite of the append only file.# Redis is able to automatically rewrite the log file implicitly calling# BGREWRITEAOF when the AOF log size grows by the specified percentage.## This is how it works: Redis remembers the size of the AOF file after the# latest rewrite (if no rewrite has happened since the restart, the size of# the AOF at startup is used).## This base size is compared to the current size. If the current size is# bigger than the specified percentage, the rewrite is triggered. Also# you need to specify a minimal size for the AOF file to be rewritten, this# is useful to avoid rewriting the AOF file even if the percentage increase# is reached but it is still pretty small.## Specify a percentage of zero in order to disable the automatic AOF# rewrite feature.auto-aof-rewrite-percentage 100设置重写的基准值auto-aof-rewrite-min-size 64mb设置重写的基准值    设置AOF 重写的触发条件。    当AOF日志按照指定的比例增长时,可以通过调用BGREWRITEAOF执行自动的AOF rewrite。    工作原理:Redis通过对比上一次执行rewrite时AOF文件的大小与当前AOF文件大小(在重启时将没有上一次执行rewrite的记录,这时将使用startup时的AOF文件大小),决定是否进行rewrite。    如果当前AOF对于上一次执行rewrite的AOF文件的增长比率大于指定的比率,将会触发一次rewrite。    当然,还需指定一个AOF进行重写的最小单位。这样做可以避免增长比率已经达到要求,但对应的AOF仍很小的情况(这种情况下没有必要进行rewrite)的发生。    如果想要关闭自动AOF rewrite功能,可将进行rewrite要求的增长比率设置0。    默认当AOF大于64MB且相比于上一次rewrite,AOF以扩充了两倍时会触发一次rewrite执行----- 5 AOF 文件不完整# An AOF file may be found to be truncated at the end during the Redis# startup process, when the AOF data gets loaded back into memory.# This may happen when the system where Redis is running# crashes, especially when an ext4 filesystem is mounted without the# data=ordered option (however this can't happen when Redis itself# crashes or aborts but the operating system still works correctly).## Redis can either exit with an error when this happens, or load as much# data as possible (the default now) and start if the AOF file is found# to be truncated at the end. The following option controls this behavior.## If aof-load-truncated is set to yes, a truncated AOF file is loaded and# the Redis server starts emitting a log to inform the user of the event.# Otherwise if the option is set to no, the server aborts with an error# and refuses to start. When the option is set to no, the user requires# to fix the AOF file using the "redis-check-aof" utility before to restart# the server.## Note that if the AOF file will be found to be corrupted in the middle# the server will still exit with an error. This option only applies when# Redis will try to read more data from the AOF file but not enough bytes# will be found.aof-load-truncated yes    在将AOF文件加载到内存时(重启Redis),可能会出现AOF被截断的情况。    如当Redis运行所在系统突然崩溃(当ext4文件系统在安装时没有配置成数据按序存储),会出现AOF被截断情况。    如果Redis程序发生崩溃或异常,但操作系统仍能正常工作,则不会出现AOF被截断的情况。    出现AOF被截断后,Redis要么直接退出并返回错误,要么加载被截断AOF中尽可能多的数据(当前默认方式)。    可以通过aof-load-truncated选项进行配置    当aof-load-truncated设置成“yes”,Redis仍会加载一个被截断的AOF文件,同时向用户报告AOF文件被截断。如果设置成“no”,Redis会直接返回错误并拒绝启动,这时用户需要使用"redis-check-aof"程序修复AOF,只有这样才能重启Server。    注意,如果AOF文件在执行一半时就出现问题,即使设置aof-load-truncated为 “yes”,Redis也会直接退出并返回错误。    这个配置仅在Redis尝试从AOF文件读更多数据但发现没有足够字计数存在时有意义。

11.lua scripting

################################ LUA SCRIPTING  ###############################----- 1 Lua脚本执行超时阈值# Max execution time of a Lua script in milliseconds.## If the maximum execution time is reached Redis will log that a script is# still in execution after the maximum allowed time and will start to# reply to queries with an error.## When a long running script exceeds the maximum execution time only the# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be# used to stop a script that did not yet called write commands. The second# is the only way to shut down the server in the case a write command was# already issued by the script but the user doesn't want to wait for the natural# termination of the script.## Set it to 0 or a negative value for unlimited execution without warnings.lua-time-limit 5000    设置Lua脚本执超时的时间上限,单位是毫秒,milliseconds。    当Lua脚本执行超时,Redis会记录脚本执行之后的结果(超时后)并向查询返回错误。    当一个长时脚本执行时间超过最大执行时间时,只有SCRIPT KILL和 SHUTDOWN NOSAVE 命令可用。停止这类脚本运行的第一个方法是调用一个非写命令。第二种方法是shut down 这个server,如果已经发送了一个写命令但用户并不想等待脚本自然终止。    如果想不限制脚本的执行时间并且不需要返回warning,可以将该参数设置成0或负数。

12.redis cluster

################################ REDIS CLUSTER  ################################# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however# in order to mark it as "mature" we need to wait for a non trivial percentage# of users to deploy it in production.  WARNING EXPERIMENTAL: 尽管当前Redis Cluster代码已经稳定,但是为了将这部分代码水准标记为“mature”,  仍需要一批有分量的用户将该功能应用到生产环境。即Redis Cluster功能仍需要生产实践的考验。++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 启动Redis集群功能# Normal Redis instances can't be part of a Redis Cluster; only nodes that are# started as cluster nodes can. In order to start a Redis instance as a# cluster node enable the cluster support uncommenting the following:## cluster-enabled yes    正常情况下,启动的Redis实例为非集群模式。只有当节点配置成集群模式时才能成为集群节点。如需以集群模式启动,取消下述配置的注释即可:----- 2 集群配置文件命令# Every cluster node has a cluster configuration file. This file is not# intended to be edited by hand. It is created and updated by Redis nodes.# Every Redis Cluster node requires a different cluster configuration file.# Make sure that instances running in the same system do not have# overlapping cluster configuration file names.## cluster-config-file nodes-6379.conf    每个集群节点都有一个集群配置文件。该文件不是用来让用户编辑,而是持久化集群信息。    该文件由集群节点创建并更新。每个Redis 集群节点都需要有唯一的集群配置文件。所以在同一系统创建的多个Redis实例需要确保不存在配置文件名相同的情况发生(这样会导致集群配置文件重载)。----- 3 集群节点超时阈值# Cluster node timeout is the amount of milliseconds a node must be unreachable# for it to be considered in failure state.# Most other internal time limits are multiple of the node timeout.## cluster-node-timeout 15000    集群节点超时阈值用来作为节点不可达并被标记为失效状态的超时上限,单位是毫秒(millisecond)    大部分其他内部时间将其基本参考数。----- 4 从节点可发起故障转移的判定因子(slave-validity-factor)# A slave of a failing master will avoid to start a failover if its data# looks too old.## There is no simple way for a slave to actually have a exact measure of# its "data age", so the following two checks are performed:## 1) If there are multiple slaves able to failover, they exchange messages#    in order to try to give an advantage to the slave with the best#    replication offset (more data from the master processed).#    Slaves will try to get their rank by offset, and apply to the start#    of the failover a delay proportional to their rank.## 2) Every single slave computes the time of the last interaction with#    its master. This can be the last ping or command received (if the master#    is still in the "connected" state), or the time that elapsed since the#    disconnection with the master (if the replication link is currently down).#    If the last interaction is too old, the slave will not try to failover#    at all.## The point "2" can be tuned by user. Specifically a slave will not perform# the failover if, since the last interaction with the master, the time# elapsed is greater than:##   (node-timeout * slave-validity-factor) + repl-ping-slave-period## So for example if node-timeout is 30 seconds, and the slave-validity-factor# is 10, and assuming a default repl-ping-slave-period of 10 seconds, the# slave will not try to failover if it was not able to talk with the master# for longer than 310 seconds.## A large slave-validity-factor may allow slaves with too old data to failover# a master, while a too small value may prevent the cluster from being able to# elect a slave at all.## For maximum availability, it is possible to set the slave-validity-factor# to a value of 0, which means, that slaves will always try to failover the# master regardless of the last time they interacted with the master.# (However they'll always try to apply a delay proportional to their# offset rank).## Zero is the only value able to guarantee that when all the partitions heal# the cluster will always be able to continue.## cluster-slave-validity-factor 10    当主节点失效后,Redis避免让存储数据过旧的从节点发起故障转移。    没有简单的方式可以直接准确判定从节点的”data age”,可以通过下面两个方面的检测实现:    1) 如果有多个从节点可以发起故障转移,可以让他们交换信息以选出数据状态最节点主节点的从节点。从节点可以通过offset进行排名并通过该排名延迟发起故障转移的时机。    2) 每个独立的从节点计算最近一次与主节点交互的时间。这里的交互可以是最近一次PING、最近一次接收到来自主节点的命令、与主节点断开连接的时间(当复制链接已经down掉时)。如果最近一次与主节点的交互已经足够久远,那么这个从节点将放弃进行故障转移。    在2)中的时间阈值可以由用户设定。特别地,当从节点的最近一次与主节点的交互远大于(node-timeout * slave-validity-factor) + repl-ping-slave-period 时,这个从节点将不会执行故障转移。    例如假设node-timeout为30秒,slave-validity-factor参数为10,repl-ping-slave-period 为10秒,当从节点距离最近一次与主节点的交互时间大于310秒(30*10+10)时,该从节点不能进行故障转移。    一个过大的从节点有效因子(slave-validity-factor)会允许存储过旧数据的从节点进行故障转移,而一个过小的从节点有效因子将会妨碍集群选择从节点成为新的主节点。    所以合理的设置从节点有效因子很重要。    为了获得最大的可用性,可以将从节点有效因子(slave-validity-factor)赋值为0。也就是说,从节点忽略距离最近一次与主节点交互的时间段,则是直接点尝试发起故障转移。(但是这种策略下,这些从节点仍会根据offset的排名来推迟发起故障转移的时间)    从节点有效因子(slave-validity-factor)值为0是唯一可以保证网络分区消失后,集群仍继续工作的值。----- 5 从节点迁移屏蔽因子(cluster-migration-barrier)# Cluster slaves are able to migrate to orphaned masters, that are masters# that are left without working slaves. This improves the cluster ability# to resist to failures as otherwise an orphaned master can't be failed over# in case of failure if it has no working slaves.## Slaves migrate to orphaned masters only if there are still at least a# given number of other working slaves for their old master. This number# is the "migration barrier". A migration barrier of 1 means that a slave# will migrate only if there is at least 1 other working slave for its master# and so forth. It usually reflects the number of slaves you want for every# master in your cluster.## Default is 1 (slaves migrate only if their masters remain with at least# one slave). To disable migration just set it to a very large value.# A value of 0 can be set but is useful only for debugging and dangerous# in production.## cluster-migration-barrier 1    Redis集群支持将从节点迁移到孤立主节点(orphaned masters),没有可以工作从节点的主节点)。该功能减少了集群孤立主节点故障但没有可工作从节点进行故障转移的情况的发生。    从节点可以迁移到孤立主节点当且仅当原来的主节点的剩余可工作从节点个数大于等于指定的可工作从节点数。这个数称为从节点迁移屏蔽因子(migration barrier)。当迁移屏蔽因子设置为1时,当且仅当主节点拥有至少两个可工作的从节点才允许其中从节点迁移到孤立主节点(orphaned masters)。该因子通常用来表明使用者需要为集群中的主节点配置从节点个数。    默认迁移屏蔽因子是1(从节点可以执行迁移当前仅当其主节点在该节点迁移后仍保有至少一个从节点)。如果想关闭该功能,只需将该参数设置成一个极大值即可。    允许将迁移屏蔽因子置零。这种行为仅在调试时有用,且在生产环境中存在极大风险。-----  6 是否支持集群部分可用# By default Redis Cluster nodes stop accepting queries if they detect there# is at least an hash slot uncovered (no available node is serving it).# This way if the cluster is partially down (for example a range of hash slots# are no longer covered) all the cluster becomes, eventually, unavailable.# It automatically returns available as soon as all the slots are covered again.## However sometimes you want the subset of the cluster which is working,# to continue to accept queries for the part of the key space that is still# covered. In order to do so, just set the cluster-require-full-coverage# option to no.## cluster-require-full-coverage yes    默认情况下,Redis集群将停止接收客户端请求(停止服务)当集群检测到存在哈希槽没有对应负责的节点。也就是说,如果集群部分down(如有一部分哈希槽没有对应的节点),整个集群最终将会不可用。(集群信息传播遵循最终一致性)    当所有的槽都再次有对应负责的节点后,集群将会自动再次可用。    但是有时希望即使集群只有部分槽有对应的节点,集群也能继续接受客户端请求并处理对应的键空间。为了达到上述目的,将ecluster-require-full-coverage 设置为“no”即可。# In order to setup your cluster make sure to read the documentation# available at http://redis.io web site.    创建集群的指导文档在http://redis.io 网站可以获得。

13.show log

################################## SLOW LOG ###################################----- 1 命令执行超时上限# The Redis Slow Log is a system to log queries that exceeded a specified# execution time. The execution time does not include the I/O operations# like talking with the client, sending the reply and so forth,# but just the time needed to actually execute the command (this is the only# stage of command execution where the thread is blocked and can not serve# other requests in the meantime).## You can configure the slow log with two parameters: one tells Redis# what is the execution time, in microseconds, to exceed in order for the# command to get logged, and the other parameter is the length of the# slow log. When a new command is logged the oldest one is removed from the# queue of logged commands.# The following time is expressed in microseconds, so 1000000 is equivalent# to one second. Note that a negative number disables the slow log, while# a value of zero forces the logging of every command.slowlog-log-slower-than 10000    Redis慢日志系统用来记录执行时间较长的查询。这里的执行时间(“execution time”)不包括IO操作时间,如接收客户端的请求,返回请求结果等,而是实际执行命令的时间(此时线程处于阻塞状态,仅能执行该命令,不能同时处理其他请求)    可以使用两个参数配置慢日志:一个参数告知Redis执行时间超时阈值(单位是微秒,microseconds),这样一旦某个执行时间超过指定上限,将会被记录到慢日志中;另一个参数是慢日志的长度。慢日志使用环式结构存储超时命令。(当慢日志满后,新命令添加进去后,最老的命令将被踢出)    单位是微秒(microsecond,106微秒等于1秒)。当该值为负数时表示禁用slow log功能。当该值为零时,表示强制使用slow log记录每一条命令。    默认慢日志功能是开启的,slowlog-log-slower-than时间上限是104微秒。----- 2 慢日志长度# There is no limit to this length. Just be aware that it will consume memory.# You can reclaim memory used by the slow log with SLOWLOG RESET.slowlog-max-len 128    slow log保存在内存中,只要内存容量足够,可以随意设定慢日志长度。可以使用SLOWLOG RESET命令重新设置慢日志长度。

14.latency monitor

延迟监测配置:

################################ LATENCY MONITOR ##############################----- 1 设置操作延迟判定上限# The Redis latency monitoring subsystem samples different operations# at runtime in order to collect data related to possible sources of# latency of a Redis instance.## Via the LATENCY command this information is available to the user that can# print graphs and obtain reports.## The system only logs operations that were performed in a time equal or# greater than the amount of milliseconds specified via the# latency-monitor-threshold configuration directive. When its value is set# to zero, the latency monitor is turned off.## By default latency monitoring is disabled since it is mostly not needed# if you don't have latency issues, and collecting data has a performance# impact, that while very small, can be measured under big load. Latency# monitoring can easily be enabled at runtime using the command# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.latency-monitor-threshold 0    Redis 延迟监测自系统通过对执行期间的操作的检测来收集与延迟相关的数据。    通过使用LATENCY命令,Redis用户可以获得延迟相关的图形、报告等信息。    延迟系统只会记录大于等于设置的latency-monitor-threshold值的操作。当该值为零时,    则表明关闭latency monitor。    默认情况下,latency monitor功能是关闭的,因为大多数场景下并不需要该功能。    latency monitor可以在Redis运行时通过"CONFIG SET latency-monitor-threshold     <milliseconds>"启动。

15.事件通知配置

############################# EVENT NOTIFICATION ##############################----- 1 设置事件通知# Redis can notify Pub/Sub clients about events happening in the key space.# This feature is documented at http://redis.io/topics/notifications## For instance if keyspace events notification is enabled, and a client# performs a DEL operation on key "foo" stored in the Database 0, two# messages will be published via Pub/Sub:## PUBLISH __keyspace@0__:foo del# PUBLISH __keyevent@0__:del foo## It is possible to select the events that Redis will notify among a set# of classes. Every class is identified by a single character:##  K     Keyspace events, published with __keyspace@<db>__ prefix.#  E     Keyevent events, published with __keyevent@<db>__ prefix.#  g     Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...#  $     String commands#  l     List commands#  s     Set commands#  h     Hash commands#  z     Sorted set commands#  x     Expired events (events generated every time a key expires)#  e     Evicted events (events generated when a key is evicted for maxmemory)#  A     Alias for g$lshzxe, so that the "AKE" string means all the events.##  The "notify-keyspace-events" takes as argument a string that is composed#  of zero or multiple characters. The empty string means that notifications#  are disabled.##  Example: to enable list and generic events, from the point of view of the#           event name, use:##  notify-keyspace-events Elg##  Example 2: to get the stream of the expired keys subscribing to channel#             name __keyevent@0__:expired use:##  notify-keyspace-events Ex##  By default all notifications are disabled because most users don't need#  this feature and the feature has some overhead. Note that if you don't#  specify at least one of K or E, no events will be delivered.notify-keyspace-events ""#   Redis 可以通知那些已Pub/Sub客户端键空间发生的事件。#   该功能对应的文档是http://redis.io/topics/notifications#   例如,如果开启键空间通知功能且一个客户端对0号数据库上的“foo”key执行DEL操作,那么Redis将使用Pub/Sub发送两条消息:#       PUBLISH __keyspace@0__:foo del#       PUBLISH __keyevent@0__:del foo#   Redis对通知的事件进行了分类,每一类都使用唯一的字符标记:#   K 键空间(Key)通知,前缀为:__keyspace@<db>__ #   E 键事件(Event)通知,前缀为:__keyevent@<db>__ #   对于所有命令类型和非键事件,均使用小写字母表示,且没有前缀。#   g  一般命令(Generic commands),如DEL, EXPIRE, RENAME等#   $    字符串(String)命令#   l     列表(list)命令#   s     集合(set)命令#   h     哈希(hash)命令#   z     有序集合(sorted set)命令#   x     过期事件(过期键产生的事件)#   e     驱逐事件(因maxmemory而驱逐的事件)#   A     g$lshzxe等类型的别称(Alias),如此一来就可以使用"AKE"代表所有的事件类型#   notify-keyspace-events 可以指定多个字符组成的字符串或空串。其中空串代表关闭通知功能。#   例1:为了开启List事件和Genetic事件(从事件名称分类来说),可以使用如下设置:# notify-keyspace-events Elg#   例2:为了获取过期键的信息并发送到订阅的频道,即__keyevent@0__:expired use信息,可设置如下:# notify-keyspace-events Ex#   默认情况下,事件通知功能是关闭的,因为大多数用户并不需要这个功能且这个功能会带来额外的性能开销。#   注意,如果没有指定键空间(K)通知还是键事件(E)通知,那么任何事件通知都不会被传送。

16.高级配置:

############################### ADVANCED CONFIG ###############################---- 1 Hash类型# Hashes are encoded using a memory efficient data structure when they have a# small number of entries, and the biggest entry does not exceed a given# threshold. These thresholds can be configured using the following directives.hash-max-ziplist-entries 512hash-max-ziplist-value 64    Hash数据类型的底层实现有压缩链表(ziplist)和哈希表(hash)。当且仅当存储的数据量小于hash-max-ziplist-entries且节点占用的容量小于hash-max-ziplist-value时才使用小数据量存储高效的ziplist结构存储。否则,使用哈希结构存储。----- 2 List类型# Lists are also encoded in a special way to save a lot of space.# The number of entries allowed per internal list node can be specified# as a fixed maximum size or a maximum number of elements.# For a fixed maximum size, use -5 through -1, meaning:# -5: max size: 64 Kb  <-- not recommended for normal workloads# -4: max size: 32 Kb  <-- not recommended# -3: max size: 16 Kb  <-- probably not recommended# -2: max size: 8 Kb   <-- good# -1: max size: 4 Kb   <-- good# Positive numbers mean store up to _exactly_ that number of elements# per list node.# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),# but if your use case is unique, adjust the settings as necessary.list-max-ziplist-size -2    List类型也可以通过特殊的方式来节省空间。    每个内部list节点允许存储的entries数量可以指定为已修订最大数量或最大元素数。    如指定-5到-1,其含义是:        -5: max size: 64 Kb  <-- 对于普通的工作负载,不建议使用        -4: max size: 32 Kb  <-- 不建议使用        -3: max size: 16 Kb  <-- 有时不建议使用        -2: max size: 8 Kb   <-- good        -1: max size: 4 Kb   <-- good    整数代表每个list节点准确存储指定数量的elements    最高效的参数设置是-2 (8 Kb size) 或 -1 (4 Kb size)    但是,如果需求很特殊,则应根据需要调整参数:----- 3 List类型压缩深度设置# Lists may also be compressed.# Compress depth is the number of quicklist ziplist nodes from *each* side of# the list to *exclude* from compression.  The head and tail of the list# are always uncompressed for fast push/pop operations.  Settings are:# 0: disable all list compression# 1: depth 1 means "don't start compressing until after 1 node into the list,#    going from either the head or tail"#    So: [head]->node->node->...->node->[tail]#    [head], [tail] will always be uncompressed; inner nodes will compress.# 2: [head]->[next]->node->node->...->node->[prev]->[tail]#    2 here means: don't compress head or head->next or tail->prev or tail,#    but compress all nodes between them.# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]# etc.list-compress-depth 0    List可以实现压缩    压缩深度是划定quicklist、ziplist等list在压缩时的节点范围。为了进行快速的push/pop操作,不会对list的head和tail进行压缩,只会对中间节点进行压缩。参数设置如下:    0: 关闭list压缩功能    1: 深度为1表示只有当list添加一个节点(无论从head还是tail添加该节点)后才开始进行压缩。    所以对于[head]->node->node->...->node->[tail]    只有黑体部分加入才会执行压缩操作。    2: 深度为2    对于链表:[head]->[next]->node->node->...->node->[prev]->[tail]    不会压缩head 或 head->next 或 tail->prev 或 tail,而仅压缩剩余部分。    3: 深度为3    [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]----- 4 集合(intset)类型# Sets have a special encoding in just one case: when a set is composed# of just strings that happen to be integers in radix 10 in the range# of 64 bit signed integers.# The following configuration setting sets the limit in the size of the# set in order to use this special memory saving encoding.set-max-intset-entries 512    Set数据类型的底层实现默认是intSet,也可以是hash。    Set使用hash编码格式当且仅当字符串组成的set变成底数为10的整数,且其值范围在64位整数中。    下面的配置设置用来指定set可以使用特殊编码格式的阈值:----- 5 Sorted Set类型# Similarly to hashes and lists, sorted sets are also specially encoded in# order to save a lot of space. This encoding is only used when the length and# elements of a sorted set are below the following limits:zset-max-ziplist-entries 128zset-max-ziplist-value 64    Sorted Set默认使用ziplist实现,也可通过skiplist编码实现来节省空间。    当且仅当Sorted Set中元素值大于zset-max-ziplist-value、元素数量大于zset-max-ziplist-entries时,才使用skiplist实现Sorted Set。----- 6 HyperLogLog稀疏表示# HyperLogLog sparse representation bytes limit. The limit includes the# 16 bytes header. When an HyperLogLog using the sparse representation crosses# this limit, it is converted into the dense representation.## A value greater than 16000 is totally useless, since at that point the# dense representation is more memory efficient.## The suggested value is ~ 3000 in order to have the benefits of# the space efficient encoding without slowing down too much PFADD,# which is O(N) with the sparse encoding. The value can be raised to# ~ 10000 when CPU is not a concern, but space is, and the data set is# composed of many HyperLogLogs with cardinality in the 0 - 15000 range.hll-sparse-max-bytes 3000    HyperLogLog稀疏表示阈值。16位的header部分也在limit中。当使用稀疏表示的HyperLogLog存储的字节超过了指定的阈值,它将转变成稠密表示。    不建议使用大于16000的值。当小于16000时能够获得较高存储效率。    建议的值是3000,该值可以在较少PFADD(在执行稀疏编码时时间复杂度是O(N))操作执行的同时获得极高空间使用收益。当CPU问题无需考虑时,可将该值提升到10000,但其值不应超过 15000。----- 7 rehash处理# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in# order to help rehashing the main Redis hash table (the one mapping top-level# keys to values). The hash table implementation Redis uses (see dict.c)# performs a lazy rehashing: the more operation you run into a hash table# that is rehashing, the more rehashing "steps" are performed, so if the# server is idle the rehashing is never complete and some more memory is used# by the hash table.## The default is to use this millisecond 10 times every second in order to# actively rehash the main dictionaries, freeing memory when possible.## If unsure:# use "activerehashing no" if you have hard latency requirements and it is# not a good thing in your environment that Redis can reply from time to time# to queries with 2 milliseconds delay.## use "activerehashing yes" if you don't have such hard requirements but# want to free memory asap when possible.activerehashing yes#   激活的rehash会占用每100毫秒的1 millisecond的CPU时间来对Redis hash table(存储数据库的键值对的hash table)执行rehash。在Redis中hash table使用惰性rehash:在rehashing时,hash table中执行的操作越多,rehash执行的步骤也越多。所以当server很空闲时,rehash将很简单,hash table也会有更多的内存可以使用。#   为了在条件许可的情况下对hash table进行rehash,从而节省内存空间,默认情况下,rehash功能会每100毫秒中1 毫秒被调用一次。#   如果不确定:#       使用"activerehashing no" 如果当前应用环境很注重延迟、Redis仅允许2毫秒的延迟应答。#       使用"activerehashing yes" 如果当前应用环境不是太注重延迟且想要尽可能块的释放内存空间。----- 8 客户端输出缓冲区# The client output buffer limits can be used to force disconnection of clients# that are not reading data from the server fast enough for some reason (a# common reason is that a Pub/Sub client can't consume messages as fast as the# publisher can produce them).## The limit can be set differently for the three different classes of clients:## normal -> normal clients including MONITOR clients# slave  -> slave clients# pubsub -> clients subscribed to at least one pubsub channel or pattern## The syntax of every client-output-buffer-limit directive is the following:## client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>## A client is immediately disconnected once the hard limit is reached, or if# the soft limit is reached and remains reached for the specified number of# seconds (continuously).# So for instance if the hard limit is 32 megabytes and the soft limit is# 16 megabytes / 10 seconds, the client will get disconnected immediately# if the size of the output buffers reach 32 megabytes, but will also get# disconnected if the client reaches 16 megabytes and continuously overcomes# the limit for 10 seconds.## By default normal clients are not limited because they don't receive data# without asking (in a push way), but just after a request, so only# asynchronous clients may create a scenario where data is requested faster# than it can read.## Instead there is a default limit for pubsub and slave clients, since# subscribers and slaves receive data in a push fashion.## Both the hard or the soft limit can be disabled by setting them to zero.client-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60#   客户端输出缓冲区可以用来强制断开那些不能够快速读取服务器数据的客户端连接。(如在Pub/Sub模式中,客户端不能够快速的处理publisher发送过来的消息)#   客户端类型可以细分为三类:#       normal -> 普通客户端(包括MONITOR客户端)#       slave  -> 从节点客户端#       pubsub ->订阅至少一个pubsub通道或模式的客户端#   client-output-buffer-limit 设置的通用格式如下:#       client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>#   一旦hard limit达到,客户端将直接断开连接。如果soft limit 达到,客户端连接将会持续soft seconds 后才断开连接。#   例如,当hard limit 是 32 MB(megabytes)、soft limit 在10 秒内持续超过16MB,如果客户端输出缓冲区(clients output buffer)超过32 MB 或客户客户端输出缓冲区(clients output buffer)超过16MB,并在接下来的10秒都高于16MB,客户端连接将马上断开。#   默认情况下,不需对normal级别的clients进行约束因为这些客户端如果没有发起询问就不会接受数据。所以,只需对异步客户端进行约束因为异步客户端会出现请求速度大于read速度的情况。#   因为订阅者和从节点使用推的方式接受数据,所以需要对pubsub 客户端和slave客户端设置默认的客户端输出缓冲区约束。#   将hard limit 或 soft limit 置零表示关闭对应的功能。----- 9 Redis心跳频率# Redis calls an internal function to perform many background tasks, like# closing connections of clients in timeout, purging expired keys that are# never requested, and so forth.## Not all tasks are performed with the same frequency, but Redis checks for# tasks to perform according to the specified "hz" value.## By default "hz" is set to 10. Raising the value will use more CPU when# Redis is idle, but at the same time will make Redis more responsive when# there are many keys expiring at the same time, and timeouts may be# handled with more precision.## The range is between 1 and 500, however a value over 100 is usually not# a good idea. Most users should use the default of 10 and raise this up to# 100 only in environments where very low latency is required.hz 10#   Redis调用一个内部函数来执行后台任务,如在timeout时关闭客户端连接,清除从未被请求的过期键,等等。#   虽然并不是所有的tasks都使用同样的频率执行,但是Redis会根据指定的频率值来检测tasks的执行。#   默认设置的值为10,即每秒执行10次。在Redis处于空闲提升该值时,将会消耗更多的CPU。但是,提升该值也会使Redis更精确的处理超时问题,并检测到更多的过期键。#   该值设置范围是1到500。但是不建议将其设置大于100。大多数的用户建议使用默认的值(10),并根据应用环境的低延迟需求适当提升该值(峰值建议不要大于100)。----- 10 AOF重写与磁盘同步# When a child rewrites the AOF file, if the following option is enabled# the file will be fsync-ed every 32 MB of data generated. This is useful# in order to commit the file to the disk more incrementally and avoid# big latency spikes.aof-rewrite-incremental-fsync yes    子进程在执行重写AOF文件时,如果启动该功能,则数据每增长32MB就进行一次文件磁盘同步。该功能对加快文件同步到磁盘、避免大的延迟峰值有很大帮助。    默认该功能启动。格式如下:

参考
https://github.com/courage007/Redis-/blob/master/redis.cn.conf

原创粉丝点击