redis.conf全翻譯(版本redis5)

it技術圈 發佈 2024-05-09T08:27:04.930767+00:00

花了點時間把redis.conf從頭看了一遍,想著那就順便全部翻譯一下,也許對別人也有用。水平有限,有錯誤請指出。

花了點時間把redis.conf從頭看了一遍,想著那就順便全部翻譯一下,也許對別人也有用
水平有限,有錯誤請指出


# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
# 要使用redis的這個配置文件,配置文件路徑必須是redis-server的第一個參數
#
# ./redis-server /path/to/redis.conf

# 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
# 
# 注意單位的區別,不帶b的是1000進位
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
# 單位是大小寫不敏感的

################################## 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.
# 可以引入一個或多個配置文件。
# 如果你有一個標準模板,然後只有少量參數需要進行調整的情況下,這個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.
#
# 注意:引入的文件不能被"CONFIG REWRITE"命令重寫。
# 因為redis對於同一個配置總是使用最後一個配置參數。
# 所以你最好將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

################################## MODULES #####################################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
# redis4開始支持自定義擴展模塊
# 在啟動時加載
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so

################################## NETWORK #####################################

# 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.
# 如果沒有配置bind參數,redis將監聽本機所有網卡的連接
# 可以通過配置bind參數來限定只監聽某個或某幾個網卡的連接
# 多說一句,bind後面配的是本機ip,不是外部要訪問redis的哪些機器的ip
# 所以通常的配置是bind 本機對外ip 127.0.0.1
# 這樣允許外部通過ip訪問redis,也允許本機訪問redis
# 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 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
# 警告,如果允許redis的伺服器直接連到了外網,監聽所有是很危險的
# 所以默認情況下,我們沒有注釋掉bind 127.0.0.1
# 這樣就只允許本機的連接
# 
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# 如果你確定要開放給所有的連接,只需要注釋掉這行
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

# 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被訪問和利用
#
# 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.
#
# 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.
# 如果保護模式打開(默認就是)
# 並且沒有配置bind限定可連接的ip
# 也沒有配置密碼
# 那麼這個redis將只允許本機訪問
# 
# 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

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a tcp socket.
# redis的監聽埠
# 如果設置為0,將不會監聽tcp的socket
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.
# tcp的連接隊列長度
# linux內核為每個TCP伺服器程序維護兩條backlog隊列,一條是TCP層的未連接隊列,一條是應用層的已連接隊列,分別對應net.ipv4.tcp_max_syn_backlog和net.core.somaxconn兩個內核參數。
# 在高並發場景下,需要更高的隊列長度,以避免客戶端連接慢的問題
# 注意linux內核會截斷這個值到/proc/sys/net/core/somaxconn配置的值
# 也就是二者取小。所以別忘了修改somaxconn
tcp-backlog 511

# 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,客戶端可以通過這個socket文件來連接
# 如果沒指定,redis就不會監聽任何socket連接
# 客戶端連接方式舉例:redis-cli -s /tmp/redis.sock
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
# 如果timeout時間內,客戶端和redis服務端沒有數據交互(客戶端不向redis發送數據),redis將斷開連接
# 0表示永不斷開
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
# TCP探活
# 如果是非0值,使用linux的心跳機制SO_KEEPALIVE來探測連接
# 這個數值是客戶端發送的最後一個數據包與redis發送的第一個保活探測報文之間的時間間隔。單位是秒
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# 在linux系統,這個值會覆蓋掉linux默認tcp_keepalive_time的值(7200秒)。
# Note that to close the connection the double of the time is needed.
# 注意關閉連接需要2倍的時間
# On other kernels the period depends on the kernel configuration.
# 在其他系統該配置不生效,比如mac系統,這個探測間隔就是內核參數的配置
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300

################################# 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默認不是後台運行
# 當設置後台運行後,redis將寫一個pid文件在/var/run/redis.pid
daemonize no

# 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.
# 如果需要對redis服務進行託管(upstart模式 或systemd模式),可以通過該選項來配置Redis。
# 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回復

supervised no

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# 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".
#
# 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.
# 如果指定了pid文件,redis在啟動時會寫這個文件,在redis退出時刪除 
# 如果沒有指定pid文件,並且不是用守護進行啟動redis,那麼不會生成pid文件
# 如果使用守護進程啟動redis,並且沒有指定pid文件,默認生成"/var/run/redis.pid"
# 創建pid文件是一件盡力而為的事,如果創建失敗,redis依然會正常啟動和運行
#
pidfile /var/run/redis_6379.pid

# 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)
# 日誌級別
# debug 大量信息,用於開發和測試
# verbose 會有很多少見的有用信息
# notice 適量信息,適合用於生產環境
# waning 只有嚴重的信息
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
# 配置日誌文件
# 空字符串會輸出到標準輸出中
# 如果配置成空字符串,又用後台啟動,那麼日誌就到/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去記錄redis的日誌
# syslog-enabled no

# Specify the syslog identity.
# 使用syslog去記錄redis日誌的標識
# syslog-ident redis

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# 指定使用syslog的哪個設施來記錄redis日誌;默認是local0
# 在syslog中會有定義local0把日誌記錄到某個文件中
# 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
# 設置資料庫的數量,默認是16個
# 客戶端連上redis時默認使用的是DB 0
# 可以使用select指令切換資料庫
databases 16

# By default Redis shows an ASCII art logo only when started to log to the
# standard output and if the standard output is a TTY. Basically this means
# that normally a logo is displayed only in interactive sessions.
#
# However it is possible to force the pre-4.0 behavior and always show a
# ASCII art logo in startup logs by setting the following option to yes.
always-show-logo yes

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   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
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "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 (多少秒) (多少寫操作)
# 含義是在多少秒內至少發生了多少次寫操作,就進行一次數據落盤(寫rdb文件)
# 這個多少秒我的理解是距離上次落盤操作後的時間
# 即上一次進行bgsave保存RDB文件後的時間
# save可以配置多條,他們直接是或的關係,只要有一條滿足就進行落盤
# 下面的配置的含義是:
# 900秒內至少進行了一次寫操作
# 300秒內至少進行了10次寫操作
# 60秒內至少進行了10000次寫操作
# 注意,如果將這些save全部注釋掉,也就禁止了自動落盤
# 如果配置了 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快照(也就是只要有一個save配置),並且最近的快照操作失敗的時候,redis會停止寫服務
# 這樣可以讓用戶明確的意識到數據持久化有問題了
# If the background saving process will start working again Redis will
# automatically allow writes again.
# 如果後台落盤進程又好了,那麼redis的寫服務會自動恢復
#
# 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不可用,在生產環境影響太大。
# 我一般是關掉的
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時開啟壓縮
# 開啟壓縮會使用更多cpu,禁用壓縮rdb文件會比較大
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文件開啟校驗,會在rdb文件的最後加上crc64的校驗和。
# 這可以保護rdb文件
# 但是在保存和加載rdb文件時會有10%左右的性能損耗
# 如果是為了追求最大性能,可以關閉
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
# 如果關閉rdbchecksum,在rdb文件中的checksum就是0,redis在加載rdb文件時如果發現checksum是0,就會跳過校驗
rdbchecksum yes

# The filename where to dump the DB
# rdb文件名
dbfilename dump.rdb

# 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.
# 工作目錄,
# 默認是當前目錄,如果用redis-server啟動就是執行啟動命令的目錄。如果用systemctl啟動就是/
# 這個目錄就是上面dump.rdb的存儲目錄。所以要注意啟動用戶必須要有寫權限
# aof文件也會放在這
dir ./

################################# REPLICATION #################################

# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
#   +------------------+      +---------------+
#   |      Master      | ---> |    Replica    |
#   | (receive writes) |      |  (exact copy) |
#   +------------------+      +---------------+
#
# 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 replicas.
# 2) Redis replicas 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 replicas automatically try to reconnect to masters
#    and resynchronize with them.
#
# 主從複製。從節點使用replicaof主節點
# 1)redis的主從複製時異步的
# replicaof <masterip> <masterport>

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the replica to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
# 如果master加了密碼。那麼主從同步的從節點也必須配置上master的密碼
# masterauth <master-password>

# When a replica loses its connection with the master, or when the replication
# is still in progress, the replica can act in two different ways:
# 當從與主失去連接,或者同步進程還在執行中是,備節點能否響應業務請求
# 1) if replica-serve-stale-data is set to 'yes' (the default) the replica 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)設置為yes,可以響應業務請求。只是可能有過期數據
# 2) if replica-serve-stale-data is set to 'no' the replica will reply with
#    an error "SYNC with master in progress" to all the kind of commands
#    but to INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG,
#    SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB,
#    COMMAND, POST, HOST: and LATENCY.
# 2)設置為no,備節點會返回 "SYNC with master in progress" 錯誤。
#     但是INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG,
#    SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB,
#    COMMAND, POST, HOST: and LATENCY.這些命令可以響應
replica-serve-stale-data yes

# You can configure a replica instance to accept writes or not. Writing against
# a replica instance may be useful to store some ephemeral data (because data
# written on a replica 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 replicas are read-only.
# 從redis2.6開始,默認是只讀
# Note: read only replicas 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 replica 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 replicas using 'rename-command' to shadow all the
# administrative / dangerous commands.
# 注意,就算是只讀的從節點也不要暴露給不信任的客戶端
# 因為雖然只讀了,但是仍然可以執行管理命令
# 建議使用'rename-command'重命名掉危險的命令
replica-read-only yes

# Replication SYNC strategy: disk or socket.
# 主從同步策略:disk模式和socket模式
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
# 警告:socket模式目前還是實驗狀態
# New replicas and reconnecting replicas 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 replicas.
# The transmission can happen in two different ways:
# 新的從節點或者重新連上的但有不能進行增量同步的從節點,就會進行全量同步
# 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 replicas incrementally.
# disk方式,主節點先把rdb文件寫到硬碟,然後再啟動一個進程傳給從節點
# 2) Diskless: The Redis master creates a new process that directly writes the
#              RDB file to replica sockets, without touching the disk at all.
# Diskless方式,主節點直接將rdb寫道從節點的socket,不需要寫硬碟的動作
# With disk-backed replication, while the RDB file is generated, more replicas
# 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 replicas arriving will be queued and a new transfer
# will start when the current one terminates.
#
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple replicas
# will arrive and the transfer can be parallelized.
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
# 當硬碟很慢而網絡快時,diskless方式會更好
repl-diskless-sync no

# 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 replicas.
# 當啟用上面的diskless方式同步時,要配置一個等待時間以便並行傳遞rdb文件
# This is important since once the transfer starts, it is not possible to serve
# new replicas arriving, that will be queued for the next RDB transfer, so the server
# waits a delay in order to let more replicas arrive.
# 因為一旦傳遞開始,以後到來的從節點的同步請求只能排隊等這次傳遞結束
# 所以要配置一個等待時間,等更多的從節點的同步請求,以便並行傳遞rdb文件
# 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.
# 默認5秒,設置為0就不等待,立刻開始
repl-diskless-sync-delay 5

# Replicas send PINGs to server in a predefined interval. It's possible to change
# this interval with the repl_ping_replica_period option. The default value is 10
# seconds.
# 從節點周期性的向主節點發送ping包,即心跳間隔
# repl-ping-replica-period 10

# The following option sets the replication timeout for:
# 複製超時時間設置
# 1) Bulk transfer I/O during SYNC, from the point of view of replica.
# 2) Master timeout from the point of view of replicas (data, pings).
# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).
# 1.從節點的角度,沒有收到master SYNC傳輸的rdb數據
# 2.從節點的角度,沒有收到master的數據或者ping包
# 3.主節點的角度,沒有收到從節點的ack確認
# 當redis檢測到repl-timeout超時(默認值60s),將會關閉主從之間的連接,redis slave發起重新建立主從連接的請求。
# It is important to make sure that this value is greater than the value
# specified for repl-ping-replica-period otherwise a timeout will be detected
# every time there is low traffic between the master and the replica.
# 這個值應該比上面的心跳間隔repl-ping-replica-period大
# repl-timeout 60

# Disable TCP_NODELAY on the replica socket after SYNC?
# 是否再發送SYNC之後,該socket禁用TCP_NODELAY
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to replicas. But this can add a delay for
# the data to appear on the replica side, up to 40 milliseconds with
# Linux kernels using a default configuration.
# 設置為yes,就是禁用掉TCP_NODELAY,即可以稍微delay一下再發送,
# 這樣可以攢多一點數據,也就是可以用更少的tcp包了,
# 但是這會增大主從之間的同步延遲
# linux內核的delay時間默認是40毫秒
#
# If you select "no" the delay for data to appear on the replica 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 replicas are many hops away, turning this to "yes" may
# be a good idea.
# 默認是no,因為我們通常希望主從同步儘量快
# 但是如果網絡很擁堵或者主從之間需要很多跳,改成yes,減少包的數量可能會比較好
repl-disable-tcp-nodelay no

# Set the replication backlog size. The backlog is a buffer that accumulates
# replica data when replicas are disconnected for some time, so that when a replica
# wants to reconnect again, often a full resync is not needed, but a partial
# resync is enough, just passing the portion of data the replica missed while
# disconnected.
# 複製緩衝區的大小。
# 當從節點斷聯時,主從複製的數據先緩存到這個複製緩衝區。
# 等從節點重新連上,通常不需要全量複製。只需要進行增量複製,即把複製緩衝區的數據同步即可
# 
# The bigger the replication backlog, the longer the time the replica can be
# disconnected and later be able to perform a partial resynchronization.
# 所以,複製緩衝區越大,從節點允許的斷連時間就越長(允許進行增加複製的時間)
# The backlog is only allocated once there is at least a replica connected.
# 複製緩存區是在只要有一個從節點連上的時候才會分配內存。
# 默認是1mb
#
# repl-backlog-size 1mb

# After a master has no longer connected replicas 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 replica disconnected, for
# the backlog buffer to be freed.
# 當master上沒有任何從節點的連接,在超出一定時間後,就會釋放複製緩衝器
# 這個時間從最後一個從節點斷連開始算
# 
# Note that replicas never free the backlog for timeout, since they may be
# promoted to masters later, and should be able to correctly "partially
# resynchronize" with the replicas: hence they should always accumulate backlog.
# 從節點永遠不會因為超時而釋放backlog,因為他隨時可能被選為master
#
# A value of 0 means to never release the backlog.
# 0標識從不釋放backlog
# 
# repl-backlog-ttl 3600

# The replica priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a replica to promote into a
# master if the master is no longer working correctly.
# 用於哨兵模式下的選舉。
#
# A replica with a low priority number is considered better for promotion, so
# for instance if there are three replicas 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 replica as not able to perform the
# role of master, so a replica with priority of 0 will never be selected by
# Redis Sentinel for promotion.
# 但是0標識這個從節點不能被選為master
#
# By default the priority is 100.
replica-priority 100

# It is possible for a master to stop accepting writes if there are less than
# N replicas connected, having a lag less or equal than M seconds.
# 可以配置master在少於n個從節點,或者主從延時大於m秒的情況下,停止接收寫請求
# The N replicas need to be in "online" state.
# 需要n個從節點是online狀態
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the replica, that is usually sent every second.
# 主從同步必須小於等於指定的秒數
# 從最後一次收到從節點的ping包開始計算
# 通常每秒一次
# 原因:在主從完成同步之後,從節點默認會以每秒一次的頻率,向master發送REPLCONF ACK命令,報告自身的複製偏移量
# 
# 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 replicas
# are available, to the specified number of seconds.
# 這個配置不是保證會有N個從節點來處理寫請求,而是為了防止丟失寫操作
# 
# For example to require at least 3 replicas with a lag <= 10 seconds use:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# Setting one or the other to 0 disables the feature.
# 設置為0標識禁用該特性
#
# By default min-replicas-to-write is set to 0 (feature disabled) and
# min-replicas-max-lag is set to 10.
# 默認min-replicas-to-write是0,min-replicas-max-lag是10

# A Redis master is able to list the address and port of the attached
# replicas 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 replica instances.
# Another place where this info is available is in the output of the
# "ROLE" command of a master.
# master可以獲知備節點的地址和埠。
# 途徑有多種,比如通過INFO replication命令,這個命令會被其他工具使用,
# 比如哨兵模式使用info來發現從節點
# 另一個途徑是Role命令
# The listed IP and address normally reported by a replica is obtained
# in the following way:
# 從節點的IP和埠這樣獲取:
#   IP: The address is auto detected by checking the peer address
#   of the socket used by the replica to connect with the master.
#   IP: 通過解析socket的對端地址
#   Port: The port is communicated by the replica during the replication
#   handshake, and is normally the port that the replica is using to
#   listen for connections.
#   port:通過主從建立連接的握手,獲取從節點用於建立連接的埠
# 
# However when port forwarding or Network Address Translation (NAT) is
# used, the replica may be actually reachable via different IP and port
# pairs. The following two options can be used by a replica in order to
# report to its master a specific set of IP and port, so that both INFO
# and ROLE will report those values.
# 但是,如果從節點使用了埠轉發做個做了nat,從節點的實際連接地址就和上面自動解析出來的不一樣了。
# 這個時候可以用下面的參數,主動申報自己的ip和埠
# (這在雲原生領域需要注意)
# There is no need to use both the options if you need to override just
# the port or the IP address.
# 不是必須兩個一起用,根據需要可以只用一個
# 
# replica-announce-ip 5.5.5.5
# replica-announce-port 1234

################################## 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進行密碼認證
#
# 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.
# 警告,因為redis非常快,用戶可以進行暴力測試破解。
# 所以應該設置一個非常複雜的密碼
# 
# 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 replicas may cause problems.
# 注意改名的命令是會記錄到aof文件的,也會傳遞到從節點
# 所以如果從節點沒有相應的改名,會有問題

################################### CLIENTS ####################################

# 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
# 但是如果系統的打開文件數限制的比較小,那麼這個客戶端限制受限於系統的最大文件數限制
# 並且要減去32(留給redis自己用)
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
# 達到這個最大值會報'max number of clients reached'錯誤
# maxclients 10000

############################## MEMORY MANAGEMENT ################################

# Set a memory usage limit to 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將根據淘汰策略進行數據淘汰
#
# 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.
# 如果根據策略沒有能刪除的key,或者策略就是配置了'noeviction'(不淘汰)
# 那麼對於需要增加內存的命令(如set,lpush等),redis會返回錯誤
# 但是對於get這種讀請求,redis正常相應
# 
# This option is usually useful when using Redis as an LRU or LFU cache, or to
# set a hard memory limit for an instance (using the 'noeviction' policy).
# 這個配置在以下場景很有用的
# 將redis作為一個lru或lfu緩存使用
# 或者對redis實例限制內存使用量(配置noeviction策略)
#
# WARNING: If you have replicas attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the replicas 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 replicas is full with DELs of keys evicted triggering the deletion
# of more keys, and so forth until the database is completely emptied.
# 警告:複製緩衝區的大小是不算在使用的內存量里的
# 這個警告的內容不好理解,涉及到一些往事
# 在redis的低版本中出現過一個bug:
# 在多從節點的場景下,主節點設置了maxmemory,又設置了淘汰策略
# 可能會發生主節點數據被主鍵全部擦除的bug
# 原因是:當初主從複製buffer也是算在使用內存里的。這樣當達到最大內存時,開始淘汰key
# 淘汰key,會記錄為del key放在同步複製buffer中。如果從節點比較多,這個同步buffer會更大。
# 導致使用的內存更會觸及mamemory,進而淘汰更多的key,進而同步bufeer繼續變大。。。
# 最終形成惡性循環,導致所有的key被淘汰
# 現在就能理解這個警告了,解決這個bug的方案就是複製緩衝區的大小是不算在使用的內存量里
# 
# In short... if you have replicas attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for replica
# output buffers (but this is not needed if the policy is 'noeviction').
# 總之,如果redis實例有多個從節點連接,那麼maxmemory設置的小一點(不要和伺服器內存一樣大)
# 給複製緩衝器留一些空間。
# maxmemory <bytes>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
# 淘汰策略:當內存達到maxmemory時,選擇哪些key進行淘汰
# 
# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key among the ones 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 evict anything, just return an error on write operations.
# 共有5種行為
# volatile-lru:使用近似LRU算法從設置了expire的key中選
# allkeys-lru:使用近似LRU算法從全部的key中選
# volatile-lfu:使用近似LFU算法從設置了expire的key中選
# allkeys-lfu:使用近似LFU算法從全部的key中選
# volatile-random:從設置了expire的key中隨機選
# allkeys-random:從全部key中隨機選
# volatile-ttl:刪除剩餘過期時間最小的
# noeviction:不淘汰。對寫請求返回錯誤。默認是這個
#
# LRU means Least Recently Used
# LFU means Least Frequently Used
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
# LRU, LFU and volatile-ttl 都是近似的,不是精準算法
# 
# 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
#
# 注意:對於以上所有策略,當redis發現沒有key能刪除時,都會返回錯誤。
# The default is:
#
# maxmemory-policy noeviction

# LRU, LFU 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 more CPU. 3 is faster but not very accurate.
# lru,lfu和ttl算法都是近似算法,不是精確算法。這樣可以節約內存。
# 可以設置參數對速度和準確性進行調整
# 默認情況下,redis會一次性抓取5個key,選中其中一個。可以調整採樣數量。
#
# 默認的5已經可以得到足夠好的結果,調成10的話,得到的結果更接近準確的算法,但是需要消耗更多的cpu
# 調整成3更快但是更不準確
# 
# maxmemory-samples 5

# Starting from Redis 5, by default a replica will ignore its maxmemory setting
# (unless it is promoted to master after a failover or manually). It means
# that the eviction of keys will be just handled by the master, sending the
# DEL commands to the replica as keys evict in the master side.
# 從redis5開始,默認從節點將忽略maxmemory配置
# 對key的淘汰由master負責,然後發送del命令到從節點
#
# This behavior ensures that masters and replicas stay consistent, and is usually
# what you want, however if your replica is writable, or you want the replica to have
# a different memory setting, and you are sure all the writes performed to the
# replica are idempotent, then you may change this default (but be sure to understand
# what you are doing).
# 這個行為可以確保主從的數據一致性。
# 但是如果你的從節點配置為可寫的,或者你想要從節點有不同的memory配置
# 並且你確定對所有從節點的寫是冪等的,你可以修改這個配置
# (最好不要這樣搞)
#
# Note that since the replica by default does not evict, it may end using more
# memory than the one set via maxmemory (there are certain buffers that may
# be larger on the replica, or data structures may sometimes take more memory and so
# forth). So make sure you monitor your replicas and make sure they have enough
# memory to never hit a real out-of-memory condition before the master hits
# the configured maxmemory setting.
# 注意,因為從節點默認不會主動淘汰數據,他的內存可能比使用maxmemory設置的更大
# 也就是說從節點的內存使用量很可能比master節點的大
# 所以要確保從節點不會發生內存溢出
# 
# replica-ignore-maxmemory yes

############################# LAZY FREEING ####################################

# Redis has two primitives to delete keys. One is called DEL and is a blocking
# deletion of the object. It means that the server stops processing new commands
# in order to reclaim all the memory associated with an object in a synchronous
# way. If the key deleted is associated with a small object, the time needed
# in order to execute the DEL command is very small and comparable to most other
# O(1) or O(log_N) commands in Redis. However if the key is associated with an
# aggregated value containing millions of elements, the server can block for
# a long time (even seconds) in order to complete the operation.
# redis有兩個用於刪除key的原語
# 一個是DEl 命令。del是一個阻塞操作。指定del時會阻塞所有其他命令的執行,直到del完成。
# 如果時刪除一個小對象,del的耗時會很短,和其他O(1) 或 O(log_N) 時間複雜度的命令相當。
# 但是如果是一個聚合數據,比如有幾百萬的數據元素,那麼這個阻塞時間會很長(可能達到秒級)
#
# For the above reasons Redis also offers non blocking deletion primitives
# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and
# FLUSHDB commands, in order to reclaim memory in background. Those commands
# are executed in constant time. Another thread will incrementally free the
# object in the background as fast as possible.
# 因為以上原因,redis提供了一個非阻塞的刪除原語:UNLINK。
# flushall和flushdb增加了非阻塞操作async
# 可以在後台進行內存的回收
# 
# unlink和async的執行時間是一個常量
# 其他線程會繼續在後台遞增的刪除數據
#   
# DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.
# It's up to the design of the application to understand when it is a good
# idea to use one or the other. However the Redis server sometimes has to
# delete keys or flush the whole database as a side effect of other operations.
# Specifically Redis deletes objects independently of a user call in the
# following scenarios:
# 我們會根據自己的業務,在代碼中對del,unlink,flush-async進行主動的使用
# 但是有一些場景下,redis會受其他操作的影響而進行刪除操作
# 比如以下場景
# 
# 1) On eviction, because of the maxmemory and maxmemory policy configurations,
#    in order to make room for new data, without going over the specified
#    memory limit.
# 1、淘汰。達到maxmemory了,根據淘汰策略會進行刪除
# 2) Because of expire: when a key with an associated time to live (see the
#    EXPIRE command) must be deleted from memory.
# 2、過期。key過期進行刪除
# 3) Because of a side effect of a command that stores data on a key that may
#    already exist. For example the RENAME command may delete the old key
#    content when it is replaced with another one. Similarly SUNIONSTORE
#    or SORT with STORE option may delete existing keys. The SET command
#    itself removes any old content of the specified key in order to replace
#    it with the specified string.
# 3、 對一個已經存在的key進行賦值,會發生對舊數據的刪除
#    比如rename命令對key進行改名,如果新名字已經存在,會發生隱式的del操作
#    或者set類命令,如果已經存在。也會發生隱式的del操作 
# 4) During replication, when a replica performs a full resynchronization with
#    its master, the content of the whole database is removed in order to
#    load the RDB file just transferred.
# 4、在主從複製中,當進行全量同步後,會對全部資料庫進行flush
#
# In all the above cases the default is to delete objects in a blocking way,
# like if DEL was called. However you can configure each case specifically
# in order to instead release memory in a non-blocking way like if UNLINK
# was called, using the following configuration directives:
# 在以上這些場景下,默認的刪除操作都是阻塞的方式
# 可以使用下面的參數進行獨立配置

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

############################## 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異步的dump數據到硬碟上。
# 這種模式一般夠用,但是當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.
# aof模式(日誌追加模式)提供了更可靠的持久化保障
# 比如使用默認的刷盤策略,redis可以做到當發生主機斷電災難時只丟失1秒中的寫數據
# 當發生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模式可以同時開啟
# 如果aof是開啟的,redis在啟動時會加載aof文件。
# Please check http://redis.io/topics/persistence for more information.

appendonly no

# The name of the append only file (default: "appendonly.aof")
# aof文件名
appendfilename "appendonly.aof"

# 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.
# fsync()調用觸發作業系統將數據寫到硬碟,而不是在內存buffer中等更多的數據。
# 有的作業系統是真實的進行了刷盤,有的是盡力而為。
# 
# Redis supports three different modes:
# redis支持三種配置
# 
# 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.
# no:不主動fsync,完全交給作業系統控制。最快
# always:每次寫都觸發一次fsync,最慢最安全
# 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。沒有特殊需要用這個就可以。
# 
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "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 or everysec
# 如果此時有一個後台進行進行rdb保存或aof重寫,這也會大量操作io
# 這就和主線程的aof操作發生了競爭,在某些作業系統下,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 or 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).
# 這意味著當子線程進行save操作時,redis的 appendfsync設置為 no
# 就像上面說的,這種情況下要忍受丟部分數據的風險。
# 根據linux的默認設置,最多可能丟失30秒的寫數據
# 
# 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,不進行fsunc刷盤。只是將其放在緩衝區里,避免與命令的追加造成DISK IO上的衝突。
# 設置為no表示在進行BGSAVE or BGREWRITEAOF時,依然進行fsync刷盤
no-appendfsync-on-rewrite no

# Automatic rewrite of the append only file.
# 配置aof文件的自動重寫
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
# 當aof文件漲到指定的百分比時,自動觸發BGREWRITEAOF進行aof文件重寫
#
# 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.
# redis會記住上一次重寫後的文件大小
# 然後和當前文件大小對比,如果達到了多處的百分比,就觸發重寫。
# 也同時需要設置一個最小文件大小。放置達到了重寫的百分比但是文件依然很小的情況
# 
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.
# 將百分比設置為0,就僅用了自動重寫

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

# 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.
# redis啟動時會加載aof文件。首先會檢查aof文件,如果發現aof文件的最後的命令有截斷。
# 這個參數就是控制這種情況下redis怎麼做
# 設置為yes,redis會忽略最後損壞的數據,加載前面正確的數據。
# 設置為no,redis會報錯,無法啟動。需要你手動使用redis-check-aof工具進行修復。
# 注意如果aof文件是在中間就損壞了,設置為yes也是無法加載的。

aof-load-truncated yes

# When rewriting the AOF file, Redis is able to use an RDB preamble in the
# AOF file for faster rewrites and recoveries. When this option is turned
# on the rewritten AOF file is composed of two different stanzas:
#
#   [RDB file][AOF tail]
#
# When loading Redis recognizes that the AOF file starts with the "REDIS"
# string and loads the prefixed RDB file, and continues loading the AOF
# tail.
# aof文件重寫時,將aof文件重寫為rdb格式。之後繼續追加aof格式的數據。
# 因為rdb文件更小,重寫更快。redis重啟時加載也快
# 這樣aof文件就會變成前半部分時rdb文件,後面時aof的情況
#  [RDB file][AOF tail]
aof-use-rdb-preamble yes

################################ LUA SCRIPTING  ###############################

# 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腳本的最大可執行時間
# 當到達執行時間後,redis會記錄log,並返回錯誤
# 
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實例不能用來組建cluster集群,必須以cluster模式啟動
# 也就是將cluster-enabled設置為yes
# 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 do 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.
# 節點超時時間,默認15000毫秒。一個節點超出15秒沒有響應會被標記為可能以失效
# 其他的超時配置通常都是這個cluster-node-timeout的倍數
# cluster-node-timeout 15000

# A replica of a failing master will avoid to start a failover if its data
# looks too old.
# 這個參數是控制什麼樣的從節點可以進行faiover(故障轉移),變成master節點。
# 如果一個從節點的數據太久了,就不能faiover成master
# 
# There is no simple way for a replica to actually have an exact measure of
# its "data age", so the following two checks are performed:
#
# 1) If there are multiple replicas able to failover, they exchange messages
#    in order to try to give an advantage to the replica with the best
#    replication offset (more data from the master processed).
#    Replicas 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 replica 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 replica will not try to failover
#    at all.
# 沒有一個簡單的辦法可以準確的判斷數據的新舊程度。進行下面兩個判斷邏輯
# 1、 選主從同步offset最大的
# 2、 比較同master最後交互的時間。發送ping或者命令都算交互
#     如果這個時間間隔太長了,這個從節點將不能進行failover
# 
# The point "2" can be tuned by user. Specifically a replica will not perform
# the failover if, since the last interaction with the master, the time
# elapsed is greater than:
# 
#   (node-timeout * replica-validity-factor) + repl-ping-replica-period
# 第2點是可以配置的。根據上面這個公式,得到的是最大的間隔時間
# 
# So for example if node-timeout is 30 seconds, and the replica-validity-factor
# is 10, and assuming a default repl-ping-replica-period of 10 seconds, the
# replica will not try to failover if it was not able to talk with the master
# for longer than 310 seconds.
# 比如,node-timeout是30秒,replica-validity-factor是10,假設默認的repl-ping-replica-period是10
# 那麼最後交互時間超過310秒的從節點就不能進行failover
# 
# A large replica-validity-factor may allow replicas with too old data to failover
# a master, while a too small value may prevent the cluster from being able to
# elect a replica at all.
# 這個從節點數據有效因子如果太大,可能導致比較舊的從節點failover成主節點。
# 如果太小,又可能導致沒有從節點能failover成主節點。
# 
# For maximum availability, it is possible to set the replica-validity-factor
# to a value of 0, which means, that replicas 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.
# 為了保持最高的高可用性,可以將replica-validity-factor設置為0.
# 這樣從節點總會嘗試進行failover 
#
# cluster-replica-validity-factor 10

# Cluster replicas are able to migrate to orphaned masters, that are masters
# that are left without working replicas. 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 replicas.
# 如果一個master沒有任何在線的從節點。而另外的master有多個從節點。
# 那麼多餘的從節點可以遷移給這個孤立的master
# 使整個集群更平衡,避免這個孤立的master宕機,而沒有能進行failover的從節點
# 
# Replicas migrate to orphaned masters only if there are still at least a
# given number of other working replicas for their old master. This number
# is the "migration barrier". A migration barrier of 1 means that a replica
# will migrate only if there is at least 1 other working replica for its master
# and so forth. It usually reflects the number of replicas you want for every
# master in your cluster.
# migration barrier這個參數就是來控制什麼樣的主節點上的從節點可以遷移。
# cluster-migration-barrier 1表示遷移後,原來的master必須還有不少於1個從節點
# 這個參數一般也表示你希望集群中每個master有幾個從節點
#
# Default is 1 (replicas migrate only if their masters remain with at least
# one replica). 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。在生產環境很危險。
#
# cluster-migration-barrier 1

# 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.
# 默認情況下,redis集群中只有有一個slot丟失,整個集群將不可用
# 只要集群中有部分master宕機,整個集群即不可用
# 當slot恢復後,整個集群自動恢復可用
#
# 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.
# 但是有時候你希望集群活著的部分依然可以對外服務,就將這個配置設置為true
# 
# cluster-require-full-coverage yes

# This option, when set to yes, prevents replicas from trying to failover its
# master during master failures. However the master can still perform a
# manual failover, if forced to do so.
#
# This is useful in different scenarios, especially in the case of multiple
# data center operations, where we want one side to never be promoted if not
# in the case of a total DC failure.
# 如果這個配置設置為yes,將阻止從節點failover成master。仍然可以進行手動failover
# 這個配置在某些場景下有用,比如多數據中心,我們希望某個中心的節點永遠不要自動提升
# 
# cluster-replica-no-failover no

# In order to setup your cluster make sure to read the documentation
# available at http://redis.io web site.

########################## CLUSTER DOCKER/NAT support  ########################

# In certain deployments, Redis Cluster nodes address discovery fails, because
# addresses are NAT-ted or because ports are forwarded (the typical case is
# Docker and other containers).
# 在redis進行容器化部署的場景下,集群節點的地址發現失敗
# 因為容器化啟動的redis,他的地址可能會經過nat轉換,埠也可能經過了轉發
#
# In order to make Redis Cluster working in such environments, a static
# configuration where each node knows its public address is needed. The
# following two options are used for this scope, and are:
# 為了滿足這種場景,可以對節點地址進行靜態配置
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-bus-port
#
# Each instruct the node about its address, client port, and cluster message
# bus port. The information is then published in the header of the bus packets
# so that other nodes will be able to correctly map the address of the node
# publishing the information.
# 這三個配置分別指定ip地址,埠和集群總線埠
# 這些信息會加在集群總線信息的信息頭裡,這樣其他節點就可以得到真實的地址
# 
# If the above options are not used, the normal Redis Cluster auto-detection
# will be used instead.
# 如果沒有配置以上信息,redis集群會自動解析出這些信息(在容器化場景下通常是錯誤的)
# 
# Note that when remapped, the bus port may not be at the fixed offset of
# clients port + 10000, so you can specify any port and bus-port depending
# on how they get remapped. If the bus-port is not set, a fixed offset of
# 10000 will be used as usually.
# 注意,總線接口在伺服器上部署時,默認是客戶端埠+10000
# 在容器化中,可能不是。可以指定。如果沒有指定,那就默認是客戶端埠+10000
# Example:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380

################################## 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).
# 慢查詢日誌是為了記錄超過一定執行時間的查詢
# 這個執行時間不包括io時間(比如同client交互,發送響應的時間等)
# 只是實際執行命令的時間,在這個時間內redis是阻塞狀態,不能響應其他請求
#
# 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.
# 有兩個參數可以配置
# 一個是slowlog-log-slower-than,單位是微秒!!。表示超過這個配置的就是慢查詢
# 另一個是slowlog-max-len,限制記錄的慢查詢的數量條數。先進先出的隊列

# 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

################################ LATENCY MONITOR ##############################

# 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.
# Redis延遲監控子系統在運行時對不同的操作進行採樣,以便收集Redis實例延遲可能來源的相關數據。
# 通過延遲命令,用戶可以通過列印圖形和獲取報告獲得這些信息。
#
# 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.
# 這個延遲監控系統只記錄在時間大於等於latency-monitor-threshold指定的毫秒數時間的操作。
# 當它的值設置為0時,將關閉延遲監視器。
#
# 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.
# 默認是關閉的。因為當沒有延遲問題時,這個特性也不需要。
# 並且收集數據有一點點性能損耗。
# 當需要時,可以通過"CONFIG SET latency-monitor-threshold <milliseconds>"隨時開啟
latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at http://redis.io/topics/notifications
# redis可以通知Pub/Sub客戶端在key上發生的事件
#
# 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 「foo」上執行了del操作。那麼redis會通過發布/訂閱機制發布兩條信息

# 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
#  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 ""

############################### 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類型的數據在一定條件下底層使用ziplist進行存儲。ziplist是一種內存優化的數據結構。
# 這個一定條件就是下面的設置。當hash數據滿足下面兩個條件,就是用ziplist進行存儲。
#
# ziplist中允許存儲的最大條目數
hash-max-ziplist-entries 512
# 每條數據value值最大字節數
hash-max-ziplist-value 64

# 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.
# redis中list類型的數據底層是使用quicklist來存儲的,
# 而quicklist是基於linkedlist + ziplist實現的。
# 這個參數是用來限制每個quicklist節點上的ziplist長度
# 當取正值的時候,表示按照數據項個數來限定每個quicklist節點上的ziplist長度。比如,當這個參數配置成5的時候,表示每個quicklist節點的ziplist最多包含5個數據項。
# 當取負值的時候,表示按照占用字節數來限定每個quicklist節點上的ziplist長度。這時,它只能取-1到-5這五個值,每個值含義如上
# 比如  -2: 每個quicklist節點上的ziplist大小不能超過8 Kb
#
list-max-ziplist-size -2

# 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是可以被壓縮的,這個參數指定quicklist兩端不被壓縮的節點個數
# 頭尾兩個節點是永遠不會被壓縮的,以便於在表的兩端進行快速存取
# 0: 不進行壓縮。默認屬性
# 1: 頭尾各1個節點不進行壓縮
# 2: 頭尾各2個節點不進行壓縮
# 3: 頭尾各3個節點不進行壓縮
# 依次類推
list-compress-depth 0

# 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結構在一個特殊場景下有一個優化的數據結構intset
# 這個特殊場景是:全部是數字的字符串
# 在這種情景下,當set的元素小於set-max-intset-entries的值時,使用intset這種數據結構
# 可以極大的節省內存
# 但是當數據量超過set-max-intset-entries的值時,就會自動進行底層數據結構的類型轉換
# 從intset轉換為hashtable
# 這個轉換大量發生時,會出現內存使用量暴漲的情況
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:
# 同樣zset類型在數據量小的情況下,也有其內存優化的數據結構
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.
# HyperLogLog 稀疏模式的字節限制,包括了 16 字節的頭,默認值為 3000。 
# 當超出這個限制後 HyperLogLog 將由稀疏模式轉為稠密模式。
# 這個值設置為超過 16000 是沒必要的,因為這時使用稠密模式更省空間
# 建議值是3000左右
hll-sparse-max-bytes 3000

# Streams macro node max size / items. The stream data structure is a radix
# tree of big nodes that encode multiple items inside. Using this configuration
# it is possible to configure how big a single node can be in bytes, and the
# maximum number of items it may contain before switching to a new node when
# appending new stream entries. If any of the following settings are set to
# zero, the limit is ignored, so for instance it is possible to set just a
# max entires limit by setting max-bytes to 0 and max-entries to the desired
# value.
# 設定 Streams 單個節點的最大大小和最多能保存多少個元素
stream-node-max-bytes 4096
stream-node-max-entries 100

# 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.
# 當啟用這個功能後,Redis對哈希表的 rehash操作會每100毫秒CPU時間抽出1毫秒進行主動的rehash。
# redis的rehash策略是一種惰性策略,當有數據對hash表進行操作時,順便進行rehash
# 操作越多,rehash進行的就越多,也就能越快完成rehash
# 所以,如果redis很閒,沒什麼數據,rehash過程可能要持續很久,甚至不能完成
# 這個過程中,新舊兩個hash表都存在,也就浪費了更多內存
# 
# The default is to use this millisecond 10 times every second in order to
# actively rehash the main dictionaries, freeing memory when possible.
# 默認是每秒抽出10次1毫秒進行主動rehash
# 
# 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.
# 如果是對響應要求非常嚴格的場景,不能接收時不時的增加2ms延遲
# 那就可以設置為no
#
# use "activerehashing yes" if you don't have such hard requirements but
# want to free memory asap when possible.
# 否則就保持默認的yes,可以更快的釋放內存
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 -> 普通客戶端,包括 MONITOR 客戶端
# replica -> 從節點複製客戶端
# pubsub -> 訂閱了至少一個頻道的客戶端
#
# normal -> normal clients including MONITOR clients
# replica  -> replica 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.
# 達到hard limit,立即斷開
# 達到 soft limit,並持續soft seconds秒都達到soft limit,然後會斷開
#
# 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 replica clients, since
# subscribers and replicas receive data in a push fashion.
# 默認情況下 pubsub 和 replica 客戶端會有默認的限制,
# 因為這些客戶端是以 Redis 服務端 push 的方式接收數據的
# Both the hard or the soft limit can be disabled by setting them to zero.
# soft limit 或者 hard limit 都可以設置為 0,這表示禁用此限制

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

# Client query buffers accumulate new commands. They are limited to a fixed
# amount by default in order to avoid that a protocol desynchronization (for
# instance due to a bug in the client) will lead to unbound memory usage in
# the query buffer. However you can configure it here if you have very special
# needs, such us huge multi/exec requests or alike.
# 客戶端查詢緩衝區會累加新的命令。 
# 默認情況下,他們會限制在一個固定的數量避免協議同步失效(比如客戶端的 bug)導致查詢緩衝區出現未綁定的內存。
# 但是,如果有類似於巨大的 multi/exec請求的時候可以修改這個值以滿足你的特殊需求。

# client-query-buffer-limit 1gb

# In the Redis protocol, bulk requests, that are, elements representing single
# strings, are normally limited ot 512 mb. However you can change this limit
# here.
# 在 Redis 協議中,批量請求通常限制在 512 mb 內,
# 可以通過修改 proto-max-bulk-len 選項改變這個限制
# proto-max-bulk-len 512mb

# 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參數用於指定Redis後台任務的執行頻率,這些任務包括關閉超時的客戶端連接、主動清除過期key等。
hz 10

# Normally it is useful to have an HZ value which is proportional to the
# number of clients connected. This is useful in order, for instance, to
# avoid too many clients are processed for each background task invocation
# in order to avoid latency spikes.
#
# Since the default HZ value by default is conservatively set to 10, Redis
# offers, and enables by default, the ability to use an adaptive HZ value
# which will temporary raise when there are many connected clients.
#
# When dynamic HZ is enabled, the actual configured HZ will be used as
# as a baseline, but multiples of the configured HZ value will be actually
# used as needed once more clients are connected. In this way an idle
# instance will use very little CPU time while a busy instance will be
# more responsive.
#5.0之前的redis版本,hz參數一旦設定之後就是固定的了。
#hz默認是10。這也是官方建議的配置。
#如果改大,表示在reids空閒時會用更多的cpu去執行這些任務。官方並不建議這樣做。
#但是,如果連接數特別多,在這種情況下應該給與更多的cpu時間執行後台任務。
#所以有了這個dynamic-hz參數,默認就是打開。當連接數很多時,自動加倍hz,以便處理更多的連接。
dynamic-hz yes

# 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 的重寫時,如果啟用了 aof-rewrite-incremental-fsync, 
# 子進程會每生成 32 MB 數據就進行一次 fsync 操作。 
# 通過這種方式將數據分批提交到硬碟可以避免高延遲峰值。
aof-rewrite-incremental-fsync yes

# When redis saves RDB 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.
# rdb文件每增加32mb 就執行fsync一次(增量式,避免一次性大寫入導致的延時)
# 這個是針對rdb模式的優化,
# aof模式在4版本的時候已經有這個優化了aof-rewrite-incremental-fsync
rdb-save-incremental-fsync yes

# Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good
# idea to start with the default settings and only change them after investigating
# how to improve the performances and how the keys LFU change over time, which
# is possible to inspect via the OBJECT FREQ command.
# lfu淘汰策略可以進行配置。
# 保持默認值就是一個好主意。只有經過研究驗證後再進行變更。
# 
# 在LFU算法中,每個key有一個計數器counter。每次key被訪問的時候,計數器增大。
# 計數器越大,可以約等於訪問越頻繁。
# 但是counter不是簡單的線性增大,而是採用對數函數增長曲線
# 增加曲線通過lfu-log-factor對數因子來控制
# 並且不能只增加,醉著事件的推移,不被訪問的key的計數器需要減小
# 這個減小的速度通過lfu-decay-time衰減事件來控制
#
# There are two tunable parameters in the Redis LFU implementation: the
# counter logarithm factor and the counter decay time. It is important to
# understand what the two parameters mean before changing them.
#
# The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis
# uses a probabilistic increment with logarithmic behavior. Given the value
# of the old counter, when a key is accessed, the counter is incremented in
# this way:
# 上面說的計數器counter,是一個8bit大的數,所以最大值就是255
#
# 1. A random number R between 0 and 1 is extracted.
# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).
# 3. The counter is incremented only if R < P.
#
# The default lfu-log-factor is 10. This is a table of how the frequency
# counter changes with a different number of accesses with different
# logarithmic factors:
# 默認的log底數是10,下面的表是不同的底數,隨著訪問次數的變化,其計數器值的變化
# 根據log函數我們也能猜到,底數越大增加曲線越平緩
# +--------+------------+------------+------------+------------+------------+
# | factor | 100 hits   | 1000 hits  | 100K hits  | 1M hits    | 10M hits   |
# +--------+------------+------------+------------+------------+------------+
# | 0      | 104        | 255        | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 1      | 18         | 49         | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 10     | 10         | 18         | 142        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 100    | 8          | 11         | 49         | 143        | 255        |
# +--------+------------+------------+------------+------------+------------+
#
# NOTE: The above table was obtained by running the following commands:
#
#   redis-benchmark -n 1000000 incr foo
#   redis-cli object freq foo
#
# NOTE 2: The counter initial value is 5 in order to give new objects a chance
# to accumulate hits.
#
# The counter decay time is the time, in minutes, that must elapse in order
# for the key counter to be divided by two (or decremented if it has a value
# less <= 10).
#
# The default value for the lfu-decay-time is 1. A Special value of 0 means to
# decay the counter every time it happens to be scanned.
#
# lfu-log-factor 10
# lfu-decay-time 1

########################### ACTIVE DEFRAGMENTATION #######################
#
# 警告:該特性還在實驗階段,但是已經在生產和測試環境下經過大量壓力測試。
#
# 什麼是主動的碎片整理?
# -------------------------------
#
# Active (online) defragmentation allows a Redis server to compact the
# spaces left between small allocations and deallocations of data in memory,
# thus allowing to reclaim back memory.
# 在線碎片整理可以讓redis收集在小的分配之間的遺留空間,釋放不需要的內存數據。
# 從而可以重新分配這些內存空間
#
# Fragmentation is a natural process that happens with every allocator (but
# less so with Jemalloc, fortunately) and certain workloads. Normally a server
# restart is needed in order to lower the fragmentation, or at least to flush
# away all the data and create it again. However thanks to this feature
# implemented by Oran Agra for Redis 4.0 this process can happen at runtime
# in an "hot" way, while the server is running.
# 出現內存碎片是很正常的,每個內存分配器都會有內存碎片,Jemelloc出現內存碎片還算少的。
# 一般來說都需要重啟進程才能降低碎片率,或者至少也要重新flush一遍數據然後再重新生成數據。
# 但是幸運的是在redis4.0版本,實現了熱更新,即redis在運行過程中完成碎片整理
#
# Basically when the fragmentation is over a certain level (see the
# configuration options below) Redis will start to create new copies of the
# values in contiguous memory regions by exploiting certain specific Jemalloc
# features (in order to understand if an allocation is causing fragmentation
# and to allocate it in a better place), and at the same time, will release the
# old copies of the data. This process, repeated incrementally for all the keys
# will cause the fragmentation to drop back to normal values.
# 基本上,當碎片率超過一定水平(下面有配置參數)時,redis會利用Jemelloc的特性在一段連續的內存
# 空間中創建某些數據的副本(Jemelloc的這個特性可以分析出哪些數據的分配導致了碎片的出現,然後將其遷移到更合適的地方)。
# 同時釋放舊的數據。這樣就完成了一次數據的遷移。
# 這個過程會持續的進行,直到所有導致碎片的數據都遷移到合適的位置
#
# Important things to understand:
# 需要理解的重要內容:
#
# 1. This feature is disabled by default, and only works if you compiled Redis
#    to use the copy of Jemalloc we ship with the source code of Redis.
#    This is the default with Linux builds.
# 1. 這個特性默認時關閉的。並且只有你在編譯redis時指定了使用Jemalloc進行編譯,後續才能啟用這個特性。
#    使用linux進行構建時的默認內存分配器就是Jemalloc。
#    但是我在make時遇到jemalloc/jemalloc.h: 沒有那個文件或目錄
#    因為我的機器上沒有jemalloc
#    一個解決方案時在make時指定使用libc作為內存分配器。make MALLOC=libc
#    另一個方案就是安裝Jemalloc。jemalloc被證明比libc有更少的碎片問題。
#       還沒有實驗。
#    wget https://github.com/jemalloc/jemalloc/releases/download/5.0.1/jemalloc-5.0.1.tar.bz2
#       tar -jxvf jemalloc-5.0.1.tar.bz2
#       cd jemalloc-5.0.1
#       yum install autogen autoconf
#        
#       ./autogen.sh
#       make -j2
#       make install
#       ldconfig
#       cd ../
#       rm -rf jemalloc-5.0.1 jemalloc-5.0.1.tar.bz2
#
# 2. You never need to enable this feature if you don't have fragmentation
#    issues.
# 2. 如果你沒有碎片問題,就不需要啟用這個特性
#
# 3. Once you experience fragmentation, you can enable this feature when
#    needed with the command "CONFIG SET activedefrag yes".
# 3. 當你遇到碎片問題時,可以使用"CONFIG SET activedefrag yes"這個命令啟用在線碎片整理功能
#
# The configuration parameters are able to fine tune the behavior of the
# defragmentation process. If you are not sure about what they mean it is
# a good idea to leave the defaults untouched.
# 下面配置參數可以用來調整碎片整理的行為。
# 但是在調整前你必須搞懂這些參數的含義,否則還是用默認值為好。

# Enabled active defragmentation
# 啟用在線碎片整理特性
# activedefrag yes

# Minimum amount of fragmentation waste to start active defrag
# 碎片整理開啟的最小量。也就是碎片在100mb以下,不會進行碎片整理。當碎片達到 100mb 時,開啟內存碎片整理
# active-defrag-ignore-bytes 100mb

# Minimum percentage of fragmentation to start active defrag
# 當碎片率超過到10%時,開啟內存碎片整理
# active-defrag-threshold-lower 10

# Maximum percentage of fragmentation at which we use maximum effort
# 碎片率超過100%時,盡最大努力進行整理
# active-defrag-threshold-upper 100

# Minimal effort for defrag in CPU percentage
# 碎片整理時使用的最小cpu百分比
# active-defrag-cycle-min 5

# Maximal effort for defrag in CPU percentage
# 碎片整理時使用的最大cpu百分比,也就是盡最大努力
# active-defrag-cycle-max 75

# Maximum number of set/hash/zset/list fields that will be processed from
# the main dictionary scan
# 碎片整理時對於set/hash/zset/list類型數據的最大掃描欄位
# active-defrag-max-scan-fields 1000

# It is possible to pin different threads and processes of Redis to specific
# CPUs in your system, in order to maximize the performances of the server.
# This is useful both in order to pin different Redis threads in different
# CPUs, but also in order to make sure that multiple Redis instances running
# in the same host will be pinned to different CPUs.
# 可以將不同的redis的線程和進程綁定到特定的cpu上,以便最大化利用伺服器的性能。
# 這項能力在將redis的不同線程綁定到不同cpu時很有用,更有用的場景是在一台server上
# 啟動多個redis實例,可以將不同的redis綁定到指定的cpu上。
#
# Normally you can do this using the "taskset" command, however it is also
# possible to this via Redis configuration directly, both in Linux and FreeBSD.
# 可以用taskset命令,(linux的綁核命令)
# 也可以直接通過redis的配置文件實現
#
# You can pin the server/IO threads, bio threads, aof rewrite child process, and
# the bgsave child process. The syntax to specify the cpu list is the same as
# the taskset command:
# 你可以綁server/IO threads, bio threads, aof rewrite child process, 和the bgsave child process
# 語法和taskset命令一樣
#
# Set redis server/io threads to cpu affinity 0,2,4,6:
# 設置server/io線程和cpu 0,2,4,6有親和關係
# server_cpulist 0-7:2
#
# Set bio threads to cpu affinity 1,3:
# 設置bio線程和cpu 1,3有親和關係
# bio_cpulist 1,3
#
# Set aof rewrite child process to cpu affinity 8,9,10,11:
# 設置aod重新子進程和cpu 8,9,10,11有親和關係
# aof_rewrite_cpulist 8-11
#
# Set bgsave child process to cpu affinity 1,10,11
# 設置bgsave子進程和cpu 1,10,11有親和關係
# bgsave_cpulist 1,10-11

# In some cases redis will emit warnings and even refuse to start if it detects
# that the system is in bad state, it is possible to suppress these warnings
# by setting the following config which takes a space delimited list of warnings
# to suppress
# 當redis發現作業系統狀態有問題時會發出一些warning,有時甚至會拒絕啟動
# 可以設置忽略警告。
# 在arm64架構下啟動redis會報ARM64-COW-BUG警告,redis不能啟動。可以開啟這個忽略
# 但是最好還是換X86架構
# ignore-warnings ARM64-COW-BUG
關鍵字: