redis 6.0.9配置文件詳解


以下為博主使用redis時,抽空做的配置文件翻譯,水平有限,可能存在錯誤理解。發現了請通知博主修改,畢竟知識這東西不能糊塗,沒人看還好,就怕誤導新人。

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-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
# 以支持單位指定內存大小
# units are case insensitive so 1GB 1Gb 1gB are all the same.

INCLUDES


################################## 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.
#
# Note that 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.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
# 設置啟動指令前的配置文件、后加載的配置文件會覆蓋先加載的配置文件配置
# include /path/to/local.conf
# include /path/to/other.conf

MODULES


################################## 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.
# 在啟動時加載模塊。如果服務器無法加載模塊它將中止。可以使用多個loadmodule指令。
# 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 available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
# 
# 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 on the
# IPv4 loopback interface address (this means Redis will only be able to
# accept client connections from the same host that it is running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 允許該ip端口連接到redis服務、可配置多個。bind 0.0.0.0設置允許通過所有IP地址連接。
# 一台服務器在不同的網段的ip地址是不同的,如果我們只設置了允許在A網段下的ip地址,那么在B網段
# 下的所有服務器即使擁有正確的賬號密碼也是無法連接redis服務的,生產環境必須設定死ip
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.
#
# 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.
#
# 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.
#是否開啟保護模式,默認開啟。要是配置里沒有指定bind和密碼。開啟該參數后,redis只會本地進行訪問,拒絕外部訪問
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.
# 啟動端口
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need a high backlog in order
# to avoid slow clients connection 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積壓工作數(默認511)、會被linux的內核/proc/sys/net/core/somaxconn參數
#(默認:128)強行限制(即該值不會大於somaxconn值)
tcp-backlog 128

# 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 套接字支持
# unixsocket /tmp/redis.sock
# unix 套接字權限
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
# 當連接空閑時間超過N秒后關閉連接(設置為0,標識服務端永不主動關閉客戶端連接)
timeout 160

# TCP keepalive.
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
# 如果設置非零,則使用SO_KEEPALIVE發送TCP ACKs(確認消息) 向掉線客戶端溝通,這有兩個好處
#
# 1) Detect dead peers.
# 及時發現宕機的客戶端
# 2) Force network equipment in the middle to consider the connection to be
#    alive.
# 確保連接設備存活,
#
# 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.
# 在linux設備上,該配置周期單位為秒,需要注意的是關閉一個連接需要兩個周期。)
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300

TLS/SSL配置

################################# TLS/SSL #####################################

# By default, TLS/SSL is disabled. To enable it, the "tls-port" configuration
# directive can be used to define TLS-listening ports. To enable TLS on the
# default port, use:
# 默認情況下,TLS/SSL 是關閉的。如果開啟,則tls-port配置的端口會用作TLS默認端口(意思應該是配
# 置了tls-port的端口,同時就打開了TLS/SSL服務)
# port 0
# tls-port 6379

# Configure a X.509 certificate and private key to use for authenticating the
# server to connected clients, masters or cluster peers.  These files should be
# PEM formatted.
# 使用一個 X.509 證書與密鑰來實現客戶端連接主節點或者集群的認證過程。這些文件應該是PEM格式
#
# tls-cert-file redis.crt 
# 證書
# tls-key-file redis.key
# 密鑰

# Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange:
# 配置DHfile文件來啟動DH密鑰交換
#
# tls-dh-params-file redis.dh

# Configure a CA certificate(s) bundle or directory to authenticate TLS/SSL
# clients and peers.  Redis requires an explicit configuration of at least one
# of these, and will not implicitly use the system wide configuration.
# 配置一個CA文件或者包含CA文件的文件夾來認證客戶端的TLS/SSL連接。這兩項配置
# 你至少需要配置一個,因為redis沒有為這個做系統默認配置
#
# tls-ca-cert-file ca.crt
# CA文件
# tls-ca-cert-dir /etc/ssl/certs
# CA文件夾地址

# By default, clients (including replica servers) on a TLS port are required
# to authenticate using valid client side certificates.
# 默認情況下,客戶端(包含從節點)使用TLS的時候必須進行證書認證
#
# If "no" is specified, client certificates are not required and not accepted.
# 如果配置為no,則客戶端證書不是必要的
# If "optional" is specified, client certificates are accepted and must be
# valid if provided, but are not required.
# 如果配置為 optional 則客戶端證書有則必須校驗通過,或者沒有。
#
# tls-auth-clients no
# tls-auth-clients optional

# By default, a Redis replica does not attempt to establish a TLS connection
# with its master.
# 默認情況下,從節點不會以TLS的方式連接主節點
#
# Use the following directive to enable TLS on replication links.
# 從節點同步數據使用TLS
#
# tls-replication yes

# By default, the Redis Cluster bus uses a plain TCP connection. To enable
# TLS for the bus protocol, use the following directive:
# 默認情況下,redis集群使用TCP連接,要啟用TLS連接的話,配置為yes
#
# tls-cluster yes

# Explicitly specify TLS versions to support. Allowed values are case insensitive
# and include "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" (OpenSSL >= 1.1.1) or
# any combination. To enable only TLSv1.2 and TLSv1.3, use:
# 明確指定TLS版本,可以同時指定多個版本(版本大於1.1.1)
# 
# tls-protocols "TLSv1.2 TLSv1.3"

# Configure allowed ciphers.  See the ciphers(1ssl) manpage for more information
# about the syntax of this string.
# 配置允許訪問的密鑰,關於更多的密鑰信息請參考 ciphers(1ssl) 手冊
#
# Note: this configuration applies only to <= TLSv1.2.
#
# tls-ciphers DEFAULT:!MEDIUM

# Configure allowed TLSv1.3 ciphersuites.  See the ciphers(1ssl) manpage for more
# information about the syntax of this string, and specifically for TLSv1.3
# ciphersuites.
#
# tls-ciphersuites TLS_CHACHA20_POLY1305_SHA256

# When choosing a cipher, use the server's preference instead of the client
# preference. By default, the server follows the client's preference.
#
# tls-prefer-server-ciphers yes

# By default, TLS session caching is enabled to allow faster and less expensive
# reconnections by clients that support it. Use the following directive to disable
# caching.
#
# tls-session-caching no

# Change the default number of TLS sessions cached. A zero value sets the cache
# to unlimited size. The default size is 20480.
#
# tls-session-cache-size 5000

# Change the default timeout of cached TLS sessions. The default timeout is 300
# seconds.
#
# tls-session-cache-timeout 60

GENERAL 基礎設置

################################# 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.
# 是否后台運行
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
#                        requires "expect stop" in your upstart job config
#   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 pings back to your supervisor.
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啟動創建,關閉刪除。指定不指定無所謂,不指定的話依然能夠正常運行(因為會創建默認文件)/var/run/redis.pid
# 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) 警告,只有非常重要、關鍵的信息被記錄
loglevel debug

# 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.
# 系統日志是否啟動,就是redis核心進程日志
# syslog-enabled no

# Specify the syslog identity.
# 系統日志標識
# syslog-ident redis

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# 記錄日志的設備、必須在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
# 數據庫數量,默認選擇數據庫0,可以用 select 0/dbid 選擇數據庫。dbid取值范圍為 [0,database-1] 間取整數
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.
# redis的log顯示與否。這里沒整明白說的是什么。唯一知道的就是不管你怎么設置,啟動日志必定顯示logo。
 always-show-logo yes

SNAPSHOTTING快照設置

################################ 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 behavior will be to save:  
#   以下配置是基於一個整體配置(3個小配置)來說明的沒有照原文翻譯,便於理解   在進行一次數據持久化后的第一個鍵產生開始
#   after 900 sec (15 min) if at least 1 key changed         如果只有1-9個鍵產生,15分鍾后進行一次數據持久化
#   after 300 sec (5 min) if at least 10 keys changed        如果有10-50個鍵產生,5分鍾后進行一次數據持久化
#   after 60 sec if at least 10000 keys changed              如果有10000-(+inf)正無窮個鍵產生,60秒進行一次數據持久化。  每次數據持久化會刷新所有小配置的⏲計時
#															正常的關閉reids是會進行數據持久化操作的,所以嚴禁通過殺死進程的方式進行關閉操作
# 
#   Note: you can disable saving completely by commenting out all "save" lines.
#	你可以通過注釋掉所有保存來使得redis不進行磁盤保存,不建議。這樣的話redis一死數據完全丟失。一般還是需要維持數據持久化的
#   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 ""
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.
#
# If the background saving process will start working again Redis will
# automatically allow writes again.
#
# 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寫操作,(這樣會保證redis持久化出問題不會造成大量數據丟失,因為一旦出現問題,不會再產生新數據入庫,一旦入庫對於用戶而言就是正常的服務。)
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?
# By default compression is enabled 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持久化的時候啟動壓縮
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.
# 從版本5開始,每個rdb文件末尾會附加 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
# rdb文件
dbfilename dump.rdb

# Remove RDB files used by replication in instances without persistence
# enabled. By default this option is disabled, however there are environments
# where for regulations or other security concerns, RDB files persisted on
# disk by masters in order to feed replicas, or stored on disk by replicas
# in order to load them for the initial synchronization, should be deleted
# ASAP. Note that this option ONLY WORKS in instances that have both AOF
# and RDB persistence disabled, otherwise is completely ignored.
# 開啟刪除同步rdb文件,默認關閉。大致意思是采用磁盤文件緩沖數據同步時產生的RDB文件是否刪除。一般
# 不建議刪除。有些場景下,出於服務器安全的考慮需要刪除。
#
# An alternative (and sometimes better) way to obtain the same effect is
# to use diskless replication on both master and replicas instances. However
# in the case of replicas, diskless is not always an option.
# 還有一種辦法就是直接采用內存同步,不經過RDB文件中間緩沖數據。這樣就不會產生RDB同步文件,那么這個配置也將失去意義
rdb-del-sync-files no

# 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的AOF文件與RDB文件保存地址
dir /data/redis

REPLICATION復制、主從設置

################################# 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.
# 1) 主從復制是異步的。后面這個但是搞得我一臉懵逼
# 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.
#    復制是自動的,不需要用戶再次手動的干預(就是內部代碼寫死的)
# 從什么ip:port下復制數據(就是設置主節點的ip端口)
# 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.
# 大致意思就是如果主節點需要密碼校驗,你個從節點就必須輸入密碼,不然主節點就不帶你玩,就無法復制主節點數據
# #主節點認證密鑰:
# masterauth <master-password>
#
# However this is not enough if you are using Redis ACLs (for Redis version
# 6 or greater), and the default user is not capable of running the PSYNC
# command and/or other commands needed for replication. In this case it's
# better to configure a special user to use with replication, and specify the
# masteruser configuration as such:
# 如果使用的ACLs版本的redis(redis6以后的)。默認用戶沒有PSYNC權限,所以最好配置一個專門的用戶用來做數據復制
# 擁有復制權限的用戶
# masteruser <username>
#
# When masteruser is specified, the replica will authenticate against its
# master using the new AUTH form: AUTH <username> <password>.
# 當配置了masteruser賬戶是,從節點將使用這個賬號進行認證,(不明白這句話放在這里的意義是什么)
#
# 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.
#    如果設置為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 commands except:
#    INFO, REPLICAOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, SUBSCRIBE,
#    UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, COMMAND, POST,
#    HOST and LATENCY.
#   如果設置為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.
# 從redis 2.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.
# 大致意思是:從節點只讀設置不是為了向未授權的客戶端公開數據,主要是為了防止實例濫用的保護層
#(說讀寫分離主要是為了提高性能的打臉了,讀寫分離很重要。但官方可不是為了提高性能而設計的只讀、主要是為了安全性)
# 由於默認情況下從節點依然可以使用部分配置、調試指令。故可以采用重命名指令名字的方式提高從節點的安全性
# 
# 從節點配置只讀
replica-read-only yes

# Replication SYNC strategy: disk or 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.
# 如果是新連接的從節點,或者斷線重連的從節點無法使用部分同步(因為存在嚴重數據丟失的風險)就會執行
# 全量同步,主節點會生產RDB文件
#
# The transmission can happen in two different ways:
# 主從復制有兩種方式提供選擇
# 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.
# 方案一:磁盤復制:主節點創建一個新進程在磁盤將數據寫入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.
#
# 方案二:主節點直接將數據寫進套接字發送給從節點進行數據同步
# 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.
# 如果使用磁盤復制的話,主節點能夠在一個RDB文件生產完畢后同時給多個子節點使用。
# 如果這個磁盤復制在無磁盤復制任務后創建,那么就會進入等待隊列,等無磁盤復制完成后進行
#
# 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.
# 網絡快磁盤慢的就用無磁盤復制、一般多個redis部署在一個局域網絡。相互之間的網絡通信速度都很快
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.
# 當使用無磁盤復制的時候,可以合理的配置等待時間以便通過套接字的方式復制數據給從節點
#
# 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.
# 有一點很重要,就是當傳輸開始的時候,主節點無法再為從節點提供服務,會將請求放進等待隊列
# 因此設置主節點的等待時間以便可以一次處理更多的從節點同步數據請求
#
# 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,則標識無等待直接同步數據
#(這里最好建議別設置為0,因為一旦進行數據傳輸的話,新的同步請求會等待這一次完成后再進行,幾乎永遠不會有多個子節點同步同步數據)
repl-diskless-sync-delay 5

# -----------------------------------------------------------------------------
# WARNING: RDB diskless load is experimental. Since in this setup the replica
# does not immediately store an RDB on disk, it may cause data loss during
# failovers. RDB diskless load + Redis modules not handling I/O reads may also
# cause Redis to abort in case of I/O errors during the initial synchronization
# stage with the master. Use only if your do what you are doing.
# 警告:無磁盤數據同步是實驗性的。由於這中設置中,從節點不會立即將數據存在磁盤上,如果此時發生故障會導致數據的丟失。
# redis無磁盤同步與redis無I/O讀也會在reids發生I/O錯誤的時候終止數據同步,因此你最好再三確認你的選擇。
# -----------------------------------------------------------------------------
#
# Replica can load the RDB it reads from the replication link directly from the
# socket, or store the RDB to a file and read that file after it was completely
# received from the master.
# 從節點可以直接從網絡套接字中獲取數據,也可以先將所有套接字里面的數據存在本地文件后再從文件讀取
#
# In many cases the disk is slower than the network, and storing and loading
# the RDB file may increase replication time (and even increase the master's
# Copy on Write memory and salve buffers).
# 通常情況下,磁盤比網絡慢,RDB寫入磁盤和加載磁盤獲取RDB都會增加復制時間。
# 甚至會增加主節點在內存和緩沖區上復制和寫入的時間
# However, parsing the RDB file directly from the socket may mean that we have
# to flush the contents of the current database before the full rdb was
# received. For this reason we have the following options:
# 然而直接從網絡獲取RDB文件再復制數據意味着我們必須在接收到完整的RDB文件之前先刷新當前redis數據
#
# "disabled"    - Don't use diskless load (store the rdb file to the disk first) 不使用無磁盤接收,先將數據保存成RDB文件進磁盤
# "on-empty-db" - Use diskless load only when it is completely safe.  當完全安全的情況下可以使用無磁盤接收
# "swapdb"      - Keep a copy of the current db contents in RAM while parsing 直接從套接字獲取數據讀取,在內存中保留數據副本,需要注意的是,一旦內存不夠了,可能
#                 the data directly from the socket. note that this requires  面臨OOM(內存溢出)異常導致redis宕機
#                 sufficient memory, if you don't have it, you risk an OOM kill.
repl-diskless-load disabled

# 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秒
# 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.  對於從節點,一次數據同步I/O操作是一個過程。
# 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). 對於主節點有從節點連接超時
#
# 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. The default
# value is 60 seconds.
# 復制連接超時時間。這個值必須大於從節點的確認通信間隔時間,否則當主從之間沒有數據同步操作的時候,會檢測連接超時(既沒有數據同步,定期ping的時間間隔又沒到,超時時間一過,就認為連接超時了)
# repl-timeout 60

# Disable TCP_NODELAY on the replica socket after SYNC?
# 是否禁止復制tcp鏈接的 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.
# 如果你選擇“是”Redis將使用更少的TCP數據包和更少的帶寬發送數據副本。但是這可能會增加數據在副本端出現的延遲,在使用默認配置的Linux內核中,延遲高達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.
# 默認情況下我們選擇優化延遲,但是如果數據量很大的情況下或者當主節點與從節點經過多層跳轉的情況下,建議開啟。
#(這里不好說,首先要吐槽的是這個配置是反着來的,nodelay:無延遲選擇yes,延遲更高。選擇no,延遲更低)
# 而且yes的場景下,本來數據量就大了,有時候人家就是要盡快看到效果,你還建議選擇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.
# 設置從節點 backlog 大小,這個東西是一個用作緩存的東西,當從節點下線后(假設宕機了一段時間)
# 這個 backlog 會一直保存從節點沒有同步的數據,這樣的話從節點一旦重新上線,只要復制這里面保存的數據就夠了。
#
# The bigger the replication backlog, the longer the replica can endure the
# disconnect and later be able to perform a partial resynchronization.
# 這個值設置的越大,能夠容忍從節點的下線時間就越長。
#
# The backlog is only allocated if there is at least one replica connected.
# 只有在至少有一個從節點連接的時候才會產生 backlog 文件
#
# repl-backlog-size 1mb

# After a master has no 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.
# 當從節點下線超過一定時間后,這個 backlog 文件將會被清除。下面的配置就是配置這個時間的
#
# 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 other replicas: hence they should always accumulate backlog.
# 注意,副本永遠不會因為超時而釋放backlog,因為它們以后可能會被提升到主版本,並且應該能夠正確地與其他副本“部分重新同步”:因此,它們應該始終積累 backlog。
#
# A value of 0 means to never release the backlog.
#
# repl-backlog-ttl 36000

# 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.
# 優先級數字是越小的優先級越高, 10>25>100
#
# 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,則表示該從節點不適合作為主節點,則該從節點永遠不會被哨兵選舉成為父節點
#
# By default the priority is 100.
# 默認情況下,優先級是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.
# 當連接的從節點小於N個的時候,延遲M秒后,主節點停止寫入操作,這樣可以避免沒有足夠健康的從節點作為數據分壓,數據持久性保護。
#
# The N replicas 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 replica, that is usually sent every second.
# 這個延遲時間以秒為單位。這個健康的從節點的ping延遲必須小於這個值才是正常的。
# 從從節點最后一個ping開始計算,這個ping通常是每秒發送一次的。
#
# 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.
# 大致意思就是這個配置並不保證有這么多個認為健康的從節點了就一定能成功的進行寫操作
# 但是在沒有這么多健康從節點的情形下就會在指定延時后限制主節點的寫操作。
#
# For example to require at least 3 replicas with a lag <= 10 seconds use:
# 主節點至少有3個ping延時小於10秒的從節點就能進行正常的寫操作
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# Setting one or the other to 0 disables the feature.
# 設置1或另一個設置為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.
# 主節點可以以各種方式列出從節點列表。例如"INFO replication"指令就可以列出部分信息。哨兵就是通過主節點發現從節點的、
# 同時ROLE指令也可以顯示從節點信息
#
# The listed IP address and port 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.
#      地址自動檢測的時候從節點會發送套接字給主節點
#
#   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.
#
# However when port forwarding or Network Address Translation (NAT) is
# used, the replica may actually be 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.
# 然而當使用了端口轉發或者網絡地址轉換(NET)的時候,從節點可以使用下面這兩個配置向主節點發送一組特定的IP:port
# 告訴主節點可以通過這組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

KEYS TRACKING 鍵 跟蹤

############################### KEYS TRACKING #################################
############################### 鍵 跟蹤 #################################

# Redis implements server assisted support for client side caching of values.
# This is implemented using an invalidation table that remembers, using
# 16 millions of slots, what clients may have certain subsets of keys. In turn
# this is used in order to send invalidation messages to clients. Please
# check this page to understand more about the feature:
# Redis實現了對客戶端值緩存的服務器輔助支持。這是使用一個失效表來實現的,
# 該表使用1600萬個插槽來記住哪些客戶機可能具有某些密鑰子集。反過來,
# 它用於向客戶端發送無效消息。請查看此頁以了解有關該功能的更多信息:
#
#   https://redis.io/topics/client-side-caching
#
# When tracking is enabled for a client, all the read only queries are assumed
# to be cached: this will force Redis to store information in the invalidation
# table. When keys are modified, such information is flushed away, and
# invalidation messages are sent to the clients. However if the workload is
# heavily dominated by reads, Redis could use more and more memory in order
# to track the keys fetched by many clients.
# Redis實現了對客戶端值緩存的服務器輔助支持。這是使用一個失效表來實現的,
# 該表使用1600萬個插槽來記住哪些客戶機可能具有某些密鑰子集。
# 反過來,它用於向客戶端發送無效消息。請查看此頁以了解有關該功能的更多信息:
#
# For this reason it is possible to configure a maximum fill value for the
# invalidation table. By default it is set to 1M of keys, and once this limit
# is reached, Redis will start to evict keys in the invalidation table
# even if they were not modified, just to reclaim memory: this will in turn
# force the clients to invalidate the cached values. Basically the table
# maximum size is a trade off between the memory you want to spend server
# side to track information about who cached what, and the ability of clients
# to retain cached objects in memory.
# 因此,可以為失效表配置最大填充值。默認情況下,它被設置為1M的鍵,一旦達到這個限制,
# Redis將開始逐出失效表中的鍵,即使它們沒有被修改,只是為了回收內存:這反過來會迫使客戶端使緩存的值失效。
# 表的最大大小基本上是在服務器端跟蹤誰緩存了什么內容的信息所需的內存和客戶端在內存中保留緩存對象的能力之間的權衡。
#
# If you set the value to 0, it means there are no limits, and Redis will
# retain as many keys as needed in the invalidation table.
# In the "stats" INFO section, you can find information about the number of
# keys in the invalidation table at every given moment.
# 如果將該值設置為0,則表示沒有限制,Redis將根據需要在失效表中保留盡可能多的鍵。在“stats”INFO部分,您可以找到關於每個給定時刻失效表中的鍵數的信息。
#
# Note: when key tracking is used in broadcasting mode, no memory is used
# in the server side so this setting is useless.
# 注意:當在廣播模式下使用密鑰跟蹤時,服務器端沒有使用內存,因此此設置無效。
# 
# tracking-table-max-keys 1000000

################################## SECURITY ###################################

# Warning: since Redis is pretty fast, an outside user can try up to
# 1 million passwords per second against a modern box. This means that you
# should use very strong passwords, otherwise they will be very easy to break.
# Note that because the password is really a shared secret between the client
# and the server, and should not be memorized by any human, the password
# can be easily a long string from /dev/urandom or whatever, so by using a
# long and unguessable password no brute force attack will be possible.
# 就是警告redis速度非常快,所以很方便執行暴力密碼破解指令,所以redis的密碼應該盡可能的復雜。(即使做了網絡限制,還是建議設置一個復雜的密碼)

# Redis ACL users are defined in the following format:
# redis ACL 用戶定義格式如下
#   user <username> ... acl rules ...
#
# For example:
#
#   user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
#
# The special username "default" is used for new connections. If this user
# has the "nopass" rule, then new connections will be immediately authenticated
# as the "default" user without the need of any password provided via the
# AUTH command. Otherwise if the "default" user is not flagged with "nopass"
# the connections will start in not authenticated state, and will require
# AUTH (or the HELLO command AUTH option) in order to be authenticated and
# start to work.
# 特殊用戶"default"用作新連接使用,如果這個用戶擁有跳過密碼權限,那么可以不進行認證直接登錄使用
#
# The ACL rules that describe what a user can do are the following:
# 描述用戶可以執行的操作的ACL規則如下:
#
#  on           Enable the user: it is possible to authenticate as this user. 					啟用用戶:可以為這個用戶進行身份認證
#  off          Disable the user: it's no longer possible to authenticate  						關閉用戶,無法再使用此用戶進行身份驗證,但是已經通過身份驗證的連接仍然有效。
#               with this user, however the already authenticated connections
#               will still work.
#  +<command>   Allow the execution of that command          									允許執行該命令
#  -<command>   Disallow the execution of that command											不允許執行該命令
#  +@<category> Allow the execution of all the commands in such category  						允許執行該類命令
#               with valid categories are like @admin, @set, @sortedset, ...
#               and so forth, see the full list in the server.c file where
#               the Redis command table is described and defined.
#               The special category @all means all the commands, but currently
#               present in the server, and that will be loaded in the future
#               via modules.
#  +<command>|subcommand    Allow a specific subcommand of an otherwise
#                           disabled command. Note that this form is not
#                           allowed as negative like -DEBUG|SEGFAULT, but
#                           only additive starting with "+".    								允許禁用命令的特定子命令。請注意,此表單不允許為負數,如-DEBUG | SEGFAULT,而只能是以“+”開頭的加法形式。
#  allcommands  Alias for +@all. Note that it implies the ability to execute 
#               all the future commands loaded via the modules system.    						+@all的別名它意味着能夠執行通過模塊系統加載的所有未來命令。
#  nocommands   Alias for -@all.										  						-@all的別名
#  ~<pattern>   Add a pattern of keys that can be mentioned as part of        					添加能匹配到的命令作為擁有的權限
#               commands. For instance ~* allows all the keys. The pattern
#               is a glob-style pattern like the one of KEYS.
#               It is possible to specify multiple patterns.
#  allkeys      Alias for ~*																	~*的別名				
#  resetkeys    Flush the list of allowed keys patterns.										刷新允許的指令列表
#  ><password>  Add this password to the list of valid password for the user.					為用戶設置密碼
#               For example >mypass will add "mypass" to the list.
#               This directive clears the "nopass" flag (see later).
#  <<password>  Remove this password from the list of valid passwords.							將密碼用有效密碼列表中移除
#  nopass       All the set passwords of the user are removed, and the user						設置用戶跳過密碼校驗,如果設置默認用戶跳過密碼校驗。所有的新連接都將直接使用默認用戶直接連接,安全認證直接失效
#               is flagged as requiring no password: it means that every						"resetpass" 指令可以清楚該設置
#               password will work against this user. If this directive is
#               used for the default user, every new connection will be
#               immediately authenticated with the default user without
#               any explicit AUTH command required. Note that the "resetpass"
#               directive will clear this condition.
#  resetpass    Flush the list of allowed passwords. Moreover removes the       				刷新密碼:刷新密碼列表。此外,刪除“nopass”狀態。
#               "nopass" status. After "resetpass" the user has no associated  					在“resetpass”之后,用戶沒有關聯的密碼,
#               passwords and there is no way to authenticate without adding   					並且沒有辦法在不添加密碼(或稍后將其設置為“nopass”)的情況下進行身份驗證。
#               some password (or setting it as "nopass" later).  
#  reset        Performs the following actions: resetpass, resetkeys, off,     					相當於執行了resetpass, resetkeys, off, -@all操作,這個用戶立即恢復為初始創建狀態
#               -@all. The user returns to the same state it has immediately
#               after its creation.
#
# ACL rules can be specified in any order: for instance you can start with
# passwords, then flags, or key patterns. However note that the additive
# and subtractive rules will CHANGE MEANING depending on the ordering.
# For instance see the following example:
# ACL規則可以按任何順序指定:例如,可以從密碼開始,然后是標志或密鑰模式。但是請注意,加法和減法規則將根據順序改變含義。
#
#   user alice on +@all -DEBUG ~* >somepassword
#
# This will allow "alice" to use all the commands with the exception of the
# DEBUG command, since +@all added all the commands to the set of the commands
# alice can use, and later DEBUG was removed. However if we invert the order
# of two ACL rules the result will be different:
# 上面這個案例的含義就是允許alice用戶使用除了DEBUG外的所有指令,由於配置是一步一步來,后面的覆蓋前面的,
# 如果上面的”+@all“與” -DEBUG“顛倒了位置,結果就是允許alice用戶使用所有指令,下面這個案例的說明就是這個意思
#   user alice on -DEBUG +@all ~* >somepassword
#
# Now DEBUG was removed when alice had yet no commands in the set of allowed
# commands, later all the commands are added, so the user will be able to
# execute everything.
# 現在,當alice在允許的命令集中還沒有命令時,DEBUG被刪除了,稍后所有的命令都被添加,這樣用戶就可以執行所有的命令了。
#
# Basically ACL rules are processed left-to-right.
# ACL規則是從左向右處理的。
#
# For more information about ACL configuration please refer to
# 更多的關於ACL配置的信息請參閱官方網址
# the Redis web site at https://redis.io/topics/acl

# ACL LOG
#
# The ACL Log tracks failed commands and authentication events associated
# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked 
# by ACLs. The ACL Log is stored in memory. You can reclaim memory with 
# ACL LOG RESET. Define the maximum entry length of the ACL Log below.
# ACL日志跟蹤與ACL關聯的失敗命令和身份驗證事件。ACL日志對於排除ACL阻止的失敗命令非常有用。ACL日志存儲在內存中。您可以使用ACL日志重置來回收內存。在下面定義ACL日志的最大條目長度。
acllog-max-len 128

# Using an external ACL file
# 使用外部ACL文件配置
#
# Instead of configuring users here in this file, it is possible to use
# a stand-alone file just listing users. The two methods cannot be mixed:
# if you configure users here and at the same time you activate the external
# ACL file, the server will refuse to start.
# 用戶只需在這里配置一個單獨的文件就可以了。這兩種方法不能混合使用:如果在這里配置用戶,同時激活外部ACL文件,服務器將拒絕啟動。
#
# The format of the external ACL user file is exactly the same as the
# format that is used inside redis.conf to describe users.
#
# aclfile /etc/redis/users.acl

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# requirepass foobared

# Command renaming (DEPRECATED).
#
# ------------------------------------------------------------------------
# WARNING: avoid using this option if possible. Instead use ACLs to remove
# commands from the default user, and put them only in some admin user you
# create for administrative purposes.
# ------------------------------------------------------------------------
#
# 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.

################################### 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個客戶端,
# 但是如果Redis服務器無法配置進程文件限制以允許指定的限制,
# 則允許的最大客戶端數將設置為當前文件限制減去32(因為Redis保留了一些文件描述符供內部使用)
# 就是說默認設置10000實際上最高連接數是9968
#
# 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”。
#
# IMPORTANT: When Redis Cluster is used, the max number of connections is also
# shared with the cluster bus: every node in the cluster will use two
# connections, one incoming and another outgoing. It is important to size the
# limit accordingly in case of very large clusters.
# 重要提示:當使用Redis集群時,最大連接數也與集群總線共享:集群中的每個節點將使用兩個連接,一個傳入,另一個傳出。(就是對與主節點而言,沒個從節點都保持了兩個連接來維持主從通信的)
# 在非常大的簇的情況下,相應地調整限制的大小是很重要的。
# 客戶端連接數
# 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將根據所選的逐出策略刪除數據(請參閱maxmemory策略)。
#
# 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無法根據策略刪除密鑰,或者如果策略設置為“noeviction”,Redis將開始對使用更多內存的命令(如set、LPUSH等)進行錯誤應答,並繼續回復GET等只讀命令。
# 就是說內存不夠了后,還不允許刪除舊有的數據的話,再插入就會報錯了,只能調用取命令
#
# 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緩存時,或者設置實例的硬內存限制(使用“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.
# 警告:如果啟用了maxmemory的實例有從節點,則從已用內存計數中減去提供從節點所需
# 的輸出緩沖區的大小,這樣網絡問題/重新同步將不會觸發一個循環,在該循環中,數據被逐出,
# 而副本的輸出緩沖區將充滿,並觸發刪除更多的密鑰,以此類推,直到數據庫完全清空。
#
# 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').
# 簡而言之。。。如果附加了副本,建議您為maxmemory設置一個下限,以便系統上有一些可用的RAM用於副本輸出緩沖區(但是,如果策略為“noeviction”,則不需要這樣做)。
# maxmemory <bytes>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
# MAXMEMORY策略:達到MAXMEMORY時Redis將如何選擇要刪除的內容。可以從以下行為中選擇一個:
#
# volatile-lru -> Evict using approximated LRU, only keys with an expire set.   從已設置過期時間的內存數據集中挑選最近最少使用的數據 淘汰;
# allkeys-lru -> Evict any key using approximated LRU.							從內存數據集中挑選最近最少使用的數據 淘汰;
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.   從已設置過期時間的內存數據集中挑選最近最多使用的數據 淘汰;
# allkeys-lfu -> Evict any key using approximated LFU.							從內存數據集中挑選最近最多使用的數據 淘汰;
# volatile-random -> Remove a random key having an expire set.					從已設置過期時間的內存數據集中任意挑選數據 淘汰;
# allkeys-random -> Remove a random key, any key.								從數據集中任意挑選數據 淘汰;	
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)       已設置過期時間的內存數據集中刪除最接近過期時間的數據(次要TTL)
# noeviction -> Don't evict anything, just return an error on write operations. 不淘汰任何數據,直接返回寫入數據異常
#
# LRU means Least Recently Used         LRU標識最少使用
# LFU means Least Frequently Used		LFU表示最多使用
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
# LRU、LFU和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.
# 注意:對於以上任何一種策略,當沒有合適的密鑰進行逐出時,Redis將在寫操作時返回錯誤。
#
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
#
# The default is:
# 默認設置是不淘汰數據,直接返回異常
# maxmemory-policy noeviction

# 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. By default Redis will check five keys and pick the one that was
# used least recently, you can change the sample size using the following
# configuration directive.
# LRU、LFU和minimal TTL算法不是精確算法,而是近似算法(為了節省內存),因此您可以根據速度或精度對其進行調整。默認情況下,Redis將檢查五個鍵並選擇最近使用過的一個,您可以使用以下配置指令更改樣本大小。
#
# 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.
# 默認值為5會產生足夠好的結果。10接近真實的LRU,但占用更多的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.
# 從Redis 5開始,默認情況下,復制副本將忽略其maxmemory設置(除非在故障轉移后或手動將其升級為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).
# 此行為可確保主副本和副本保持一致,並且通常是您想要的,但是,如果您的復制副本是可寫的,
# 或者您希望復制副本具有不同的內存設置,並且您確定對副本執行的所有寫操作都是冪等的,
# 則可以更改此默認值(但一定要了解您正在做什么)。
#
# 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設置的內存更多的內存
# (副本上有一些緩沖區可能更大,或者數據結構有時可能占用更多內存等等)。因此,請確保您監視您的副本,
# 並確保它們有足夠的內存,在主機命中配置的maxmemory設置之前,它們不會出現內存不足的情況。
# 
# 從節點會略最大內存設置
# replica-ignore-maxmemory yes

# Redis reclaims expired keys in two ways: upon access when those keys are
# found to be expired, and also in background, in what is called the
# "active expire key". The key space is slowly and interactively scanned
# looking for expired keys to reclaim, so that it is possible to free memory
# of keys that are expired and will never be accessed again in a short time.
# Redis通過兩種方式回收過期的密鑰:當訪問時發現這些密鑰已過期,並且在后台,即所謂的“活動過期密鑰”。
# 密鑰空間被緩慢地交互掃描,尋找過期的密鑰以回收,這樣就可以釋放過期密鑰的內存,而這些密鑰在很短時間內就設置未永遠不能被訪問。
#
# The default effort of the expire cycle will try to avoid having more than
# ten percent of expired keys still in memory, and will try to avoid consuming
# more than 25% of total memory and to add latency to the system. However
# it is possible to increase the expire "effort" that is normally set to
# "1", to a greater value, up to the value "10". At its maximum value the
# system will use more CPU, longer cycles (and technically may introduce
# more latency), and will tolerate less already expired keys still present
# in the system. It's a tradeoff between memory, CPU and latency.
# expire循環的默認工作將盡量避免超過10%的過期密鑰仍在內存中,並將盡量避免消耗超過25%的總內存,並增加系統的延遲。
# 但是,可以將通常設置為“1”的expire“efforce”增加到更大的值,直到值“10”。在其最大值時,系統將使用更多的CPU、更長的周期(從技術上講,可能會引入更多的延遲)
# ,並將容忍系統中仍然存在的已過期密鑰更少。這是內存、CPU和延遲之間的折衷。
# 大致意思是expire循環任務調度清理密鑰也是需要消耗性能的,想過期密鑰清理的越干凈那么cpu消耗就越高,看你自己折中選擇
# effort改變了過期鍵可占內存的最大百分比,改變了最大占用cpu的百分比等,effort越大,cpu負擔越重,所以根據自己的需要設置effort的值。 引至:https://cloud.tencent.com/developer/article/1692645
# active-expire-effort 1

############################# 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有兩個基本體來刪除密鑰。一種叫做DEL,是對對象的阻塞性刪除。這意味着服務器停止處理新命令,
# 以便以同步方式回收與對象關聯的所有內存。如果刪除的密鑰與一個小對象關聯,
# 則執行DEL命令所需的時間非常小,與Redis中大多數其他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(non-blocking DEL)等非阻塞刪除原語,
# 以及FLUSHALL和FLUSHDB命令的異步選項,以便在后台回收內存。這些命令在固定時間內執行。
# 另一個線程將以最快的速度增量釋放后台的對象。
#
# 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:
# FLUSHALL和FLUSHDB的DEL、UNLINK和ASYNC選項由用戶控制。這取決於應用程序的設計來
# 理解何時使用其中一個是好主意。然而,由於其他操作的副作用,Redis服務器有時不得
# 不刪除密鑰或刷新整個數據庫。具體來說,在以下情況下,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.     
#    在逐出時,由於maxmemory和maxmemory策略配置,為了在不超過指定內存限制的情況下為新數據騰出空間。

# 2) Because of expire: when a key with an associated time to live (see the
#    EXPIRE command) must be deleted from memory.
#    因為expire:必須從內存中刪除具有相關生存時間的密鑰(請參閱expire命令)。

# 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.
#    因為命令的副作用是可能將數據存儲在已經存在的鍵上。
#    例如,重命名命令可能會刪除舊的密鑰內容,當它被另一個替換時。類似地,
#    SUNIONSTORE或SORT with STORE選項可能會刪除現有的密鑰。SET命令本身刪除指定鍵的任何舊內容,以便用指定的字符串替換它。

# 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.
#    在復制過程中,當從節點與其主節點執行數據完全重新同步時,從節點整個數據庫的內容將被刪除,以便加載剛剛傳輸的RDB文件
#
# 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.
# 在上述所有情況下,默認情況是以阻塞方式刪除對象,就像調用DEL一樣。但是,您可以具體地配置每種情況,以便使用以下配置指令以非阻塞方式釋放內存,就像調用UNLINK一樣。

lazyfree-lazy-eviction no    
# 是否異步驅逐key,當內存達到上限,分配失敗后
lazyfree-lazy-expire no
# 是否異步進行key過期事件的處理
lazyfree-lazy-server-del no
# del命令是否異步執行刪除操作,類似unlink
replica-lazy-flush no
# 從節點做全同步的時候,是否異步flush本地db

# It is also possible, for the case when to replace the user code DEL calls
# with UNLINK calls is not easy, to modify the default behavior of the DEL
# command to act exactly like UNLINK, using the following configuration
# directive:
# 在用UNLINK調用替換用戶代碼DEL調用並不容易的情況下,還可以使用以下配置指令修改DEL命令的默認行為,使其與UNLINK完全相同:

#執行DEL命令時是否基於lazyfree異步刪除數據,可選值:
lazyfree-lazy-user-del no

################################ THREADED I/O #################################

# Redis is mostly single threaded, however there are certain threaded
# operations such as UNLINK, slow I/O accesses and other things that are
# performed on side threads.
# redis的大多數操作()都是單線程的,但也有部分操作多線程操作
#
# Now it is also possible to handle Redis clients socket reads and writes
# in different I/O threads. Since especially writing is so slow, normally
# Redis users use pipelining in order to speed up the Redis performances per
# core, and spawn multiple instances in order to scale more. Using I/O
# threads it is possible to easily speedup two times Redis without resorting
# to pipelining nor sharding of the instance.
#
# By default threading is disabled, we suggest enabling it only in machines
# that have at least 4 or more cores, leaving at least one spare core.
# Using more than 8 threads is unlikely to help much. We also recommend using
# threaded I/O only if you actually have performance problems, with Redis
# instances being able to use a quite big percentage of CPU time, otherwise
# there is no point in using this feature.
# 大致意思是:1、cpu核心至少4核以上。2、缺失存在由於線程數造成的io性能瓶頸
# (然而大部分性能瓶頸都是內存與網絡造成的,除非你用明朝的cpu配清朝的內存)。否則使用多線程沒什么意義
#
# So for instance if you have a four cores boxes, try to use 2 or 3 I/O
# threads, if you have a 8 cores, try to use 6 threads. In order to
# enable I/O threads use the following configuration directive:
# io線程數,默認為1。可根據你的cpu線程數調配,4核的就設置2或者3,8核的就設置6。
# io-threads 4
#
# Setting io-threads to 1 will just use the main thread as usual.
# When I/O threads are enabled, we only use threads for writes, that is
# to thread the write(2) syscall and transfer the client buffers to the
# socket. However it is also possible to enable threading of reads and
# protocol parsing using the following configuration directive, by setting
# it to yes:
# 大致意思是:無法理解。
# 反正這個配置的意思是讀操作是否也啟用I/O多線程
# io-threads-do-reads no
#
# Usually threading reads doesn't help much. 通常情況下,多線程讀取沒什么卵用
#
# NOTE 1: This configuration directive cannot be changed at runtime via
# CONFIG SET. Aso this feature currently does not work when SSL is
# enabled.
# 這個配置不能在redis運行時進行改變。該版本下,使用SSL時,該功能失效
#
# NOTE 2: If you want to test the Redis speedup using redis-benchmark, make
# sure you also run the benchmark itself in threaded mode, using the
# --threads option to match the number of Redis threads, otherwise you'll not
# be able to notice the improvements.
# 如果你使用redis-benchmark測試性能的化,請確認你的操作運行在該線程模式下。使用
# --threads 參數設置redis線程數。否則,你是看不到多線程的改進的。菜雞新人基本用不上這個。

KERNEL OOM CONTROL 內核OOM控件

############################ KERNEL OOM CONTROL ##############################

# On Linux, it is possible to hint the kernel OOM killer on what processes
# should be killed first when out of memory.
# 在linux上,可以再內粗溢出的時候提示 OOM殺手干掉那些進程
#
# Enabling this feature makes Redis actively control the oom_score_adj value
# for all its processes, depending on their role. The default scores will
# attempt to have background child processes killed before all others, and
# replicas killed before masters.
# 啟用此功能將使Redis主動控制其所有進程的oom_score_adj值,具體取決於它們的角色。
# 默認分數將嘗試在所有其他進程之前殺死后台子進程,並在主進程之前殺死副本。

oom-score-adj no

# When oom-score-adj is used, this directive controls the specific values used
# for master, replica and background child processes. Values range -1000 to
# 1000 (higher means more likely to be killed).
# 當使用oom score adj時,此指令控制主進程、副本進程和后台子進程使用的特定值。值的范圍是-1000到1000(越高意味着死亡的可能性越大)。
#
# Unprivileged processes (not root, and without CAP_SYS_RESOURCE capabilities)
# can freely increase their value, but not decrease it below its initial
# settings.
# 非特權進程(不是根進程,也沒有CAP_SYS_資源功能)可以自由地增加它們的值,但不能將其降低到初始設置以下。
#
# Values are used relative to the initial value of oom_score_adj when the server
# starts. Because typically the initial value is 0, they will often match the
# absolute values.
# 當服務器啟動時,使用相對於oom_score_adj的初始值的值。因為通常初始值是0,所以它們通常與絕對值匹配。

oom-score-adj-values 0 200 800

APPEND ONLY MODE 附加模式

############################## 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文件是另一種持久性模式,它提供了更好的持久性。例如,如果使用默認的數據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持久性可以同時啟用而不會出現問題。如果啟動時啟用了AOF,Redis將加載AOF,即具有更好的持久性保證的文件。
# 
# Please check http://redis.io/topics/persistence for more information.

# 開啟AOF 默認no
appendonly yes

# The name of the append only file (default: "appendonly.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()調用告訴操作系統在磁盤上直接寫入數據,而不是等待輸出緩沖區中的更多數據。
# 有些操作系統會在磁盤上刷新數據,而有些操作系統則會盡快刷新。
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.    從不fsync,只需將數據交給操作系統即可(官網說明:從不fsync,只需將數據交給操作系統即可。更快,更不安全的方法。通常,Linux使用此配置每30秒刷新一次數據,但這取決於內核的精確調整。)
# always: fsync after every write to the append only log. Slow, Safest.     次將新命令附加到AOF時。非常非常慢,非常安全。請注意,在執行了來自多個客戶端或管道的一批命令之后,這些命令會附加到AOF,因此這意味着一次寫入和一次fsync(在發送答復之前)。
# everysec: fsync only one time every second. Compromise.            		fsync每秒。速度足夠快(在2.4中可能與快照速度一樣快),如果發生災難,您可能會丟失1秒的數據。
#
# 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”,因為這通常是速度和數據安全之間的正確折衷。這取決於您是否可以將此設置放寬為“否”,
# 這樣操作系統可以在需要時刷新輸出緩沖區,以獲得更好的性能(但是如果您可以接受某些數據丟失的想法,
# 請考慮默認的快照持久性模式),或者恰恰相反,使用“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也會阻止我們的同步write(2)調用。
#
# 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或bwriteAOF時在主進程中調用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”相同。(就是有子進程在背后寫AOF,主進程也在寫AOF文件,兩者同時操作磁盤,會存在阻塞的情形。)
# 實際上,這意味着在最壞的情況下(使用默認的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.
# 如果您有延遲問題,請將此選項設置為“是”。否則,將其保留為“否”,從耐用性的角度來看,這是最安全的選擇。

# 當主進程執行寫AOF文件的時候不進行appendfsync操作
no-appendfsync-on-rewrite no
# 使用推薦:無法忍受延遲,而可以容忍少量的數據丟失,則設置為yes。如果應用系統無法忍受數據丟失,則設置為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.
# 自動重寫僅附加文件。Redis能夠在AOF日志大小按指定的百分比增長時自動重寫日志文件,並隱式調用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文件的大小(如果重新啟動后沒有重寫,則使用啟動時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.
# 指定零的百分比以禁用自動AOF重寫功能。

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啟動過程中,當AOF數據加載回內存時,可能會發現AOF文件在末尾被截斷。
# 當運行Redis的系統崩潰時,尤其是在沒有data=ordered選項的情況下掛載ext4文件系統時,
# 可能會發生這種情況(但是,當Redis本身崩潰或中止,但操作系統仍然正常工作時,這種情況就不會發生)。
#
# 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.
# Redis可以在出現錯誤時退出,也可以加載盡可能多的數據(現在是默認值),
# 如果發現AOF文件在結尾處被截斷,則可以啟動。以下選項控制此行為。
#
# 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.
# 如果aof load truncated設置為yes,則加載一個截斷的aof文件,Redis服務器開始
# 發出一個日志來通知用戶事件。否則,如果該選項設置為“否”,則服務器會因錯誤而
# 中止並拒絕啟動。當該選項設置為no時,用戶需要在重新啟動服務器之前使用“redis check AOF”實用程序修復AOF文件。
#
# Note that if the AOF file will be found to be corrupted in the middle
# the server will still exit with an error. This option only applies when
# Redis will try to read more data from the AOF file but not enough bytes
# will be found.
# 請注意,如果發現AOF文件在中間被損壞,服務器仍將退出並返回一個錯誤。此選項僅適用於Redis將嘗試從AOF文件讀取更多數據,但找不到足夠字節的情況。

# AOF文件加載是否允許文件存在錯誤信息,
# 允許則會自動從第一個錯誤開始截取至最后(可能造成很嚴重的數據丟失)
# 不允許,則啟動報錯,需要先人工修復AOF文件后才能正常的啟動,官方根據不通的版本給出了不通的修復策略、修復工具。詳情:https://redis.io/topics/persistence
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:
# 在重寫AOF文件時,Redis能夠在AOF文件中使用RDB前導碼以加快重寫和恢復。
# 啟用此選項時,重寫的AOF文件由兩個不同的段落組成:(RDB文件頭+AOF尾)
#
#   [RDB file][AOF tail]
#
# When loading, Redis recognizes that the AOF file starts with the "REDIS"
# string and loads the prefixed RDB file, then continues loading the AOF
# tail.
# 加載時,Redis識別出AOF文件以“Redis”字符串開頭並加載帶前綴的RDB文件,然后繼續加載AOF尾部。

aof-use-rdb-preamble yes

LUA SCRIPTING LUA腳本

################################ LUA SCRIPTING  ###############################
################################ LUA      腳本  ###############################

# 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 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 call any 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.
# 當長時間運行的腳本超過最大執行時間時,只有腳本KILL和SHUTDOWN NOSAVE命令可用。
# 第一個命令可用於停止尚未調用任何write命令的腳本。第二種方法是在腳本已經發出
# write命令但用戶不想等待腳本自然終止的情況下關閉服務器的唯一方法。
#
# Set it to 0 or a negative value for unlimited execution without warnings.
# 將其設置為0或負值,以無限制地執行而不發出警告。默認5000毫秒
lua-time-limit 5000

REDIS CLUSTER redis集群配置

################################ REDIS CLUSTER  ###############################
################################ REDIS    集群  ###############################

# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
# 普通的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 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 a multiple of the node timeout.
# 大多數其他內部時間限制是節點超時的倍數。
#
# cluster-node-timeout 15000

# A replica of a failing master will avoid to start a failover if its data
# looks too old.
# 如果主節點出錯了,但是從節點的數據看起來也太久了,它將避免啟動故障轉移(從節點競選主節點)
#
# 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.
#    每個副本都計算最后一次與主副本交互的時間。這可以是上一次接收到的ping或命令
#   (如果主服務器仍處於“已連接”狀態),也可以是自與主服務器斷開連接后經過的時間
#   (如果復制鏈接當前處於關閉狀態)。如果最后一次交互太舊,復制副本根本不會嘗試故障轉移
#
# 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 * cluster-replica-validity-factor) + repl-ping-replica-period
#   節點超時時間 * 集群-復制—有效—系數 + 從節點ping周期
#
# So for example if node-timeout is 30 seconds, and the cluster-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.
# 因此,例如,如果節點超時為30秒,而群集副本有效性系數為10,並且假定默認的復制副本周期為10秒,
# 則如果副本無法與主機通信超過310秒,則該副本不會嘗試進行故障轉移。
#
# A large cluster-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.
# 較大的群集副本有效性系數可能會允許具有太舊數據的副本對主服務器進行故障轉移,而太小的值可能會使群集根本無法選擇副本。
#
# For maximum availability, it is possible to set the cluster-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).
# 為了獲得最大可用性,可以將群集副本有效性因子設置為0,這意味着副本將始終嘗試故障轉移主服務器,而不管它們上次與主服務器交互的時間。(但是他們總是嘗試應用與偏移量成比例的延遲)。
#
# Zero is the only value able to guarantee that when all the partitions heal
# the cluster will always be able to continue.
# 零是唯一能夠保證當所有分區恢復時,集群始終能夠繼續運行的值。
#
# 集群-復制—有效—系數
# 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.
# 從節點能夠變成主節點。這提高了集群抵御故障的能力,
# 否則,如果單獨的主節點沒有從節點,則無法在發生故障時進行故障切換。
#
# 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.
# 大致意思是設置了個集群最小從節點數,主節點宕機后,集群必須至少還擁有不少於這個數的節點
# 才能進行故障遷移。
#
# 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 a 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集群節點檢測到至少有一個未覆蓋的哈希槽(沒有可用節點為其提供服務),
# 則它們將停止接受查詢。這樣,如果集群部分關閉(例如不再覆蓋一系列哈希槽),
# 那么最終所有集群都將不可用。一旦所有插槽再次被覆蓋,它就會自動返回可用。
#
# However sometimes you want the subset of the cluster which is working,
# to continue to accept queries for the part of the key space that is still
# covered. In order to do so, just set the cluster-require-full-coverage
# option to no.
# 但是,有時您希望正在工作的集群的子集繼續接受對仍然被覆蓋的密鑰空間部分的查詢。為此,只需將cluster require full coverage選項設置為no。
# 
# 默認情況下,集群全部的slot有節點負責,集群狀態才為ok,才能提供服務。設置為no,可以在slot沒有全部分配的時候提供服務。不建議打開該配置,這樣會造成分區的時候,小分區的master一直在接受寫請求,而造成很長時間數據不一致。
# 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.
# 這在不同的場景中非常有用,特別是在多個數據中心操作的情況下,如果在整個DC故障的情況下,我們希望永遠不會升級一個端。
# 
# 集群-副本-不發生故障轉移
# cluster-replica-no-failover no

# This option, when set to yes, allows nodes to serve read traffic while the
# the cluster is in a down state, as long as it believes it owns the slots. 
# 此選項在設置為yes時,允許節點在集群處於關閉狀態時提供讀取流量,只要它認為它擁有插槽。
#
# This is useful for two cases.  The first case is for when an application 
# doesn't require consistency of data during node failures or network partitions.
# One example of this is a cache, where as long as the node has the data it
# should be able to serve it. 
# 這有兩種情況。第一種情況是在節點故障或網絡分區期間,應用程序不需要數據的一致性。緩存就是一個例子,只要節點有數據,它就應該能夠為它提供服務。
#
# The second use case is for configurations that don't meet the recommended  
# three shards but want to enable cluster mode and scale later. A 
# master outage in a 1 or 2 shard configuration causes a read/write outage to the
# entire cluster without this option set, with it set there is only a write outage.
# Without a quorum of masters, slot ownership will not change automatically. 
# 第二個用例是針對那些不滿足推薦的三個碎片,但希望以后啟用集群模式和擴展的配置。
# 1或2碎片配置中的主中斷會導致對的讀/寫中斷 沒有設置此選項的整個群集,
# 如果設置了此選項,則只會發生寫入中斷。如果沒有足夠數量的主機,插槽所有權將不會自動更改。
#
# 當集群關閉的時候允許讀取數據
# cluster-allow-reads-when-down no

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

CLUSTER DOCKER/NAT support 集群DOCKER/NAT支持

########################## CLUSTER DOCKER/NAT support  ########################
########################## 集群    DOCKER/NAT    支持  ########################

# 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集群節點地址發現失敗,原因是地址是NAT的,或者是端口被轉發(典型的情況是Docker和其他容器)。
#
# 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:
# 為了使Redis集群能夠在這樣的環境中工作,需要一個靜態配置,每個節點都知道自己的公共地址。以下兩個選項(其實有三個)用於此范圍,分別是:
#
# * cluster-announce-ip  
# * cluster-announce-port
# * cluster-announce-bus-port
#
# Each instructs 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.
# 每個都指示節點關於其地址、客戶機端口和集群消息總線端口。然后在總線包的報頭中發布信息,以便其他節點能夠正確地映射發布信息的節點的地址。
#
# 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 usual.
# 請注意,當客戶機在總線上重新映射端口時,可能無法指定端口的偏移量。如果沒有設置總線端口,將像往常一樣使用固定偏移量10000。
#
# Example:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380

SLOW LOG

################################## 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 Slow Log是一個記錄超過指定執行時間的查詢的系統。執行時間不包括與客戶機對話、
# 發送應答等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.
# 您可以使用兩個參數來配置slow log:一個參數告訴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秒。請注意,負數將禁用慢速日志,而值為零將強制記錄每個命令。
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延遲監視器

################################ 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.
# Redis延遲監控子系統在運行時對不同的操作進行采樣,以收集與Redis實例可能的延遲源相關的數據。
#
# Via the LATENCY command this information is available to the user that can
# print graphs and obtain reports.
# 通過LATENCY命令,用戶可以打印圖形並獲取報告。
#
# The system only logs operations that were performed in a time equal or
# greater than the amount of milliseconds specified via the
# latency-monitor-threshold configuration directive. When its value is set
# to zero, the latency monitor is turned off.
# 系統只記錄在大於或等於通過延遲監視器閾值配置指令指定的毫秒數的時間內執行的操作。當其值設置為零時,將關閉延遲監視器。
#
# By default latency monitoring is disabled since it is mostly not needed
# if you don't have latency issues, and collecting data has a performance
# impact, that while very small, can be measured under big load. Latency
# monitoring can easily be enabled at runtime using the command
# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
# 默認情況下,延遲監視是禁用的,因為如果沒有延遲問題,則通常不需要延遲監視,並且收集數據會對性能產生影響,雖然影響很小,
# 但可以在大負載下進行測量。如果需要,可以使用命令“CONFIG SET Latency monitor threshold<millises>”在運行時輕松啟用延遲監視。
latency-monitor-threshold 0

EVENT NOTIFICATION事件通知

############################# EVENT NOTIFICATION ##############################
############################# 事件          通知 ##############################

# Redis can notify Pub/Sub clients about events happening in the key space.
# Redis可以將密鑰空間中發生的事件通知發布/訂閱客戶端。
# This feature is documented at http://redis.io/topics/notifications
#
# For instance if keyspace events notification is enabled, and a client
# performs a DEL operation on key "foo" stored in the Database 0, two
# messages will be published via Pub/Sub:
# 例如,如果啟用了keystpace events通知,並且客戶機對存儲在數據庫0中的鍵“foo”執行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.  			鍵空間通知,以 __keyspace@<db>__ 作為前綴發布。
#  E     Keyevent events, published with __keyevent@<db>__ prefix.  			鍵事件通知,以 __keyevent@<db>__ 作為前綴發布。
#  g     Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...   	DEL、EXPIRE、RENAME 等類型無關的通用命令的通知
#  $     String commands														字符串命令的通知
#  l     List commands															列表命令的通知
#  s     Set commands															set集合命令的通知
#  h     Hash commands															哈希命令的通知
#  z     Sorted set commands													有序set集合命令的通知
#  x     Expired events (events generated every time a key expires)				過期事件:每當有過期鍵被刪除時發送
#  e     Evicted events (events generated when a key is evicted for maxmemory)	 驅逐(evict)事件:每當有鍵因為 maxmemory 政策而被刪除時發送
#  t     Stream commands														流事件時發布
#  m     Key-miss events (Note: It is not included in the 'A' class)			key未命中事件,(不包含在A類別中)
#  A     Alias for g$lshzxet, so that the "AKE" string means all the events     參數 g$lshzxe 的別名
#        (Except key-miss events which are excluded from 'A' due to their
#         unique nature).
#
#  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:
# 例如:啟動列表命令通知、Generic命令通知、鍵事件通知案例
#
#  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.
#  默認情況下,所有通知都被禁用,因為大多數用戶不需要此功能,而且該功能有一些開銷。
#  請注意,如果不指定K或E中的任何一個,則不會傳遞任何事件。
notify-keyspace-events ""

GOPHER SERVER GOPHER服務支持

############################### GOPHER SERVER #################################
############################### GOPHER 服務 #################################

# Redis contains an implementation of the Gopher protocol, as specified in
# the RFC 1436 (https://www.ietf.org/rfc/rfc1436.txt).
#
# The Gopher protocol was very popular in the late '90s. It is an alternative
# to the web, and the implementation both server and client side is so simple
# that the Redis server has just 100 lines of code in order to implement this
# support.
# Gopher協議在90年代末非常流行,它是web的一種替代方案,服務器端和客戶端的實現都非常簡單,Redis服務器只有100行代碼來實現這種支持。
#
# What do you do with Gopher nowadays? Well Gopher never *really* died, and
# lately there is a movement in order for the Gopher more hierarchical content
# composed of just plain text documents to be resurrected. Some want a simpler
# internet, others believe that the mainstream internet became too much
# controlled, and it's cool to create an alternative space for people that
# want a bit of fresh air.
#
# Anyway for the 10nth birthday of the Redis, we gave it the Gopher protocol
# as a gift.
# 無論如何,在Redis 10歲生日那天,我們把Gopher協議作為禮物送給它。
#
# --- HOW IT WORKS? ---
# --- 這個怎么用? ---
#
# The Redis Gopher support uses the inline protocol of Redis, and specifically
# two kind of inline requests that were anyway illegal: an empty request
# or any request that starts with "/" (there are no Redis commands starting
# with such a slash). Normal RESP2/RESP3 requests are completely out of the
# path of the Gopher protocol implementation and are served as usual as well.
# Redis Gopher支持使用Redis的內聯協議,特別是兩種無論如何都是非法的內聯請求:
# 空請求或任何以“/”開頭的請求(沒有以這樣的斜杠開頭的Redis命令)。正常的RESP2/RESP3
# 請求完全脫離了Gopher協議實現的路徑,並且也像往常一樣提供服務。
#
# If you open a connection to Redis when Gopher is enabled and send it
# a string like "/foo", if there is a key named "/foo" it is served via the
# Gopher protocol.
# 如果你連接一個啟用Gopher服務的Redis,並向其發送類似“/foo”的字符串,那么如果有一個名為“/foo”的密鑰,則通過Gopher協議提供服務。
#
# In order to create a real Gopher "hole" (the name of a Gopher site in Gopher
# talking), you likely need a script like the following:
# 為了創建一個真正的Gopher“hole”(Gopher talking中的一個Gopher站點的名稱),您可能需要以下腳本:
#
#   https://github.com/antirez/gopher2redis
#
# --- SECURITY WARNING ---
# --- 安全        警告 ---
#
# If you plan to put Redis on the internet in a publicly accessible address
# to server Gopher pages MAKE SURE TO SET A PASSWORD to the instance.
# Once a password is set:
# 如果您計划將Redis放在internet上的一個公共可訪問的地址,那么一定要為實例設置一個密碼。設置密碼后:
#
#   1. The Gopher server (when enabled, not by default) will still serve
#      content via Gopher.
# 	   Gopher服務器(啟用時,不是默認情況下)仍將通過Gopher提供內容
#   2. However other commands cannot be called before the client will
#      authenticate.
#      但是,在客戶端進行身份驗證之前不能調用其他命令。
#
# So use the 'requirepass' option to protect your instance.
# 所以使用  “requirepass”(必須密鑰) 選項來保護您的實例。
#
# Note that Gopher is not currently supported when 'io-threads-do-reads'
# is enabled.
# 請注意,當啟用“io線程執行讀取”時,當前不支持Gopher。
#
# To enable Gopher support, uncomment the following line and set the option
# from no (the default) to yes.
# 要啟用Gopher支持,請取消注釋以下行並將選項從no(默認值)設置為yes。
#
# gopher-enabled no

ADVANCED CONFIG 高級配置

############################### 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的用ziplist,大於hash-max-ziplist-entries用hash
hash-max-ziplist-entries 512
# value大小小於等於list-max-ziplist-value的用ziplist,大於list-max-ziplist-value用list。
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到-1,意思是:
# -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.
# 正數意味着每個列表節點最多存儲u個元素。
# 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.
# 性能最高的選項通常是-2(8KB大小)或-1(4KB大小),但是如果您的用例是唯一的,請根據需要調整設置。
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:
# 從快速壓縮列表中排除壓縮列表中每個壓縮節點的 *exclude*。。列表的頭和尾總是未壓縮的,以便進行快速 push/pop 操作。設置為:
# 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"
#    1 表示在列表中有1個節點之后才開始壓縮,無論是從頭部還是尾部
#    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.
#    2 表示頭的下一個節點與尾的上一個節點不會被壓縮,中間的其他節點將被壓縮。
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
#    3 表示頭的下兩個節點與尾的上兩個個節點不會被壓縮,中間的其他節點將被壓縮。
# etc.
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.
# 集合只有一種特殊的編碼方式:當一個集合由恰好是基數為10的64位有符號整數范圍內的整數組成時。
# 為了使用這種特殊的內存節省編碼,下面的配置設置設置了集合大小的限制。
# 設置最大的intset復數
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-max-ziplist-entries用ziplist,大於zset-max-ziplist-entries用zset。
zset-max-ziplist-entries 128
# value大小小於等於zset-max-ziplist-value用ziplist,大於zset-max-ziplist-value用zset。
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.
# 大於16000的值是完全無用的,因為在這一點上密集表示更節省內存。
#
# 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.
# value大小小於等於hll-sparse-max-bytes使用稀疏數據結構(sparse),
# 大於hll-sparse-max-bytes使用稠密的數據結構(dense)。一個比16000大的value是幾乎沒用的,
# 建議值為~3000,以便在不減慢過多PFADD(稀疏編碼為O(N))的情況下利用空間高效編碼的優點。當CPU不是問題,但空間是問題,並且數據集由許多基數在0-15000范圍內的超日志組成時,該值可以提升到~10000。
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 宏節點 每項最大值。流數據結構是一個由大節點組成的基數樹,其中對多個項進行編碼。
# 使用此配置,可以配置單個節點的大小(以字節為單位),以及在附加新的流條目時切換到新節點
# 之前可能包含的最大項數。如果將以下任何設置設置為零,則會忽略該限制,因此,例如,可以
# 通過將max bytes設置為0,將max entries設置為所需的值來設置max entires限制

# stream節點最大大小
stream-node-max-bytes 4096
# stream節點最大數量
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.
# 主動重新緩存每100毫秒CPU時間使用1毫秒,以幫助重新緩存主Redis哈希表(映射頂層的表
# 值的鍵)。Redis使用的哈希表實現(參見dict.c)執行延遲重散列:在重新散列表中運行的操作越多,
# 執行的重新散列“步驟”就越多,因此,如果服務器空閑,則重新散列永遠不會完成,哈希表將使用更多內存。
#
# The default is to use this millisecond 10 times every second in order to
# actively rehash the main dictionaries, freeing memory when possible.
# 默認情況下,每秒使用此操作10次,以便主動重新整理主詞典,盡可能釋放內存。
#
# 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.
# 如果您有嚴格的延遲要求,並且在您的環境中,Redis可以不時地以2毫秒的延遲響應查詢,那么使用“activerehashing no”。
#
# use "activerehashing yes" if you don't have such hard requirements but
# want to free memory asap when possible.
# 如果您沒有這樣的硬性要求,但希望盡快釋放內存,請使用“activerehashingyes”。

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 including MONITOR clients         普通客戶端包括監視器客戶端
# replica  -> replica clients								 從節點客戶端
# pubsub -> clients subscribed to at least one pubsub channel or pattern   至少訂閱了一個pubsub頻道或模式的客戶端
#
# The syntax of every client-output-buffer-limit directive is the following:
# 每個客戶端輸出緩沖區限制指令的語法如下:
#
# client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
# 客戶端輸出緩沖區限制<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.
# 一旦達到硬限制,或者達到軟限制並保持達到指定秒數(連續)時,客戶端將立即斷開連接。
# 因此,例如,如果硬限制為32兆字節,軟限制為16兆字節/10秒,則當輸出緩沖區的大小達到32兆字節時,
# 客戶端將立即斷開連接,但如果客戶端達到16兆字節並連續超過限制10秒,客戶端也將斷開連接。
#
# 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客戶端有一個默認限制,因為訂閱服務器和副本以推送方式接收數據。
#
# Both the hard or the soft limit can be disabled by setting them to zero.
# 硬限制或軟限制都可以通過設置為零來禁用。

# 對於normal client,第一個0表示取消hard limit,第二個0和第三個0表示取消soft limit,normal client默認取消限制,因為如果沒有尋問,他們是不會接收數據的。
client-output-buffer-limit normal 0 0 0
# 對於slave client和MONITER client,如果client-output-buffer一旦超過256mb,又或者超過64mb持續60秒,那么服務器就會立即斷開客戶端連接。
client-output-buffer-limit replica 256mb 64mb 60
# 對於pubsub client,如果client-output-buffer一旦超過32mb,又或者超過8mb持續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.
# 客戶端查詢緩沖區累積新命令。默認情況下,它們被限制為固定數量,以避免協議取消同步
#(例如由於客戶端中的錯誤)將導致查詢緩沖區中未綁定內存的使用。但是,如果您有非常特殊的需要,
# 比如我們巨大的multi/exec請求或類似的請求,您可以在這里配置它。
#
# client-query-buffer-limit 1gb

# In the Redis protocol, bulk requests, that are, elements representing single
# strings, are normally limited to 512 mb. However you can change this limit
# here, but must be 1mb or greater
# 在Redis協議中,大容量請求,即代表單個字符串的元素,通常被限制在512MB。不過,您可以在這里更改此限制,但必須大於1mb
#
# 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.
# Redis調用一個內部函數來執行許多后台任務,比如超時關閉客戶端的連接,清除從未被請求的過期密鑰,等等。
#
# Not all tasks are performed with the same frequency, but Redis checks for
# tasks to perform according to the specified "hz" value.
# 並非所有任務都以相同的頻率執行,但Redis會根據指定的“hz”值檢查要執行的任務。
#
# 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.
# 默認情況下,“hz”設置為10。當Redis空閑時,提高該值將占用更多的CPU,但同時也會使Redis在多個密鑰同時過期時響應更快,超時處理可能更精確。
#
# 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.
# 范圍在1到500之間,但最好別超過100。大多數用戶應該使用默認值10,並且只有在需要非常低延遲的環境中才將此值提高到100。

# redis執行任務的頻率為1s除以hz。
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 temporarily raise when there are many connected clients.
# 由於默認的默認HZ值保守地設置為10,Redis提供並在默認情況下啟用使用自適應HZ值的能力,當有許多連接的客戶端時,該值將臨時提高。
#
# When dynamic HZ is enabled, the actual configured HZ will be used
# 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.
# 當啟用動態赫茲時,實際配置的赫茲將被用作基線,但是一旦有更多的客戶機連接起來,
# 實際上將根據需要使用配置的赫茲值的倍數。這樣一來,空閑實例將占用很少的CPU時間,而繁忙的實例將具有更高的響應速度。
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文件時,如果啟用以下選項,則每生成32mb的數據將對該文件進行fsync。
# 這對於以增量方式將文件提交到磁盤並避免較大的延遲峰值非常有用。

# aof以增量方式使用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.
# 當redis保存RDB文件時,如果啟用以下選項,則每生成32mb的數據將對該文件進行fsync。
# 這對於以增量方式將文件提交到磁盤並避免較大的延遲峰值非常有用。

# rdb以增量方式使用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.
# Redis LFU逐出(請參閱maxmemory設置)可以進行調整。但是,最好從默認設置開始,
# 在研究如何提高性能以及密鑰LFU如何隨時間變化后才更改它們,這可以通過OBJECT FREQ命令進行檢查。
#
# 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:
# Redis-LFU實現中有兩個可調參數:計數器對數因子和計數器衰減時間。在改變這兩個參數之前,了解它們的含義是很重要的。
#
# 1. A random number R between 0 and 1 is extracted.                          提取0到1之間的隨機數R。
# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).         概率P計算為1/(old_value*lfu_log_factor+1)。
# 3. The counter is incremented only if R < P.                                只有當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:													      默認的lfu日志系數為10。以下是頻率計數器如何隨不同對數因子的不同訪問次數而變化的表:
#
# +--------+------------+------------+------------+------------+------------+
# | 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.
# 計數器的初始值是5,以便給新對象一個累積命中的機會。
#
# 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).
# 計數器衰變時間是按鍵計數器除以2(如果其值小於等於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衰退時間的默認值為1。一個特殊值0意味着每次掃描計數器時都會衰減計數器。
#
# lfu-log-factor 10
# lfu-decay-time 1

ACTIVE DEFRAGMENTATION活動碎片整理

########################### ACTIVE DEFRAGMENTATION #######################
########################### 活動          碎片整理 #######################
#
# What is 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 a "hot" way, while the server is running.
# 碎片化是一個自然的過程,它發生在每個分配器(幸運的是Jemalloc)和某些工作負載上。
# 通常需要重新啟動服務器以降低碎片,或者至少刷新所有數據並重新創建。不過,
# 多虧了OranAgra for Redis 4.0實現的這一特性,這個過程可以在服務器運行時以“熱”的方式在運行時發生
#
# 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將開始利用某些特定的Jemalloc特性
# 在連續內存區域中創建值的新副本(以便了解某個分配是否導致碎片並將其分配到更好的位置)
# ,同時,會發布舊的數據拷貝。對所有鍵增量重復此過程將導致碎片返回到正常值。
#
# 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.
#    此功能在默認情況下是禁用的,並且只有在您編譯Redis以使用Redis源代碼附帶的Jemalloc副本時才起作用。這是Linux版本的默認設置。
#
# 2. You never need to enable this feature if you don't have fragmentation
#    issues.
# 	 如果沒有碎片問題,則不需要啟用此功能。
#
# 3. Once you experience fragmentation, you can enable this feature when
#    needed with the command "CONFIG SET activedefrag yes".
#    一旦遇到碎片,您可以在需要時使用命令“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 no

# Minimum amount of fragmentation waste to start active defrag
# 當碎片達到 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, to be used when the lower
# threshold is reached
# 內存自動整理占用資源最小百分比
# active-defrag-cycle-min 1

# Maximal effort for defrag in CPU percentage, to be used when the upper
# threshold is reached
# 內存自動整理占用資源最大百分比
# active-defrag-cycle-max 25

# 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

# Jemalloc background thread for purging will be enabled by default
# 默認情況下,將啟用用於清除的Jemalloc后台線程
jemalloc-bg-thread yes

# 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上,也可以確保在同一主機上運行的多個Redis實例被固定到不同的cpu上。
# 就是將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和FreeBSD中,也可以通過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:
# 您可以固定服務器/IO線程、bio線程、aof重寫子進程和bgsave子進程。指定cpu列表的語法與taskset命令相同:
#
# Set redis server/io threads to cpu affinity 0,2,4,6:
# 將redis 服務/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:
# 將 AOF 子進程寫操作綁定到 cpu線 8,9,10,11 上
# aof_rewrite_cpulist 8-11
#
# Set bgsave child process to cpu affinity 1,10,11
# 將子進程后台保存操作綁定到 cpu線 1,10,11 上
# bgsave_cpulist 1,10-11

sentinel.conf

哨兵配置,基本上百度翻譯一遍就行,唯一有難點的就是ACL文件里面存什么,剛開始博主查官方文檔時沒發現案例還准備吐槽的,后來發現,使用redis的ACL指令,寫兩個帶密碼的自定義權限的用戶進去,就知道文件保存的是什么了。

# Example sentinel.conf

# *** IMPORTANT ***
#
# By default Sentinel will not be reachable from interfaces different than
# localhost, either use the 'bind' directive to bind to a list of network
# interfaces, or disable protected mode with "protected-mode no" by
# adding it to this configuration file.
#
# Before doing that MAKE SURE the instance is protected from the outside
# world via firewalling or other means.
#
# For example you may use one of the following:
# 指定受保護模式下,可通過下列ip端口訪問哨兵服務
# bind 127.0.0.1 192.168.1.1
bind 127.0.0.1 172.165.165.101
#
# protected-mode no
# 以保護模式啟動哨兵服務
protected-mode yes

# port <sentinel-port>
# The port that this sentinel instance will run on
# 指定哨兵啟動端口
port 26379

# By default Redis Sentinel does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis-sentinel.pid when
# daemonized.
# 以守護進程啟動,就是后台啟動的意思
daemonize yes

# When running daemonized, Redis Sentinel writes a pid file in
# /var/run/redis-sentinel.pid by default. You can specify a custom pid file
# location here.
# 指定pid文件
pidfile /data/redis/redis-sentinel_26379.pid

# Specify the log file name. Also the empty string can be used to force
# Sentinel to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
# 指定日志文件
logfile "/data/redis/log/redis-sentinel_26379.log"

# sentinel announce-ip <ip>
# sentinel announce-port <port>
sentinel announce-ip 172.165.165.101
sentinel announce-port 26379
# 
# The above two configuration directives are useful in environments where,
# because of NAT, Sentinel is reachable from outside via a non-local address.
#
# When announce-ip is provided, the Sentinel will claim the specified IP address
# in HELLO messages used to gossip its presence, instead of auto-detecting the
# local address as it usually does.
#
# Similarly when announce-port is provided and is valid and non-zero, Sentinel
# will announce the specified TCP port.
#
# The two options don't need to be used together, if only announce-ip is
# provided, the Sentinel will announce the specified IP and the server port
# as specified by the "port" option. If only announce-port is provided, the
# Sentinel will announce the auto-detected local IP and the specified port.
# 這一大段話的意思就是,指定告訴其他哨兵自己的訪問ip、端口。主要當互相之間的
# 訪問經過了nginx或其他代理軟件后,無法直接獲取通過本地ip訪問。這里就配置成可
# 訪問的代理ip、端口。和reids服務一樣。 
#
# Example:
#
# sentinel announce-ip 1.2.3.4

# dir <working-directory>
# Every long running process should have a well-defined working directory.
# For Redis Sentinel to chdir to /tmp at startup is the simplest thing
# for the process to don't interfere with administrative tasks such as
# unmounting filesystems.
# 工作空間,默認/tmp
dir /data/redis

# sentinel monitor <master-name> <ip> <redis-port> <quorum>
#
# Tells Sentinel to monitor this master, and to consider it in O_DOWN
# (Objectively Down) state only if at least <quorum> sentinels agree.
# 告訴哨兵建視這個redis-master,並且只有在至少 quorum 個哨兵統一的情況
# 下,才客觀關閉該 redis-master
#
# Note that whatever is the ODOWN quorum, a Sentinel will require to
# be elected by the majority of the known Sentinels in order to
# start a failover, so no failover can be performed in minority.
# 就是哨兵的客觀下線,是必須大多數哨兵同意才行,因此哨兵太少了,就不得行
# 那樣的話就無法容錯了
#
# Replicas are auto-discovered, so you don't need to specify replicas in
# any way. Sentinel itself will rewrite this configuration file adding
# the replicas using additional configuration options.
# Also note that the configuration file is rewritten when a
# replica is promoted to master.
# 復制副本是自動發現的,因此您不需要以任何方式指定復制副本。
# Sentinel本身將重寫此配置文件,並使用其他配置選項添加副本。還要注意,
# 當復制副本升級為主副本時,配置文件會被重寫。
#
# Note: master name should not include special characters or spaces.
# 注意:主控形狀名稱不應包含特殊字符或空格
# The valid charset is A-z 0-9 and the three characters ".-_".
# 有效的字符集是A-z 0-9和這三個字符“—”。
sentinel monitor mymaster 172.165.165.101 6379 2

# sentinel auth-pass <master-name> <password>
#
# Set the password to use to authenticate with the master and replicas.
# 設置用於向主副本和副本進行身份驗證的密碼。
# Useful if there is a password set in the Redis instances to monitor.
#
# Note that the master password is also used for replicas, so it is not
# possible to set a different password in masters and replicas instances
# if you want to be able to monitor these instances with Sentinel.
# 請注意,主密碼也用於副本,因此,如果您希望能夠使用Sentinel監視這些實例,
# 則無法在主密碼和副本實例中設置不同的密碼。就是主redis與從redis的密碼必須相同
#
# However you can have Redis instances without the authentication enabled
# mixed with Redis instances requiring the authentication (as long as the
# password set is the same for all the instances requiring the password) as
# the AUTH command will have no effect in Redis instances with authentication
# switched off.
# 但是,您可以將未啟用身份驗證的Redis實例與需要身份驗證的Redis實例混合使用(
# 只要對所有需要密碼的實例設置的密碼相同),因為AUTH命令在關閉身份驗證的Redis
# 實例中無效。
# 就是允許混搭使用,有的要密碼,有的不要密碼,只要保證要密碼的密碼都相同即可
#
# Example:
#
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
sentinel auth-pass sentinel-user 05a364a63b7cd0894a7f97817ac11041fe4f581d82aeeb3b0d773b9dcc19ba9c

# sentinel auth-user <master-name> <username>
#
# This is useful in order to authenticate to instances having ACL capabilities,
# that is, running Redis 6.0 or greater. When just auth-pass is provided the
# Sentinel instance will authenticate to Redis using the old "AUTH <pass>"
# method. When also an username is provided, it will use "AUTH <user> <pass>".
# In the Redis servers side, the ACL to provide just minimal access to
# Sentinel instances, should be configured along the following lines:
# 這對於向具有ACL功能的實例(即運行Redis 6.0或更高版本)進行身份驗證非常有用。
# 當只提供auth pass時,Sentinel實例將使用舊的“auth<pass>方法對Redis進行身份驗證。
# 同時提供用戶名時,它將使用“AUTH<user><pass>”。在Redis服務器端,僅提供對Sentinel
# 實例的最小訪問的ACL應按以下方式配置:
#
#     user sentinel-user >somepassword +client +subscribe +publish \
#                        +ping +info +multi +slaveof +config +client +exec on

# sentinel down-after-milliseconds <master-name> <milliseconds>
#
# Number of milliseconds the master (or any attached replica or sentinel) should
# be unreachable (as in, not acceptable reply to PING, continuously, for the
# specified period) in order to consider it in S_DOWN state (Subjectively
# Down).
# 設置超時主觀下線毫秒數。哨兵連接redis服務超過了這個指定時間,則視該redis主觀下線
#
# Default is 30 seconds.
sentinel down-after-milliseconds mymaster 30000

# requirepass <password>
#
# You can configure Sentinel itself to require a password, however when doing
# so Sentinel will try to authenticate with the same password to all the
# other Sentinels. So you need to configure all your Sentinels in a given
# group with the same "requirepass" password. Check the following documentation
# for more info: https://redis.io/topics/sentinel
# 意思就是說,你也可以給哨兵服務設置一個密碼,就是如果一個設置了,其余的也必須設置這個密碼


# sentinel parallel-syncs <master-name> <numreplicas>
#
# How many replicas we can reconfigure to point to the new replica simultaneously
# during the failover. Use a low number if you use the replicas to serve query
# to avoid that all the replicas will be unreachable at about the same
# time while performing the synchronization with the master.
# 指定了在執行故障轉移時, 最多可以有多少個從服務器同時對新的主服務器進行同步
# 例如三個服務的話,死了一個,還剩兩個,則允許一個對主服務器進行同步
sentinel parallel-syncs mymaster 1

# sentinel failover-timeout <master-name> <milliseconds>
#
# Specifies the failover timeout in milliseconds. It is used in many ways:
# 指定故障轉移超時時間
#
# - The time needed to re-start a failover after a previous failover was
#   already tried against the same master by a given Sentinel, is two
#   times the failover timeout.
# 在給定的Sentinel已經針對同一主機嘗試了上一次故障轉移之后,
# 重新啟動故障轉移所需的時間是故障轉移超時的兩倍。
#
# - The time needed for a replica replicating to a wrong master according
#   to a Sentinel current configuration, to be forced to replicate
#   with the right master, is exactly the failover timeout (counting since
#   the moment a Sentinel detected the misconfiguration).
# 根據Sentinel當前配置,復制副本復制到錯誤主機所需的時間,強制復制到正確
# 主機所需的時間,正好是故障轉移超時(從Sentinel檢測到錯誤配置的那一刻起計算)。
#
# - The time needed to cancel a failover that is already in progress but
#   did not produced any configuration change (SLAVEOF NO ONE yet not
#   acknowledged by the promoted replica).
# 取消已在進行但未產生任何配置更改的故障轉移所需的時間(從屬於尚未被提升的復
# 制副本確認的任何人)。
#
# - The maximum time a failover in progress waits for all the replicas to be
#   reconfigured as replicas of the new master. However even after this time
#   the replicas will be reconfigured by the Sentinels anyway, but not with
#   the exact parallel-syncs progression as specified.
# 正在進行的故障轉移等待將所有副本重新配置為新主機的副本的最長時間。
# 但是,即使在這段時間之后,復制副本也將由sentinel重新配置,但不會按照指定的
# 並行同步進程進行配置。
#
# Default is 3 minutes.
sentinel failover-timeout mymaster 180000

# SCRIPTS EXECUTION
# 執行腳本
#
# sentinel notification-script and sentinel reconfig-script are used in order
# to configure scripts that are called to notify the system administrator
# or to reconfigure clients after a failover. The scripts are executed
# with the following rules for error handling:
# sentinel通知腳本和sentinel reconfig腳本用於配置調用的腳本,以便在故障轉移
# 后通知系統管理員或重新配置客戶端。使用以下錯誤處理規則執行腳本:
#
# If script exits with "1" the execution is retried later (up to a maximum
# number of times currently set to 10).
# 如果腳本以“1”退出,則稍后將重試執行(最多可重試10次)。
#
# If script exits with "2" (or an higher value) the script execution is
# not retried.
# 如果腳本以“2”(或更高的值)退出,則不重試腳本執行。
#
# If script terminates because it receives a signal the behavior is the same
# as exit code 1.
# 如果腳本因為接收到信號而終止,則行為與退出代碼1相同。
#
# A script has a maximum running time of 60 seconds. After this limit is
# reached the script is terminated with a SIGKILL and the execution retried.
# 腳本的最大運行時間為60秒。達到此限制后,腳本將以SIGKILL終止並重試執行。

# NOTIFICATION SCRIPT
# 通知腳本
#
# sentinel notification-script <master-name> <script-path>
# 
# Call the specified notification script for any sentinel event that is
# generated in the WARNING level (for instance -sdown, -odown, and so forth).
# This script should notify the system administrator via email, SMS, or any
# other messaging system, that there is something wrong with the monitored
# Redis systems
# 為警告級別中生成的任何sentinel事件調用指定的通知腳本(例如-sdown、-odown等等)
# 。此腳本應通過電子郵件、SMS或任何其他消息傳遞系統通知系統管理員受監視的Redis
# 系統有問題。.
#
# The script is called with just two arguments: the first is the event type
# and the second the event description.
# 調用腳本時只有兩個參數:第一個是事件類型,第二個是事件描述。
#
# The script must exist and be executable in order for sentinel to start if
# this option is provided.
# 如果提供了此選項,則腳本必須存在並可執行,以便sentinel啟動。
#
# Example:
#
# sentinel notification-script mymaster /var/redis/notify.sh

# CLIENTS RECONFIGURATION SCRIPT
# 客戶端重新配置腳本
#
# sentinel client-reconfig-script <master-name> <script-path>
#
# When the master changed because of a failover a script can be called in
# order to perform application-specific tasks to notify the clients that the
# configuration has changed and the master is at a different address.
# 由於故障轉移而更改了主機時,可以調用腳本來執行特定於應用程序的任務,
# 以通知客戶端配置已更改,並且主機位於不同的地址。
# 
# The following arguments are passed to the script:
#
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
#
# <state> is currently always "failover"
# <role> is either "leader" or "observer"
# 
# The arguments from-ip, from-port, to-ip, to-port are used to communicate
# the old address of the master and the new address of the elected replica
# (now a master).
# 參數from ip,from port,to ip,to port用於傳遞主機的舊地址和所選副本(現在是主機)的新地址。
#
# This script should be resistant to multiple invocations.
# 這個腳本應該能夠抵抗多次調用。
#
# Example:
#
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

# SECURITY
# 安全
#
# By default SENTINEL SET will not be able to change the notification-script
# and client-reconfig-script at runtime. This avoids a trivial security issue
# where clients can set the script to anything and trigger a failover in order
# to get the program executed.
# 默認情況下,SENTINEL SET將無法在運行時更改通知腳本和客戶端重新配置腳本。
# 這避免了一個微不足道的安全問題,即客戶端可以將腳本設置為任何值並觸發故障轉移以執行程序。

sentinel deny-scripts-reconfig yes

# REDIS COMMANDS RENAMING
# REDIS命令重命名
#
# Sometimes the Redis server has certain commands, that are needed for Sentinel
# to work correctly, renamed to unguessable strings. This is often the case
# of CONFIG and SLAVEOF in the context of providers that provide Redis as
# a service, and don't want the customers to reconfigure the instances outside
# of the administration console.
# 有時Redis服務器有一些Sentinel正常工作所需的命令,這些命令被重命名為不可使用的字符串。
# 在將Redis作為服務提供的提供者的上下文中,CONFIG和SLAVEOF常常是這種情況,
# 它們不希望客戶在管理控制台之外重新配置實例。
# 就是為了安全起見,不允許客戶在控制台以外的其他地方通過指令操作哨兵服務。所以重命名指令
#
# In such case it is possible to tell Sentinel to use different command names
# instead of the normal ones. For example if the master "mymaster", and the
# associated replicas, have "CONFIG" all renamed to "GUESSME", I could use:
# 在這種情況下,可以告訴Sentinel使用不同的命令名,而不是普通的命令名。例如,
# 如果主機“mymaster”和相關副本的“CONFIG”都重命名為“GUESSME”,

# SENTINEL rename-command mymaster CONFIG GUESSME
#
# After such configuration is set, every time Sentinel would use CONFIG it will
# use GUESSME instead. Note that there is no actual need to respect the command
# case, so writing "config guessme" is the same in the example above.
# 在設置了這樣的配置之后,每次Sentinel使用CONFIG時,它都會使用GUESSME。
# 請注意,實際上不需要考慮命令大小寫,因此在上面的示例中編寫“config guessme”是相同的。
#
# SENTINEL SET can also be used in order to perform this configuration at runtime.
# 為了在運行時執行此配置,還可以使用SENTINEL SET。
#
# In order to set a command back to its original name (undo the renaming), it
# is possible to just rename a command to itself:
# 為了將命令設置回其原始名稱(撤消重命名),可以只將命令重命名為其自身:
#
# SENTINEL rename-command mymaster CONFIG CONFIG

users.acl

user default off nopass ~* +@all
user admin-user on #6073ee0c1f33a7c55c023cfb5ae41202634ec5d47f5839766d7e9c72784692c7 ~* +@all
user redis-user on #b29890a1832f93ab561d6e5da14ac6cd6688a72674da66ba342e52dfb3fced0b
user stop-user on #aa655477ccee0866310f71602923f37351245c53fe77c178cf2f79b04d0b2cd0 +SHUTDOWN
user sentinel-user on #f52269d79c568147710decedb57dac72400211768eb1137097b5f67233f4290d -@all +subscribe +publish +client|setname +client|kill +config|rewrite +role +exec +slaveof +info +multi +ping +script|kill
user replica-user on #3ee15bb3d499740ccdc5ebf49b6f8b3f4a43dfc74b1597f6f3822023cbab008a -@all +ping +psync +replconf

參考地址:https://www.cnblogs.com/chuijingjing/p/12832678.html

百度翻譯真香

由於英語渣渣,剛開始很多配置信息看不明白的就用有道翻譯。然后翻譯出來的更是天書,只能一個一個單詞的翻譯,然后自己去理解redis官方在配置文件里留的這段話到底是什么意思。后來用了下百度翻譯。真TM的香,不得不說百度對於這些IT行業的專有名詞處理的很好,感覺兩者就完全不是一個層級的。從此卸載有道翻譯。
一個具有注腳的文本。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM