简述
看源码之前,当然先看工具的配置文件。Redis配置文件是英文注释,读起来晦涩难懂。那么今天就先来翻译以下Redis的配置文件。
redis.conf
# Redis configuration file example
# Redis 配置文件模版
# 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 5GB 4M等形式指定,如下所示
#
# 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时相同的含义
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis server but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
# Include表示有一个或多个其他配置文件。您如果有适用于所有Redis服务器的模版,但还需要自定义每个服务器的设置。
# Include文件可以包含include其他文件,非常建议你这么适用。
#
# 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"不会被"CONFIG REWRITE"命令重写,即使是admin或者redis哨兵。因为Redis会将最后读取到的值做为配置文件的值,
# 因此最好将include文件放在开头,避免运行时覆盖配置。
# CONFIG REWRITE:命令对启动中的Redis服务器所指定的redis.conf配置文件进行修改。
#
# 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
################################ GENERAL #####################################
# 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.
# 默认Redis不以守护进程的方式运行。如果需要开启修改为"yes"。
# 注意,redis开启守护进程时,会将pd写入到/var/run/redis.pid文件中。
#
daemonize no
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
# 以守护进程运行时,Redis默认会将pid写入/var/run/redis.pid文件中。您可以在这里指定pid写入的位置。
pidfile /var/run/redis.pid
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
# 接收指定端口的连接,默认是6379。如果端口是0,Redis将无法监听TCP的连接。
port 6379
# 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.
# 在每秒高请求的环境中,您需要提高backlog的配置,来避免客户端连接速度慢的问题。
# 注意,Linux内核会截断这个值,因此同时修改/proc/sys/net/core/somaxconn和tcp_max_syn_backlog的值,
# 来获得期待的效果。
# tcp-backlog:在TCP连接三次握手中,客户端首次向服务端发送的syn请求会被redis使用队列缓存起来,这个队列就是tcp-backlog,
# 当队列长度超过511时,会将其丢弃,客户端会认为网络丢包未收到响应而进行重传。
# tcp-backlog设置过大会导致队列存储请求过多占用大量内存,客户端很长时间无法接收到响应,触发超时重传。
# tcp-backlog设置过小会导致客户端丢包率频繁,重传频繁造成网络拥塞。
tcp-backlog 511
# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
# 默认Redis监听所有能够链接服务器的网络链接。可以使用"bind"配置指令只监听一个或多个接口,后面可以跟一个或多个ip地址。
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# 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 755
# Close the connection after a client is idle for N seconds (0 to disable)
# 客户端空闲N秒后链接关闭(0表示禁用)
timeout 0
# TCP keepalive.
# TCP保活
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
# 如果不是0,会使用SO_KEEPALIVE在没有数据传输的情况下向客户端发送TCP的确认。有如下两个好处:
#
# 1) Detect dead peers.
# 1)检测链接是否死掉。
# 2) Take the connection alive from the point of view of network
# equipment in the middle.
# 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上,指定的值(单位秒)是用于发送ACK的时间周期。
# 请注意,关闭链接需要两倍的时间周期。
# 在其他内核上,时间周期取决于内核配置。
#
# A reasonable value for this option is 60 seconds.
# 这里合理的值为60秒
tcp-keepalive 0
# Specify the server verbosity level.
# 指定服务器详细级别。
# This can be one of:
# 以下可选情况之一:
# debug (a lot of information, useful for development/testing)
# debug(大量新秀,针对开发/测试)
# verbose (many rarely useful info, but not a mess like the debug level)
# verbose(大量的有用信息,但不像debug级别那样混乱)
# notice (moderately verbose, what you want in production probably)
# notice(一般的信息,可以在生产中使用)
# warning (only very important / critical messages are logged)
# warning(只记录非常重要和关键的消息)
loglevel notice
# 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/null
# 指定日志名称。也可以使用空字符串让Redis日志进行标准输出。
# 请注意,如果使用标准日志输出,且是守护进程,则日志会输出到/dev/null
logfile ""
# 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"设置为yes,并根据需要设置其他ssylog参数。
#
# syslog-enabled no
# Specify the syslog identity.
# 指定系统日志标记。
#
# syslog-ident redis
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# 指定系统日志工具。必须是USER或者LOCAL0-LOCAL7。
#
# syslog-facility local0
# 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'-1
# 设置数据库编号。默认数据库是DB 0,您可以使用SELECT <bdid>针对每个链接选择不同的数据库,其中
# dbid的编号是在0和'databases'设置值之间。
#
databases 16
################################ SNAPSHOTTING ################################
#
# 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.
# 如果给定的秒数和对数据库的修改操作数两个条件同时满足,则都会触发保存数据库。
#
# In the example below the behaviour will be to save:
# 下面的示例中会触发保存:
#
# after 900 sec (15 min) if at least 1 key changed
# 900秒(15分钟)后,如果有1个key被修改
#
# after 300 sec (5 min) if at least 10 keys changed
# 300秒(5分钟)后,如果有10个key被修改
#
# after 60 sec if at least 10000 keys changed
# 60秒后,如果有10000个key被修改
#
# Note: you can disable saving at all commenting all the "save" lines.
#
# 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指令,删除以前的保存点,如下所示:
# save ""
save 900 1
save 300 10
save 60 10000
# 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快照(至少一个保存点),并且最新的保存失败,Redis将停止接收写入。
# 这会让用户意识到数据没有正确的保存在磁盘上(这是非常强硬的),否则没有正确的保存磁盘没有被人注意到,这将会发生一些灾难;
# If the background saving process will start working again Redis will
# automatically allow writes again.
# 如果保存过程中Redis再次运行,RDB将会允许再次写入。
# 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.
# 如果您已经设置了对Redis服务器和持久化的正确性监视,则需要禁用此功能来保证即使在磁盘、权限等方面出现问题时,Redis仍然能正常工作。
stop-writes-on-bgsave-error yes
# 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.
# rdb databases何时使用LZF压缩存储字符串对象?
# 默认是值是"yes",因为这总是成功的。
# 如果您想要保留一些CPU,请将其设置为"no",但是数据集可能会更大,即使有压缩空间的值。
rdbcompression yes
# 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 5版本之后CRC64校验被放置在文件末尾。
# 这种格式更能抵抗损坏,但保存和加载RDB文件时,性能会受到影响(约10%),因此您可以禁用它来获得性能最大化。
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
# 禁用检查文件会校验RDB文件是否存储检查值,这将告诉加载代码跳过检查。
rdbchecksum yes
# The filename where to dump the DB
# 存储数据库的文件名称。
dbfilename dump.rdb
# The working directory.
# 工作目录。
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# 使用上面"dbfilename"配置的文件,将会写入到此目录。
# The Append Only File will also be created inside this directory.
# aof文件也将在此目录中创建
# Note that you must specify a directory here, not a file name.
# 请注意,您必须在此处指定目录,而不是名称。
dir ./
################################# REPLICATION #################################
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
# 主从复制。使用slaveof让Redis实例复制另一台Redis服务。
# 请注意,配置的是本地从机,因此可以将从机间的不同保存,或者监听另一个端口,等等。
# slaveof <masterip> <masterport>
# 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>
# 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
# 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.
# 因此Redis2.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.
# 注意:只读从机设计不允许暴露在不受信任的客户端上。
# 它只是一个防止实例误用的保护层。
# 默认情况下,只读从机仍会响应所有命令,如CONFIG、DEBUG等。
# 您可以使用"rename-command"来隐藏所有的管理和危险的命令,从而提高只读丛机的安全性。
slave-read-only yes
# 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.
# 从服务器以设定的间隔时间向服务器发送ping。可以"repl_ping_slave_period"配置修改间隔时间。默认间隔是10秒。
# repl-ping-slave-period 10
# 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-ping-slave-period"的值,否则每次主设备从设备之间的同步的通信数量较少时都会被检测到超时。
# repl-timeout 60
# 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.
# 如果选择"yes",Redis将使用较少的TCP数据包和较少的网络贷款向从服务器发送数据。
# 但这会明显增加从机的数据延迟,如果使用linux内核的默认配置,延迟能达到40毫秒。
# 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.
# 如果您选择"no",从机明显的数据延迟将减少,但主从复制将使用更多网络带宽。
# 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.
# 默认情况下我们会优化低延迟,但在流量非常高的情况下,或者主节点和从节点数据之间有很大差异时,将这项选择为"yes"是个好的方案。
repl-disable-tcp-nodelay no
# 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.
# 设置复制集的backlog大小。这个backlog会缓存,从机断开后一段时间后的累积数据,因此当从机想要重新连接时,
# 通常不需要完全重新同步,只需要部分的重新同步就足够了,此时只传递断开连接时从机丢失的部分数据。
# The biggest the replication backlog, the longer the time the slave can be
# disconnected and later be able to perform a partial resynchronization.
# backlog值越大,则从机器可以断开的时间就越长,重新连接之后执行部分重新同步。
# The backlog is only allocated once there is at least a slave connected.
# 至少有一个从机连接时,才会分配backlog空间。
# repl-backlog-size 1mb
# 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.
# 主机器不再连接从机器一段时间后,backlog空间将被释放。以下配置是最后一次从机器断开连接时到开始释放积压的缓冲区所需要的时间秒数。
# A value of 0 means to never release the backlog.
# 这个值为0表示,永远不释放backlog。
# repl-backlog-ttl 3600
# 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.
# 从属优先级是Redis中INFO命令中输出的一个整数。Redis Sentinel使用它来选择一个从机器,以便主机器故障时,将从机器升级为主机器。
# 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.
# 优先级分数较低的从机器被认为更适合升级,例如有三个优先级分数为10,100,25的从机器,Sentinel将选择优先级分数为10的从机,因为这是延迟最低的。
# 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.
# 然而,特殊的优先级分数为0的从机器将无法担任主机器的角色,因此Redis Sentinel将永远不会选择优先级分数为0的从机器进行升级。
# By default the priority is 100.
# 默认情况下,优先级为100。
slave-priority 100
# 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.
# 如果连接的从机器少于N个,且从机器延迟时间必须小于或等于M秒,否则主机器将停止接受写入。
# The N slaves need to be in "online" state.
# 这个N表示从机器需要处于"在线"状态。
# 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.
# 这个延迟秒数,必须<=指定的时间,是根据从机器接收最后一次ping计算得出,ping通常每秒发送一次。
# This option does not GUARANTEES 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:
# 如下例,要求至少3个从机器,且延迟时间<=10秒:
# min-slaves-to-write 3
# min-slaves-max-lag 10
#
# Setting one or the other to 0 disables the feature.
# 将一个或另一个设置为0,将禁用该功能。
# By default min-slaves-to-write is set to 0 (feature disabled) and
# min-slaves-max-lag is set to 10.
# 默认情况下,min-slaves-to-write是0(功能已经禁用),min-slaves-max-lag是10。
################################## SECURITY ###################################
# 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.
# 要求客户端在发送其它命令之前发送AUTH <PASSWORD>。在不信任他人能够访问运行中的redis服务器,这将很实用。
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 为了向后兼容,并且大多数人不需要auth(例如,他们运行在自己的服务器上)。
# 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.
# 警告:由于Redis速度非常快,外部用户可以每秒150K密码进行尝试。这意味着您应该使用非常复杂的密码,否则很容易被破解。
# requirepass foobared
# 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.
# 可以在公共(共享)环境中更改危险命令。例如,CONFIG命令可以被重命名为难以猜测的内容,它仍然可以用于内部的工具找到,
# 但普通的客户端不可用。
# 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.
# 请注意,更改记录AOF文件或数据传输从服务器的命令,可能会导致问题。
################################### LIMITS ####################################
# 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).
# 设置同时连接客户端的最大数量。默认情况下此限制为10000个客户端,
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.然而Redis服务器无法对进程允许的最大限制进行配置,因此允许的最大客户端数为当前
# 允许打开的文件数减去32(由于Redis服务器预留一些供内部使用的文件描述符)。
# maxclients 10000
# 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).
# 不要使用超过指定大小的内存。
# 当达到内存限制时,Redis将根据所选的淘汰策略尝试删除key(请查阅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.
# 如果Redis无法根据策略删除key,或者策略设置为"noeviction",Redis将对使用更多内存命令
# 进行错误回复,如SET、LPUSH等等,并继续对只读命令进行回复,如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).
# 当Redis作为LRU缓存或为实例设置固定内存限制时,此选项通常很有用(使用"noeviction"策略)。
#
# 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.
# 警告:如果连接到的从机器打开maxmemory设置,则从机器的使用内存中减去为从机器提供数据的缓冲区大小,
# 这样网络问题/重新同步将不会触发key循环淘汰,反之,从机器的输出缓冲区满了会触发更多的key淘汰删除,
# 以此类推,直到数据库完全被清空。
#
# 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,以便系统上有一些可用RAM用于从机器输出缓冲区
#(但如果策略为"noeviction",则不需要这么做)。
#
# maxmemory <bytes>
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
# MAXMEMORY 策略:当内存达到maxmemory时,Redis将从如何选择性删除。您可以从以下五种中进行选择:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# volatile-lru -> 使用LRU算法删除有过期时间的key
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# allkeys-lru -> 使用LRU算法删除任意的key
# volatile-random -> remove a random key with an expire set
# volatile-random -> 随机删除带有过期时间的key
# allkeys-random -> remove a random key, any key
# allkeys-random -> 随机删除key,任意key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# volatile-ttl -> 删除即将过期的key(类似TTL)
# noeviction -> don't expire at all, just return an error on write operations
# noeviction -> 从不过期,可能返回一个写错误。
#
# Note: with any of the above policies, Redis will return an error on write
# operations, when there are not suitable keys for eviction.
# 注意:对于上述策略,当没有合适的键淘汰时,Redis将在写入操作时返回错误。
#
# At the date of writing this 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
# 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.
# LRU和TTL不是精确算法,而是近似算法(为了节省内存),因此可以调整来提高速度或精度。默认情况下,
# Redis将检查5个key并选择最近使用的key,您可以使用以下配置更改样本大小。
#
# 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.
# 默认值为5会产生足够好的结果。10非常接近真实的LRU,但需要更多的CPU。3很快,但不是很准确。
#
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
# 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).
# 默认情况下,Redis将数据异步转存储到磁盘上。这种模式在许多应用程序中已经足够好了,但Redis进程出现问题
# 或断电可能会导致几分钟的写丢失(取决于配置的保存点)。
#
# 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.
# 这个Append Only File是另一种持久化模式,提供了更好的持久化。例如,默认的数据fsync策略(请参阅
# 后面的配置文件部分),Redis可能会在服务器断电之类的重大事故中丢失一秒的写入,或者在Redis进程本身
# 发生故障时丢失一次写入,但操作系统仍然能够正常运行。
#
# 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.
# AOF和RDB持久化可以同时启用,不会出现问题。如果Redis启动时启用AOF,Redis将加载AOF,这文件具有
# 更好的持久化保存。
#
# Please check http://redis.io/topics/persistence for more information.
# 请求查看了解更多信息http://redis.io/topics/persistence。
appendonly no
# The name of the append only file (default: "appendonly.aof")
# append only file名称(默认"appendonly.aof")
appendfilename "appendonly.aof"
# The fsync() call tells the Operating System to actually write data on disk
# instead to wait 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.
# fsync()调用告诉操作系统进行磁盘写入,而不是在输出缓冲区等待更多的数据。有些操作系统会真正的刷新磁盘,
# 而另一些操作系统则会尽快刷盘。
#
# Redis supports three different modes:
# Redis支持的三种模式:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# no:不执行fsync,让操作系统在需要时刷新数据即可,更快。
# always: fsync after every write to the append only log . Slow, Safest.
# always:每次写入追加日志后进行fsync,很慢,最安全。
# everysec: fsync only one time every second. Compromise.
# everysec:fsync操作每秒进行一次。妥协(折中)。
#
# 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.
# 默认值是"everysec",因为这通常是速度和安全之间的最佳折中。这是由您来决定的,如果可以放宽到"no",
# 这会让操作系统在它想要的时候刷新缓冲区,来获得更好的性能(但如果您能容忍一些数据丢失的话,考虑使用
# 快照的方式持久化),或者相反,使用"always"这是非常慢的,但比"everysec"安全一些。
#
# More details please check the following article:
# 更多详细信息请查看以下文章
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".
# 如果不确定,请使用"everysec"。
# appendfsync always
appendfsync everysec
# appendfsync no
# 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.
# 当AOF fsync策略为always或者everysec,并后台保存进程(后台保存或AOF重写)正在对磁盘执行大量I/O时,
# 在某些配置的linux中,Redis可能会在fsync()调用阻塞太长时间。请注意,目前还没有解决此问题的方案,因为
# 即使在不同的线程中执行fsync,也会阻止我们调用同步写入。
#
# 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.
# 为了缓解此问题,可以使用以下选项,以防止BGSAVE或BGREWRITEAOF时主进程中调用fsync()。
#
#
# 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).
# 这意味着另一个子线程在存储时,Redis持久化与"appendfsync none"相同,实际上这意味着在最坏的
# 情况下,可能会丢失多大30秒的日志(使用默认linux配置)。
#
# 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.
# 如果您由延迟问题,请将此项设置为"yes"。否则请保留"no",从持久化角度来看,这是最安全的选择。
no-appendfsync-on-rewrite no
# 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.
# 自动重写append only file。
# 当AOF日志大小达到指定大小时,Redis能够隐性的调用BGREWRITEAOF自动重写日志文件。
#
# 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).
# 它的工作原理是:Redis会记录最后一次写入(如果重新启动为发生写入,则使用启动时AOF)。
#
# 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.
# 将此基本大小与当前大小进行比较。如果当前大小大于指定的百分比,则会触发重写。此外,您还需要为
# 重写AOF文件指定最小大小,这对于避免重写AOF文件非常有用,即使达到增加的百分比,但仍然非常小。
#
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.
# 指定0的百分比禁用AOF重写功能。
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
################################ LUA SCRIPTING ###############################
# Max execution time of a Lua script in milliseconds.
# Lua脚本的最大执行时间毫秒。
#
# 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.
# 如果达到最大执行时间,Redis脚本将在允许的最大执行时间后仍然执行,并开始回复带有错误的查询。
#
# When a long running script exceed 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 commands was
# already issue by the script but the user don't want to wait for the natural
# termination of the script.
# 当长时间运行的脚本超过最大执行m命令的时间时,只有SCRIPT KILL和SHUTDOWN NOSAVE命令可用。
# 第一个命令可用于停止当前尚未调用写入命令的脚本。第二个命令是在脚本已经发出写入命令但用户不想
# 等待脚本自然终止的情况下关闭服务器的唯一方法。
#
# Set it to 0 or a negative value for unlimited execution without warnings.
# 将其设置为0,便是在没有警告的情况下无限执行。
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
#
# 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:
# 普通Redis实例不能作为Redis集群的一部分。只有作为集群节点启动才能成功节点。要将Redis实例作为
# 集群节点启动,请启用集群支持取消以下注释:
#
# cluster-enabled yes
# 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 does not have
# overlapping cluster configuration file names.
# 每个集群节点都有一个集群配置文件。此文件不可手动编辑。它有Redis节点创建和更新。每个Redis集群
# 节点都需要不同的集群配置文件。确保在同一系统中运行的实例没有重叠的集群配置文件名。
#
# cluster-config-file nodes-6379.conf
# 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
# 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.
# 只有当旧主机还有一定数量的其他从机器时,从机器才会迁移到孤立主机那里。这个数字就是"migration barrier"。
# 迁移屏障为1意味着只有当主设备至少有一个其他从机器工作时,从机器才会迁移,以此类推。它通常反应集群中每个
# 节点所需要的从节点数量。
#
# 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.
# 默认值为1(当其主机器至少有一台从机器时,从机器才会迁移)。要禁用迁移,只需要将其设置为非常大的值。
# 可以设置成0,但该值仅对debug有用,并且生产中很危险。
#
# cluster-migration-barrier 1
# In order to setup your cluster make sure to read the documentation
# available at http://redis.io web site.
# 要设置集群,请务必阅读以下站点提供的文档。
# http://redis.io
################################## SLOW LOG ###################################
# 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).
# Redis慢日志系统,用于记录超过指定执行时间的查询。执行时间不包括I/O操作,例如客户端会话、发送回复等,
# 而只包含实际执行命令所需要的时间(这是命令执行的唯一阶段,线程被阻塞,同时不同服务于其他请求)。
#
# 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.
# 您可以使用两个参数配置慢日志:一个参数告诉Redis为了记录命令要超过的执行时间微妙,另一个参数是慢
# 速日志的长度。记录新命令时,将从记录的命令队列中删除最旧的命令。
# 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.
# 以下时间单位为微妙,因此1000000相当于1秒。请注意,负数将禁用慢日志,而0将强制记录每个命令。
slowlog-log-slower-than 10000
# 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 RESET回收慢日志内存。
slowlog-max-len 128
############################# Event notification ##############################
# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at http://redis.io/topics/keyspace-events
# Redis可以将key空间中发生的事件通知客户端(发布/订阅)。
# 此功能详细:http://redis.io/topics/keyspace-events
#
# 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:
# 例如:如果启用了key空间事件通知,并且客户端对数据库0中存储的key执行了DEL操作,将通过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:
# 可以在一组类中选择Redis将通知的事件。每个类都由一个字符标识:
#
# 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
# by zero or multiple characters. The empty string means that notifications
# are disabled at all.
# "notify-keyspace-events"将有0个或多个字符串作为参数。空字符串表示完全禁用通知。
#
# Example: to enable list and generic events, from the point of view of the
# event name, use:
# 例如:要启用list和常规命令事件,从事件名称的角度来看,请使用:
#
# notify-keyspace-events Elg
#
# Example 2: to get the stream of the expired keys subscribing to channel
# name __keyevent@0__:expired use:
# 例子2:获取订阅通道名称的过期key
#
# 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.
# 默认情况下所有通知都被禁用,因为大多数用户不需要此功能,和此功能带来的一些开销。请注意,如果
# 没有指定K或者E中的至少一个,则不会传递任何事件。
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
# 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 512
hash-max-ziplist-value 64
# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
# you are under the following limits:
# 与散列类似,小列表也以特殊的方式编码,来节省大量的空间。当处于以下限制条件时,才使用特殊限制:
list-max-ziplist-entries 512
list-max-ziplist-value 64
# Sets have a special encoding in just one case: when a set is composed
# of just strings that happens 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
# 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:
# 与散列和列表类似,sorted也经过特殊的编码节省大量的空间。此编码仅在sorted长度和元素低于以下限制时使用:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
# 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
# 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
# active rehashing 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 form 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
# 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
# slave -> slave clients and MONITOR 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 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# 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 accordingly 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
# 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
网友评论