Redis 配置详解 —— 全网最新最全

文章目录

        • 一、撰文目的
        • 二、配置详解
          • 1、 EXAMPLE(概要说明)
          • 2、INCLUDES(配置包含)
          • 3、MODULES(加载模块)
          • 4、NETWORK(网络配置)
          • 5、TLS/SSL(通讯协议)
          • 6、GENERAL(常规配置)
          • 7、SNAPSHOTTING(快照配置)
          • 8、REPLICATION(复制配置)
          • 9、KEYS TRACKING(键的追踪)
          • 10、SECURITY(安全配置)
          • 11、CLIENTS(客户端配置)
          • 12、MEMORY MANAGEMENT(内存管理)
          • 13、LAZY FREEING(懒惰释放)
          • 14、THREADED I/O(线程配置)
          • 15、KERNEL OOM CONTROL(内核控制)
          • 16、KERNEL transparent hugepage CONTROL(内核透明大页控制)
          • 17、APPEND ONLY MODE(AOF 配置)
          • 18、SHUTDOWN(停止配置)
          • 19、NON-DETERMINISTIC LONG BLOCKING COMMANDS(非决定性的长阻断命令)
          • 20、REDIS CLUSTER(集群配置)
          • 21、CLUSTER DOCKER/NAT support(集群容器/NAT支持)
          • 22、SLOW LOG(慢日志配置)
          • 23、LATENCY MONITOR(延迟监控)
          • 24、LATENCY TRACKING(延迟追踪)
          • 25、EVENT NOTIFICATION(事件通知)
          • 26、ADVANCED CONFIG(高级配置)
          • 27、ACTIVE DEFRAGMENTATION(主动碎片整理)

一、撰文目的

  • Redis 是项目开发中使用频率最高的中间件,那么试问有谁认真的全文解读过 Redis 的配置文件?

  • 当中间件性能遇到所谓的 “瓶颈” 的时候,也许就是某个配置设置的不合理导致的问题。

  • 今天借此机会花费一点时间来全文解读一次 Redis 的配置,配置信息是基于 Redis-7.0.7 版本

  • 点击此处 获取 Redis 全部版本的安装文件。

二、配置详解

1、 EXAMPLE(概要说明)
# 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.
# Redis 配置文件示例。
#
# 注意,为确保准确的读取配置文件,Redis 启动时必须以配置文件路径作为第一个启动参数
#
# ./redis-server /path/to/redis.conf

# 单位注意事项:当需要设置内存大小时,可以以 1k 5GB 4M 等常规形式来指定单位
#
# 1k    等于 1000 bytes
# 1kb   等于 1024 bytes
# 1m    等于 1000000 bytes
# 1mb   等于 1024*1024 bytes
# 1g    等于 1000000000 bytes
# 1gb   等于 1024*1024*1024 bytes
#
# 单位是不区分大小写的,所以 1GB 1Gb 1gB 都是一样的
2、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.
#
# Included paths may contain wildcards. All files matching the wildcards will
# be included in alphabetical order.
# Note that if an include path contains a wildcards but no files match it when
# the server is started, the include statement will be ignored and no error will
# be emitted.  It is safe, therefore, to include wildcard files from empty
# directories.
#
# include /path/to/local.conf
# include /path/to/other.conf
# include /path/to/fragments/*.conf
#
################################## 配置包含 ###################################

# 配置文件中可以包含一个或多个其它配置文件。如果你有一个适用于所有 Redis 服务器的标准的模板,
# 但是又需要为每台 Redis 服务器有少量定制设置,这个功能就很有用。包含的文件可以包含其它文件,
# 所以使用这个功能很明智。
#
# 注意:"include" 这个选项不会被管理员或 Redis Sentinel 的 "CONFIG REWRITE" 命令改写。
# 由于 Redis 总是使用最后处理的行作为配置指令值,你最好把 "include" 放在这个配置文件的开头,
# 以避免在运行时覆盖了配置的变化
#
# 如果你有兴趣或者需要使用 "include" 来覆盖配置的选项,最好使用 "include" 放在最后一行来覆
# 盖前面相同的配置项
#
# 被包含的路径可以包含通配符。所有与通配符匹配的文件将按字母顺序被包含。
# 请注意:如果一个包含路径包含通配符,但是在服务器启动时候没有文件与之匹配,那么启动程序将忽略
# 这个包含语句,也不会发出错误。因此,从空目录中包含通配符文件是安全的。
#
# include /path/to/local.conf
# include /path/to/other.conf
# include /path/to/fragments/*.conf
#
3、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 /path/to/my_module.so
# loadmodule /path/to/other_module.so
################################## 加载模块 #####################################
# 在启动时加载模块。如果服务器不能加载模块,那么它将被终止。可以使用多个 "loadmodule" 指令
# 来加载模块
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
4、NETWORK(网络配置)
################################## 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.
# Each address can be prefixed by "-", which means that redis will not fail to
# start if the address is not available. Being not available only refers to
# addresses that does not correspond to any network interface. Addresses that
# are already in use will always fail, and unsupported protocols will always BE
# silently skipped.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
# bind * -::*                     # like the default, all available interfaces
#
# ~~~ 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 and IPv6 (if available) loopback interface addresses (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
# COMMENT OUT THE FOLLOWING LINE.
#
# You will also need to set a password unless you explicitly disable protected
# mode.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1

# By default, outgoing connections (from replica to master, from Sentinel to
# instances, cluster bus, etc.) are not bound to a specific local address. In
# most cases, this means the operating system will handle that based on routing
# and the interface through which the connection goes out.
#
# Using bind-source-addr it is possible to configure a specific address to bind
# to, which may also affect how the connection gets routed.
#
# Example:
#
# bind-source-addr 10.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 the default user has no password, the server
# only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address
# (::1) or 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.
protected-mode yes

# Redis uses default hardened security configuration directives to reduce the
# attack surface on innocent users. Therefore, several sensitive configuration
# directives are immutable, and some potentially-dangerous commands are blocked.
#
# Configuration directives that control files that Redis writes to (e.g., 'dir'
# and 'dbfilename') and that aren't usually modified during runtime
# are protected by making them immutable.
#
# Commands that can increase the attack surface of Redis and that aren't usually
# called by users are blocked by default.
#
# These can be exposed to either all connections or just local ones by setting
# each of the configs listed below to either of these values:
#
# no    - Block for any connection (remain immutable)
# yes   - Allow for any connection (no protection)
# local - Allow only for local connections. Ones originating from the
#         IPv4 address (127.0.0.1), IPv6 address (::1) or Unix domain sockets.
#
# enable-protected-configs no
# enable-debug-command no
# enable-module-command no

# 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-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /run/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) 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.
# 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

# Apply OS-specific mechanism to mark the listening socket with the specified
# ID, to support advanced routing and filtering capabilities.
#
# On Linux, the ID represents a connection mark.
# On FreeBSD, the ID represents a socket cookie ID.
# On OpenBSD, the ID represents a route table ID.
#
# The default value is 0, which implies no marking is required.
# socket-mark-id 0
################################## 网络配置 #####################################

# 默认情况下,如果没有指定 "bind" 配置指令,Redis 会监听主机上所有可用网络接口的连接。可以使用
# "bind" 配置指令只监听一个或多个选定的接口,后面跟一个或者多个 IP 地址。每个地址都可以用 "-" 
# 作为前缀。这意味着如果地址不可用,Redis 将不会启动失败,不可用仅仅指不对应于任何网络接口地址。
# 已经在使用的网络接口地址将总是失败,不支持的协议将总是被默默地跳过。
#
# 示例:
#
# bind 192.168.1.100 10.0.0.1     # 监听了两个特定的 IPv4 地址
# bind 127.0.0.1 ::1              # 监听回环的 IPv4 和 IPv6 地址
# bind * -::*                     # 像默认一样,所有可用的接口
#
# ~~~ 警告 ~~~ 如果运行 Redis 的计算机直接暴露在互联网上,绑定所有接口是很危险的,会将实例暴露给
# 互联网上的所有人。
# 所以默认情况下,我们取消了下面的绑定指令,这将迫使 Redis 只监听 IPv4 和 IPv6(如果有的话)环回
# 接口地址(这意味着 Redis 将只能接受来自它所运行的同一主机的客户端连接)。
#
# 如果你确定你想让你的实例监听所有的接口,注释掉下面一行
#
# 你还需要设置一个密码,除非你明确地禁用了保护的模式
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1

# 默认情况下,出站连接(从副本到主站,从 Sentinel 到实例,集群总线,等)不绑定到一个特定的本地地址。
# 在大多数情况下,这意味着操作系统将根据路由和连接出去的接口来处理。
#
# 使用 "bind-source-addr" 可以配置一个特定的地址来绑定,这也会影响连接的路由。
#
# 示例:
#
# bind-source-addr 10.0.0.1

# 保护模式是一个安全保护层,以避免留在互联网上的 Redis 实例被访问和利用
#
# 当保护模式开启且默认用户没有密码时,Redis 服务器只接受来自 IPv4 地址(127.0.0.1)、
# IPv6 地址(::1)或者 Unix 域套接字。
#
# 默认情况下,保护模式是启用的,只有当你想让其它主机的客户端连接到 Redis 时,你才应该禁用它。即使
# 没有配置权限认证。
protected-mode yes

# Redis 使用默认的硬化安全配置指令来减少无辜用户的攻击面。因此,一些敏感的配置指令不可被改变,一些
# 有潜在危险的命令被也会被阻止。
#
# 控制 Redis 写入文件的配置指令(如:"dir" 和 "dbfilename"), 以及通常在运行期间不被修改的配置
# 指令,通过使其不可变来保护。
#
# 可以增加 Redis 攻击面的命令,以及通常不被用户调用的命令,在默认情况下是被阻止的。
#
# 通过将下面列出的每个配置设置为这些值中的任何一个,这些都可以暴露给所有的连接,或者只暴露给本地的连接。
#
# no    —— 阻止任何连接(保护不可改变)
# yes   —— 允许任何连接(无保护)
# local —— 只允许本地连接。源自于 IPv4 地址(127.0.0.1)、IPv6 地址(::1)或 Unix 域套接字。
#
# enable-protected-configs no
# enable-debug-command no
# enable-module-command no

# 接受指定端口的连接,默认为 6379(IANA #815344)。如果指定端口为 0 ,Redis 将不在 TCP 套接字上
# 监听
port 6379

# TCP 监听积压。
#
# 在高并发的场景下,你需要一个高的积压以避免缓慢的客户端连接问题。
# 注意:Linux 内核会默默地将其截断为 /proc/sys/net/core/somaxconn 的值,所以要确保同时提高 
# somaxconn 和 tcp_max_syn_backlog 的值,以获得预期的效果
tcp-backlog 511

# Unix 套接字
#
# 指定 Unix 套接字的路径,该套接字将用于监听进入的连接。没有默认值,所以 Redis 在没有指定时不会
# 监听 Unix 套接字。
#
# unixsocket /run/redis.sock
# unixsocketperm 700

# 在客户端闲置 N 秒后关闭连接(0 表示禁用)。
timeout 0

# TCP keepalive
#
# 如果非零,使用 SO_KEEPALIVE 在没有通讯的情况下向客户端发送 TCP ACK。
# 这有两个有用的原因:
#
# 1)检测死亡的对等体
# 2)迫使中间的网络设备认为该连接是活的
#
# 在 Linux 上,指定的值(以秒为单位)是用来发送 ACK 的周期。请注意,要关闭连接,需要两倍的时间。
# 在其他内核上,这个周期取决于内核配置。
#
# 这个选项的合理值是 300 秒,这是自 Redis 3.2.1 开始的新默认值。
tcp-keepalive 300

# 应用操作系统特定的机制来标记监听套接字与指定的 ID,以支持高级路由和过滤功能。
#
# 在 Linux 上,该 ID 代表一个连接标记。
# 在 FreeBSD 上,该 ID 代表一个套接字 cookie ID。
# 在 OpenBSD 中,ID 代表一个路由表的 ID。
#
# 默认值是 0,这意味着不需要标记。
# socket-mark-id 0
5、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:
#
# 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.
#
# tls-cert-file redis.crt
# tls-key-file redis.key
#
# If the key file is encrypted using a passphrase, it can be included here
# as well.
#
# tls-key-file-pass secret

# Normally Redis uses the same certificate for both server functions (accepting
# connections) and client functions (replicating from a master, establishing
# cluster bus connections, etc.).
#
# Sometimes certificates are issued with attributes that designate them as
# client-only or server-only certificates. In that case it may be desired to use
# different certificates for incoming (server) and outgoing (client)
# connections. To do that, use the following directives:
#
# tls-client-cert-file client.crt
# tls-client-key-file client.key
#
# If the key file is encrypted using a passphrase, it can be included here
# as well.
#
# tls-client-key-file-pass secret

# Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange,
# required by older versions of OpenSSL (<3.0). Newer versions do not require
# this configuration and recommend against it.
#
# 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.
#
# tls-ca-cert-file ca.crt
# tls-ca-cert-dir /etc/ssl/certs

# By default, clients (including replica servers) on a TLS port are required
# to authenticate using valid client side certificates.
#
# If "no" is specified, client certificates are not required and not accepted.
# If "optional" is specified, client certificates are accepted and must be
# valid if provided, but are not required.
#
# tls-auth-clients no
# tls-auth-clients optional

# By default, a Redis replica does not attempt to establish a TLS connection
# with its master.
#
# Use the following directive to enable TLS on replication links.
#
# 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:
#
# tls-cluster yes

# By default, only TLSv1.2 and TLSv1.3 are enabled and it is highly recommended
# that older formally deprecated versions are kept disabled to reduce the attack surface.
# You can 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-protocols "TLSv1.2 TLSv1.3"

# Configure allowed ciphers.  See the ciphers(1ssl) manpage for more information
# about the syntax of this string.
#
# 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
################################# 通讯协议 #####################################

# 默认情况下,TLS/SSL 是被禁用的。要启用它,可以使用 "tls-port" 配置指令来定义 TLS 监听端口
# 要在默认端口上启用 TLS,请使用:
#
# port 0
# tls-port 6379

# 配置一个 X.509 证书和私钥,用于向连接的客户端、主节点或者集群对等体验证服务器。这些文件应该是 
# PEM 格式的。
#
# tls-cert-file redis.crt
# tls-key-file redis.key
#
# 如果密钥文件是用口令加密的,可以把它放在这里
#
# tls-key-file-pass secret

# 通常 Redis 在服务器功能(接受连接)和客户端功能(从主站复制,建立集群总线连接等)上使用相同的
# 证书。
#
# 有时颁发的证书具有指定它们为仅适用于客户或仅适用于服务器证书的属性。在这种情况下,我们可能需要为
# 传入(服务器)和传出(客户)连接使用不同的证书。要做到这一点,请使用以下指令。
#
# tls-client-cert-file client.crt
# tls-client-key-file client.key
#
# 如果密钥文件是用口令加密的,也可以包括在这里。
#
# tls-client-key-file-pass secret

# 配置 DH 参数文件以启用 Diffie-Hellman(DH)密钥交换,这是旧版 OpenSSL(<3.0)的要求。较新
# 的版本不需要这种配置,建议不要这样做。
#
# tls-dh-params-file redis.dh

# 配置一个 CA 证书包或目录,以验证 TLS/SSL 客户和对等体。Redis 需要明确配置其中的至少一个,而
# 不会隐含地使用系统范围内的配置。
#
# tls-ca-cert-file ca.crt
# tls-ca-cert-dir /etc/ssl/certs

# 默认情况下,TLS 端口的客户端(包括复制服务器)需要使用有效的客户端证书进行认证。
#
# 如果指定为 "no",则不需要也不接受客户端证书
# 如果指定为 "optional" 则接受客户端证书,如果提供的话必须是有效的,但不是必须的
#
# tls-auth-clients no
# tls-auth-clients optional

# 默认情况下,Redis 的副本不会尝试与它的主节点建立 TLS 连接
#
# 使用下面的指令来启动副本(从节点)链接上的 TLS
#
# tls-replication yes

# 默认情况下,Redis Cluster 总线使用普通的 TCP 连接。要为总线协议启用 TLS,请使用以下指令。
#
# tls-cluster yes

# 默认情况下,只有 TLSv1.2 和 TLSv1.3 被启用,强烈建议保留旧的正式废弃的版本以减少攻击面。你
# 可以明确指定要支持的 TLS 版本。允许的值不区分大小写,包括 "TLSv1"、"TLSv1.1"、"TLSv1.2"、
# "TLSv1.3"(OpenSSL >= 1.1.1)或任何组合。
# 要只仅仅启用TLSv1.2和TLSv1.3,请使用:
#
# tls-protocols "TLSv1.2 TLSv1.3"

# 配置允许的密码。 更多关于这个字符串的语法信息,请参见 ciphers(1ssl) 手册。
#
# 注意: 这个配置只适用于 <= TLSv1.2
#
# tls-ciphers DEFAULT:!MEDIUM

# 配置允许的 TLSv1.3 密码套件。 关于这个字符串的语法的更多信息,请参见 ciphers(1ssl) manpage,
# 特别是关于 TLSv1.3 密码套件的信息。
#
# tls-ciphersuites TLS_CHACHA20_POLY1305_SHA256

# 在选择密码时,使用服务器的偏好而不是客户端的偏好。默认情况下,服务器会遵循客户端的偏好。
#
# tls-prefer-server-ciphers yes

# 默认情况下,TLS 会话缓存是启用的,以允许支持它的客户更快和更便宜地重新连接。使用下面的指令来禁用缓存。
#
# tls-session-caching no

# 改变默认的 TLS 会话缓存的数量。0 表示将缓存设置为无限大小。默认大小为 20480。
#
# tls-session-cache-size 5000

# 改变缓存的 TLS 会话的默认超时。默认超时时间是 300 秒。
#
# tls-session-cache-timeout 60
6、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.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
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
#                        on startup, and updating Redis status on a regular
#                        basis.
#   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.
#
# The default is "no". To run under upstart/systemd, you can simply uncomment
# the line below:
#
# supervised auto

# 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.
#
# Note that on modern Linux systems "/run/redis.pid" is more conforming
# and should be used instead.
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 notice

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile ""

# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
# syslog-enabled no

# Specify the syslog identity.
# syslog-ident redis

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# syslog-facility local0

# To disable the built in crash log, which will possibly produce cleaner core
# dumps when they are needed, uncomment the following:
#
# crash-log-enabled no

# To disable the fast memory check that's run as part of the crash log, which
# will possibly let redis terminate sooner, uncomment the following:
#
# crash-memcheck-enabled no

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT  where
# dbid is a number between 0 and 'databases'-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 and syslog logging is
# disabled. Basically this means that normally a logo is displayed only in
# interactive sessions.
#
# However it is possible to force the pre-4.0 behavior and always show a
# ASCII art logo in startup logs by setting the following option to yes.
always-show-logo no

# By default, Redis modifies the process title (as seen in 'top' and 'ps') to
# provide some runtime information. It is possible to disable this and leave
# the process name as executed by setting the following to no.
set-proc-title yes

# When changing the process title, Redis uses the following template to construct
# the modified title.
#
# Template variables are specified in curly brackets. The following variables are
# supported:
#
# {title}           Name of process as executed if parent, or type of child process.
# {listen-addr}     Bind address or '*' followed by TCP or TLS port listening on, or
#                   Unix socket if only that's available.
# {server-mode}     Special mode, i.e. "[sentinel]" or "[cluster]".
# {port}            TCP port listening on, or 0.
# {tls-port}        TLS port listening on, or 0.
# {unixsocket}      Unix domain socket listening on, or "".
# {config-file}     Name of configuration file used.
#
proc-title-template "{title} {listen-addr} {server-mode}"
################################# 常规配置 #####################################

# 默认情况下,Redis 不作为一个守护程序运行。如果你需要以守护程序运行 Redis,请设置为 "yes"。
# 注意,Redis 在守护进程中会在 "/var/run/redis.pid" 中写入一个 pid 文件。当 Redis 由 
# upstart 或者 systemd 监管时,这个参数没有影响。
daemonize no

# 如果你从 upstart 或者 systemd 运行 Redis,Redis 可以与你的监督树互动。
# 选项:
# supervised no         —— 没有监督的互动
# supervised upstart    —— 通过让 Redis 进入 SIGSTOP 模式来发出启动信号,要求在你的 
                            upstart 工作配置中加入 "期望停止"。
# supervised systemd    —— 通过在启动时向 $NOTIFY_SOCKET 写入 READY1 来给 systemd 发
                            信号,并定期更新 Redis 状态
# supervised auto       —— 根据 UPSTART_JOB 或 NOTIFY_SOCKET 环境变量检测 upstart 或 
                            systemd 方法
# 注意:这些监督方法只发出 "进程已准备好 "的信号。它们并不能使你的监督员获得连续的平移。
#
# 默认是 "no"。要在 upstart/systemd 下运行,你可以简单地取消注释下面这一行。
#
# supervised auto

# 如果指定了一个 pid 文件,Redis 会在启动时将其写入指定位置,并在退出时将其删除
#
# 当服务器在非守护状态下运行时,如果配置中没有指定 pid 文件,则不会创建 pid 文件。
# 当服务器处理守护状态时,即使没有指定,也会使用 pid 文件,默认为 "/var/run/redis.pid"。
#
# 创建 pid 文件是最大的努力:如果 Redis 无法创建它,也不会发生什么坏事,服务器会正常启动和运行
#
# 注意,在现代的 Linux 系统上,"/run/redis.pid" 更加符合要求,应该用它来代替配置示例的地址。
pidfile /var/run/redis_6379.pid

# 指定服务器日志信息的粗略程度。
# 这可以是其中之一:
# debug     (大量的信息,对开发/测试有用)
# verbose   (许多很少有用的信息,但不像调试级别那样混乱)
# notice    (适度粗略,可能是你在生产中想要的)
# warning   (只有非常重要/关键的信息才会被记录)
loglevel notice

# 指定日志文件的名称。也可以用空字符串来强制 Redis 在标准输出上记录。
# 注意:如果你使用标准输出进行日志记录,但是又进行了 "daemonize" 的设置,日志将发送到 /dev/null
logfile ""

# 是否启用对系统日志的记录,只需要将 "syslog-enabled" 设置为 "yes" 并选择性地更新其它 syslog 
# 参数以适应你的需要。
# syslog-enabled no

# 指定 syslog 身份
# syslog-ident redis

# 指定 syslog 设施,必须是 USER 或在 LOCAL0~LOCAL7 之间
# syslog-facility local0

# 要禁用内置的崩溃日志,这可能会在需要时产生更干净的核心存储
# 请解开以下代码
#
# crash-log-enabled no

# 要禁用作为崩溃日志一部分运行的快速内存检查,这可能会让 Redis 更快的停止
# 请解开以下内容
#
# crash-memcheck-enabled no

# 设置数据库的数量。默认的数据库是 DB0。你可以在每个连接的基础上使用 SELECT  选择一个不同
# 的数据库。其中 dbid 是 0 和 databasese -1 之间的数字
databases 16

# 默认情况下,Redis 只在启动记录到标准输出时显示 ASCII 艺术标志,如果标准输出是 TTY,并且禁用 
# syslog 记录。基本上意味着通常只有在交互式会话中才会显示标识。
#
# 然而,可以通过设置以下选项来强制执行 4.0 之前的行为,并在启动日志中始终显示 ASCII 艺术标识。
always-show-logo no

# 默认情况下,Redis 修改了进程标题(如在 "top" 和 "ps" 中看到的),已提供一些运行时信息,可以通过
# 将以下内容设置为 "no" 来禁用这一点,并保持执行的进行名称不变。
set-proc-title yes

# 当改变进程标题时,Redis 使用以下模板来构建修改后的标题
#
# 模板变量实在大括号中指定的,以下变量是被支持的:
#
# {title}           如果是父进程,则执行的进程名称,或子进程的类型。
# {listen-addr}     绑定地址或者 "*" 后面的 TCP 或者 TLS 端口监听,如果只有 Unix 套接字,也可以使用它
# {server-mode}     特殊模式,即 "[sentinel]" 或 "[cluster]"
# {port}            监听的 TCP 端口或者 0 
# {tls-port}        TLS 端口监听或者 0
# {unixsocket}      Unix 域套接字的监听或者 ""
# {config-file}     使用的配置文件的名称。
#
proc-title-template "{title} {listen-addr} {server-mode}"
7、SNAPSHOTTING(快照配置)
################################ SNAPSHOTTING  ################################

# Save the DB to disk.
#
# save   [  ...]
#
# Redis will save the DB if the given number of seconds elapsed and it
# surpassed the given number of write operations against the DB.
#
# Snapshotting can be completely disabled with a single empty string argument
# as in following example:
#
# save ""
#
# Unless specified otherwise, by default Redis will save the DB:
#   * After 3600 seconds (an hour) if at least 1 change was performed
#   * After 300 seconds (5 minutes) if at least 100 changes were performed
#   * After 60 seconds if at least 10000 changes were performed
#
# You can set these explicitly by uncommenting the following line.
#
# save 3600 1 300 100 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.
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.
rdbcompression yes

# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
# This makes the format more resistant to corruption but there is a performance
# hit to pay (around 10%) when saving and loading RDB files, so you can disable it
# for maximum performances.
#
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
rdbchecksum yes

# Enables or disables full sanitization checks for ziplist and listpack etc when
# loading an RDB or RESTORE payload. This reduces the chances of a assertion or
# crash later on while processing commands.
# Options:
#   no         - Never perform full sanitization
#   yes        - Always perform full sanitization
#   clients    - Perform full sanitization only for user connections.
#                Excludes: RDB files, RESTORE commands received from the master
#                connection, and client connections which have the
#                skip-sanitize-payload ACL flag.
# The default should be 'clients' but since it currently affects cluster
# resharding via MIGRATE, it is temporarily set to 'no' by default.
#
# sanitize-dump-payload no

# The filename where to dump the DB
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.
#
# 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-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.
dir ./
################################ 快照配置  ################################

# 保存这些 DB 到磁盘
#
# save   [  ...]
#
# 如果给定的秒数过去了,并且超过了对 DB 的写操作的给定数量,Redis 将保存 DB
#
# 可以用一个空字符串完全禁用快照,如下面的例子:
#
# save ""
#
# 除非另有指定,否则 Redis 默认情况下将按照如下频率来保存 DB
# * 在 3600 秒(一小时)之后,如果至少进行了 1 次修改
# * 在 300 秒(五分钟)之后,如果至少进行了 100 次修改
# * 在 60 秒(一分钟) 之后,如果至少进行了 10000 次修改
#
# 你可以通过取消对下面的注释来明确设置这些时间
#
# save 3600 1 300 100 60 10000

# 默认情况下,如果启用了 RDB 快照(至少有一个保存点),并且最近一次保存失败 Redis 将停止
# 接受写操作。这将使用户意识到(以一种艰难的方式)数据没有正确地持久化在磁盘上。有可能没有
# 人注意到一个问题,将会导致一些灾难发生
#
# 如果后台保存过程将再次开始工作,Redis 将自动允许再次写入
#
# 然后,如果你已经设置了对 Redis 服务器和持久化的适当监控,你可能想禁用这个功能,这样即使
# 磁盘、权限等出现问题,Redis 也会继续正常工作
stop-writes-on-bgsave-error yes

# 转存 .rdb 数据库时使用 LZF 压缩字符串对象?默认情况下,压缩是启用的,因为它几乎总是一个
# 胜利。如果你想在保存过程中节省一些 CPU,把它设置为 "no",但是如果你有可压缩的值或键,数
# 据集可能会更大。
rdbcompression yes

# 从 RDB 的第五个版本开始,CRC64 校验被放在文件的最后,这使得格式更容易被破坏,但在保存和
# 加载 RDB 文件时,会有性能上的损失(大约 10%),所以你可以禁用它已获得最大的性能。
#
# 在禁用用校验和的情况下创建的 RDB 文件的校验和为零,这将告诉加载代码跳过检查
rdbchecksum yes

# 在加载 RDB 或 RESTORE 有效载荷时,启用或者禁用对 ziplist 和 listpack 等的完全净化检查,
# 这可以减少以后在处理命令时出现断言或崩溃的机会
# 选项:
# no        —— 从不执行全面的净化检查
# yes       —— 始终执行全面的净化检查
# clients   —— 只针对客户端进行全面的净化检查
                不包括 RDB 文件,从主节点收到的 RESTORE 命令
                以及有 "skip-sanitize-payload ACL" 标记的客户端连接
# 默认值应该是 "clients" 但是由于它目前影响到通过 MIGRATE 进行的集群重分
# 所以默认情况下暂时设置为 "no"
#
# sanitize-dump-payload no

# 转存数据库的文件名
dbfilename dump.rdb

# 在没有启用数据持久化的实例中,移除复制使用的 RDB 文件。默认情况下,这个选项是禁用的,但是在
# 某些情况下,出于法规或者其它安全考虑,主节点为例给从节点提供信息而在磁盘上持久化的 RDB 文件,
# 或者从节点为了在初始同步中加载它们而存储在磁盘上的 RDB 文件,应该尽快删除。注意:这个选项只
# 适用于同时禁用 AOF 和 RDB 持久化的实例,否则会被完全忽略
#
# 另一种获取相同效果的方法(有时更好)是在主节点和从节点的实例上使用无盘复制,但是在复制的情况下,
# 无盘复制并不总是一种选择
rdb-del-sync-files no

# 工作目录
#
# DB 将会被写入到这个命令中,文件名为上面 "dbfilename" 所指定的文件名称
#
# AOF 文件也将会被创建在这个目录中
#
# 注意此处你只能指定目录而不能指定文件名称
dir ./
8、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.
# 2) Redis replicas are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition replicas automatically try to reconnect to masters
#    and resynchronize with them.
#
# replicaof  

# 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 
#
# 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:
#
# masteruser 
#
# When masteruser is specified, the replica will authenticate against its
# master using the new AUTH form: AUTH  .

# 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.
#
# 2) If replica-serve-stale-data is set to 'no' the replica will reply with error
#    "MASTERDOWN Link with MASTER is down and replica-serve-stale-data is set to 'no'"
#    to all data access commands, excluding commands such as:
#    INFO, REPLICAOF, AUTH, 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.
#
# 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.
#
# 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.
# 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.
#
# 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.
repl-diskless-sync yes

# 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.
repl-diskless-sync-delay 5

# When diskless replication is enabled with a delay, it is possible to let
# the replication start before the maximum delay is reached if the maximum
# number of replicas expected have connected. Default of 0 means that the
# maximum is not defined and Redis will wait the full delay.
repl-diskless-sync-max-replicas 0

# -----------------------------------------------------------------------------
# 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 you know what you are doing.
# -----------------------------------------------------------------------------
#
# 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 replica buffers).
# 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:
#
# "disabled"    - Don't use diskless load (store the rdb file to the disk first)
# "on-empty-db" - Use diskless load only when it is completely safe.
# "swapdb"      - Keep current db contents in RAM while parsing the data directly
#                 from the socket. Replicas in this mode can keep serving current
#                 data set while replication is in progress, except for cases where
#                 they can't recognize master as having a data set from same
#                 replication history.
#                 Note that this requires sufficient memory, if you don't have it,
#                 you risk an OOM kill.
repl-diskless-load disabled

# Master send PINGs to its replicas in a predefined interval. It's possible to
# change this interval with the repl_ping_replica_period option. The default
# value is 10 seconds.
#
# repl-ping-replica-period 10

# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of replica.
# 2) Master timeout from the point of view of replicas (data, pings).
# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).
#
# 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.
#
# repl-timeout 60

# Disable TCP_NODELAY on the replica socket after SYNC?
#
# 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.
#
# 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.
#
# 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.
repl-disable-tcp-nodelay no

# Set the replication backlog size. The backlog is a buffer that accumulates
# replica data when replicas are disconnected for some time, so that when a
# replica wants to reconnect again, often a full resync is not needed, but a
# partial resync is enough, just passing the portion of data the replica
# missed while disconnected.
#
# The bigger the replication backlog, the longer the 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.
#
# 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.
#
# 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.
#
# A value of 0 means to never release the backlog.
#
# repl-backlog-ttl 3600

# The replica priority is an integer number published by Redis in the INFO
# output. It is used by Redis Sentinel in order to select a replica to promote
# into a master if the master is no longer working correctly.
#
# A replica with a low priority number is considered better for promotion, so
# for instance if there are three replicas with priority 10, 100, 25 Sentinel
# will pick the one with priority 10, that is the lowest.
#
# However a special priority of 0 marks the replica as not able to perform the
# role of master, so a replica with priority of 0 will never be selected by
# Redis Sentinel for promotion.
#
# By default the priority is 100.
replica-priority 100

# The propagation error behavior controls how Redis will behave when it is
# unable to handle a command being processed in the replication stream from a master
# or processed while reading from an AOF file. Errors that occur during propagation
# are unexpected, and can cause data inconsistency. However, there are edge cases
# in earlier versions of Redis where it was possible for the server to replicate or persist
# commands that would fail on future versions. For this reason the default behavior
# is to ignore such errors and continue processing commands.
#
# If an application wants to ensure there is no data divergence, this configuration
# should be set to 'panic' instead. The value can also be set to 'panic-on-replicas'
# to only panic when a replica encounters an error on the replication stream. One of
# these two panic values will become the default value in the future once there are
# sufficient safety mechanisms in place to prevent false positive crashes.
#
# propagation-error-behavior ignore

# Replica ignore disk write errors controls the behavior of a replica when it is
# unable to persist a write command received from its master to disk. By default,
# this configuration is set to 'no' and will crash the replica in this condition.
# It is not recommended to change this default, however in order to be compatible
# with older versions of Redis this config can be toggled to 'yes' which will just
# log a warning and execute the write command it got from the master.
#
# replica-ignore-disk-write-errors no

# -----------------------------------------------------------------------------
# By default, Redis Sentinel includes all replicas in its reports. A replica
# can be excluded from Redis Sentinel's announcements. An unannounced replica
# will be ignored by the 'sentinel replicas ' command and won't be
# exposed to Redis Sentinel's clients.
#
# This option does not change the behavior of replica-priority. Even with
# replica-announced set to 'no', the replica can be promoted to master. To
# prevent this behavior, set replica-priority to 0.
#
# replica-announced yes

# 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.
#
# The N replicas need to be in "online" state.
#
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the replica, that is usually sent every second.
#
# This option does not GUARANTEE that N replicas will accept the write, but
# will limit the window of exposure for lost writes in case not enough replicas
# are available, to the specified number of seconds.
#
# For example to require at least 3 replicas with a lag <= 10 seconds use:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# Setting one or the other to 0 disables the feature.
#
# By default min-replicas-to-write is set to 0 (feature disabled) and
# min-replicas-max-lag is set to 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.
#
# The listed IP address and port normally reported by a replica is
# obtained in the following way:
#
#   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.
#
# 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
################################# 复制配置 #################################

# 主-副本复制,使用 replicaof 使一个 Redis 实例成为另一个 Redis 服务器的副本
# 关于 Redis 复制,有几件事情需要尽快了解
#
#   +------------------+      +---------------+
#   |      主节点       | ---> |    从节点      |
#   |   (接受写操作。)   |      |  (完全复制。)   |
#   +------------------+      +---------------+
#
# 1) Redis 复制是异步的,但你可以配置一个主节点,如果它看起来没有与至少给定数量的从节点连接,
     则停止接受写入。
# 2) 如果复制链接在相对较小的时间内丢失,Redis 复制能够与主节点进行部分同步。你可能想根据你
     的需要,用一个合理的值来配置复制积压的大小(见本文件的下几节)。
# 3) 复制是自动的,不需要用户干预。在一个网络分区之后,复制会自动尝试重新连接到主节点与它们重
     新同步。
#
# replicaof  

# 如果主节点有密码保护(使用下面的 "requirepass" 配置指令),就可以告诉从节点在开始复制同步
# 过程之前要进行认证,否则主节点将拒绝副本请求
#
# masterauth 
#
# 然而,如果你使用 Redis ACL (适用于 Redis 版本 6 或者更高),而默认用户不能运行 PSYNC 
# 命令和/或复制所需的其它命令,这就不够了,在这种情况下,最好配置一个特殊的用户用于复制,并将主
# 用户的配置指定为这样:
#
# masteruser 
#
# 当指定 "masteruser" 时,副本将使用新的 AUTH 形式对其主节点进行
# 认证: AUTH  .

# 当一个副本失去与主节点的连接时,或者当复制仍在进行时,副本可以以两分钟不同的方式行动:
#
# 1) 如果 "replica-serve-stale-data" 被设置为 "yes"(默认),复制体仍然会回复客户端的请求
#    可能会有过时的数据,或者如果这是第一次同步,数据集可能只是空的。
#
# 2) 如果 "replica-serve-stale-data" 被设置为 "no",那么对于所有的数据访问命令,复制体将回
#    复错误 "MASTERDOWN 与 MASTER 的连接已经关闭 'replica-serve-stale-data' 被设置为'no'",
#    不包括诸如以下命令:
#    INFO、REPLICAOF、AUTH、SHUTDOWN、REPLCONF、ROLE、CONFIG、SUBSCRIBE、UNSUBSCRIBE、
#    PSUBSCRIBE、PUNSUBSCRIBE、PUBLISH、PUBSUB、COMMAND、POST、HOST 和 LATENCY
#
replica-serve-stale-data yes

# 你可以配置一个副本实例来接受或者不接受写操作。对于副本实例进行写入可能对存储一些短暂的数据很有用
# (因为写在副本上的数据在与主站重新同步后很容易被删除)但是如果客户因此配置错误而向其写入也可能导
# 致问题
#
# 从 Redis 2.6开始,默认复制是只读的。
#
# 注意:只读副本的设计不是为了暴露给互联网上不受信任的客户端,它只是一个保护层,防止实例被滥用只读副
# 本仍然默认输出所有的管理命令,如:CONFIG、DEBUG 等。在有限的范围内,你可以使用 "rename-command"
# 来提高只读副本的安全性,以映射所有的管理/危险命令
replica-read-only yes

# 副本同步策略:磁盘或者socket.
#
# 新的复制体和重新连接的复制体,如果不能继续复制过程,只是接收差异需要做所谓的 "完全同步"。一个 RDB 
# 文件从主节点被传送到复制站点
#
# 传递可以以两种不同的方式:
#
# 1) Disk-backed: Redis 主进程创建一个新的进程,将 RDB 文件写入磁盘。之后改文件由父进程递增地转移
#                 到复制体上。
# 2) Diskless:    Redis 主站创建一个新的进程,直接将 RDB 文件写入复制套接字,完全不接触磁盘。
#
# 在有磁盘支持的复制中,在生成 RDB 文件的同时,更多的复制可以被排队,并在当前生成的 RDB 文件的
# 子代完成工作后立即提供 RDB 文件。而用无盘复制,一旦传输开始,新到达的复制被排队,单单的传输终止时
# 新的传输将开始。
#
# 当使用无盘复制时,主站在开始传输前会等待一段可配置的时间(以秒为单位),希望多个复制会到达
# 传输可以并行化。
#
# 对于慢速磁盘和快速(大带宽)网络,无盘复制效果更好。
repl-diskless-sync yes

# 当启用无盘复制时,可以配置服务器等待的时间,以便产生通过套接字将 RDB 传输到复制体的子程序。
#
# 这一点很重要,因为一旦传输开始,就不可能为到达的新副本提供服务,这些副本将被排在下一次 RDB 传输
# 的队列中。所以服务器要等待一个延迟,以便让更多的副本到达。
#
# 延迟的单位是秒,默认是 5 秒。要完全禁用它,只需将其设置为 0 秒,传输将尽快开始。
repl-diskless-sync-delay 5

# 当启用无盘复制并有延迟的时候,如果预期的最大复制数量已经连接,有可能让复制在达到最大延迟之前开始
# 默认值为 0,意味着没有定义最大值,Redis 将等待整个延迟。
repl-diskless-sync-max-replicas 0

# -----------------------------------------------------------------------------
# 警告:RDB 无磁盘负载是实验性的。因为在这种设置中,副本不会立即在磁盘上存储 RDB,所以在故障
# 恢复期间可能会导致数据丢失。RDB 无盘加载 + Redis 模块不处理 I/O 读取也可能导致 Redis 在
# 与主站的初始同步阶段出现 I/O 错误时终止。只有当你知道你在做什么的时候才使用。
# -----------------------------------------------------------------------------
#
# Replica 可以直接从套接字中加载它从复制链接中读取 RDB ,或者将 RDB 存储到一个文件中,在完全
# 接收到主站的 RDB 后再读取该文件。
#
# 在很多情况下,磁盘比网络慢,存储和加载 RDB 文件可能会增加复制时间(甚至会增加主站对 Write 
# 内存和复制缓冲区的 Copy)。然而,直接从套接字中解析 RDB 文件可能意味着收到完整的 RDB 之前,
# 我们必须刷新当前数据库内容。由于这个原因,我们有以下选项:
#
# "disabled"    - 不要使用无盘加载(先将rdb文件存储到磁盘)。
# "on-empty-db" - 只有在完全安全的情况下才使用无盘负载。
# "swapdb"      - 在 RAM 中保留当前数据库的内容,同时直接从套接字中解析数据。这种模式下的
#                 复制可以在复制过程中继续提供当前的数据集,除非它们不能识别主站是否有相同复制历史的数据
#                 集。注意,这需要足够的内存,如果你没有内存,你就有可能出现 OOM 死机。
repl-diskless-load disabled

# 主站以预定的时间间隔向其副本发送 PING。可以用 repl_ping_replica_period 选项来改变这个时间间隔。
# 默认值是10秒。
#
# repl-ping-replica-period 10

# 下面的选项设置了复制的超时时间:
#
# 1) 在SYNC期间,从复制的角度来看,批量传输I/O。
# 2) 从复制(数据、平移)的角度看,主站超时。
# 3) 从主站的角度看复制超时(REPLCONF ACK pings)。
#
# 重要的是要确保这个值大于 repl-ping-replica-period 指定的值,否则每次主站和副本之间的流量低时
# 都会检测到超时。默认值是 60 秒。
#
# repl-timeout 60

# 在 SYNC 之后禁用复制套接字的 TCP_NODELAY?
#
# 如果你选择 "yes",Redis 将使用较少的 TCP 数据包和较少的带宽来发送数据到副本。
# 但这可能会增加数据在复制端出现的延迟,在使用默认配置的 Linux 内核中,最多可达 40 毫秒。
#
# 如果你选择 "no",数据在复制端出现的延迟将减少,但复制将使用更多带宽。
#
# 默认情况下,我们会对低延迟进行优化,但在流量非常大的情况下,或者当主站和复制站相距很多跳时,
# 将其转为 "yes" 可能是一个好主意。
repl-disable-tcp-nodelay no

# 设置复制积压的大小。积压是一个缓冲区,当复制在一段时间内断开连接时,积压复制的数据,这样当复制
# 想再次重新连接时,往往不需要完全重新同步,而只需要部分重新同步即可,只是传递复制在断开连接时错过的部分数据。
#
# 复制积压越大,复制可以忍受断开连接的时间就越长,以后就可以进行部分重新同步。
#
# 只有在至少有一个副本连接的情况下才会分配积压。
#
# repl-backlog-size 1mb

# 当主站在一段时间内没有连接副本后,积压的数据将被释放。下面的选项配置了从最后一个副本断开连接开始,
# 需要经过多少秒才能释放积压的缓冲区。
#
# 请注意,副本永远不会因为超时而释放积压,因为它们以后可能会被提升为主站,并且应该能够正确地与其他
# 副本进行 "部分再同步":因此它们应该始终积累积压。
#
# 如果参数设置为 0 ,则表示从不释放积压
#
# repl-backlog-ttl 3600

# 复制的优先级是一个整数,由 Redis 在 INFO 输出中公布。它被 Redis Sentinel 用来选择一个副本,
# 以便在主副本不再正常工作时将其提升为主副本。
#
# 优先级较低的副本被认为更适合推广,因此,例如,如果有三个优先级为10、100、25的副本,Sentinel 
# 会选择优先级为 10 的副本,这是最低的。
#
# 然而,一个特殊的优先级为 0 的副本标志着它不能执行主站的角色,所以优先级为 0 的副本将永远不会被 
# Redis Sentinel 选中进行推广。
#
# 默认情况下,优先级为100。
replica-priority 100

# 传播错误行为控制 Redis 在无法处理从主站复制流中处理的命令或在从 AOF 文件读取时处理的命令时的行
# 为。传播过程中发生的错误是出乎意料的,并可能导致数据不一致。然而,在早期版本的 Redis 中存在一些
# 边缘情况,服务器有可能复制或持久化那些在未来版本上会失败的命令。由于这个原因,默认行为是忽略此类错
# 误并继续处理命令。
#
# 如果一个应用程序想确保没有数据分歧,这个配置应该被设置为 'panic',而不是该值也可以设置为 
# 'panic-on-replicas',只在副本在复制流中遇到错误时才会发生恐慌。一旦有足够的安全机制来防止假阳性
# 崩溃,这两个恐慌值中的一个将成为未来的默认值。
#
# propagation-error-behavior ignore

# 复制体忽略磁盘写入错误控制复制体的行为,当它无法坚持从其主站收到的写入命令到磁盘。默认情况下,该配置被
# 设置为 "no",在这种情况下复制会崩溃。不建议改变这个默认值,但是为了与旧版本的 Redis 兼容,这个配置
# 可以切换为 "yes",这将只是记录一个警告,并执行从主站得到的写命令。
#
# replica-ignore-disk-write-errors no

# -----------------------------------------------------------------------------
# 默认情况下,Redis Sentinel 在其报告中包括所有副本。一个副本可以从 Redis Sentinel 的公告
# 中排除。一个未公布的副本将被 'sentinel replicas ' 命令忽略,并且不会暴露给 Redis 
# Sentinel 的客户端。
#
# 这个选项并不改变副本优先级的行为。即使把 replica-announced 设置为'no',副本也可以被提升为
# master。为了防止这种行为,请将 replica-priority 设置为 0。
#
# replica-announced yes

# 如果连接的副本少于 N 个,滞后时间小于或等于 M 秒,主站就有可能停止接受写入。
#
# N 个复制体需要处于 "在线 "状态。
#
# 以秒为单位的滞后,必须 <= 指定的值,从副本收到的最后一次 ping 计算出来,通常每秒钟发送一次。
#
# 这个选项并不保证 N 个副本会接受写入,但是在没有足够的副本可用的情况下,会将丢失写入的窗口
# 限制在指定的秒数。
#
# 例如,要求至少有3个副本,滞后<=10秒,使用:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# 将其中一个设置为0,就可以禁用该功能。
#
# 默认情况下,min-replicas-to-write 被设置为 0(功能禁用),min-replicas-max-lag 被设置为 10。

# Redis 主站能够以不同的方式列出所附副本的地址和端口。例如,"INFO 复制 "部分提供了这些信息,除其他
# 工具外,Redis Sentinel 使用这些信息来发现复制实例。另一个提供该信息的地方是主站的 "ROLE "命令的
# 输出。
#
# 通常由复制体报告的列出的 IP 地址和端口是通过以下方式获得的:
#
#   IP: 该地址是通过检查复制体用于与主站连接的套接字的对等地址来自动检测的。
#
#   Port: 该端口在复制握手期间由复制体传达,通常是复制体用来监听连接的端口。
#
# 然而,当使用端口转发或网络地址转换(NAT)时,副本实际上可以通过不同的IP和端口对到达。
# 复制体可以使用下面两个选项,以便向其主站报告一组特定的 IP 和端口,这样 INFO 和 ROLLE 都会报告这些值。
#
# 如果你只需要覆盖端口或 IP 地址,就没有必要同时使用这两个选项。
#
# replica-announce-ip 5.5.5.5
# replica-announce-port 1234
9、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
# a radix key indexed by key name, what clients have which keys. In turn
# this is used in order to send invalidation messages to clients. Please
# check this page to understand more about the feature:
#
#   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.
#
# 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.
#
# 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.
#
# 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
############################### 键的追踪 #################################

# Redis 实现了对客户端缓存值的服务器辅助支持。这是用一个无效表实现的,该表使用一个以键
# 名为索引的弧度键,记住了哪些客户拥有哪些键。反过来,这被用来向客户端发送无效信息。请查
# 看此页面以了解更多关于该功能的信息:
#
# https://redis.io/topics/client-side-caching
#
# 当客户端的跟踪功能被启用时,所有的只读查询都被认为是被缓存的:这将迫使 Redis 在失效表
# 中存储信息。当键被修改时,这些信息会被冲走,无效信息会被发送到客户端。然而,如果工作负
# 载主要是读取,Redis 可能会使用越来越多的内存,以跟踪许多客户端获取的键。
#
# 出于这个原因,我们可以为无效表配置一个最大的填充值。默认情况下,它被设置为 1M 的键,一旦
# 达到这个限制,Redis 将开始驱逐无效表中的键,即使它们没有被修改,只是为了回收内存:这将反
# 过来迫使客户端无效的缓存值。基本上,表的最大尺寸是在你想花费服务器端的内存来跟踪谁缓存了什么
# 的信息,以及客户端在内存中保留缓存对象的能力之间进行权衡。
#
# 如果你把这个值设置为 0 ,那就意味着没有任何限制,Redis 会根据需要在失效表中保留多少个键。在
# "stats" INFO 部分,你可以找到每个给定时刻无效表中的键的数量信息。
#
# 注意:当在广播模式下使用键的追踪时,不会在服务器端使用内存,所以这个设置是无用的。
#
# tracking-table-max-keys 1000000
10、SECURITY(安全配置)
################################## 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 ACL users are defined in the following format:
#
#   user  ... 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.
#
# The ACL rules that describe what a user can do are the following:
#
#  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.
#  skip-sanitize-payload    RESTORE dump-payload sanitization is skipped.
#  sanitize-payload         RESTORE dump-payload is sanitized (default).
#  +   Allow the execution of that command.
#               May be used with `|` for allowing subcommands (e.g "+config|get")
#  -   Disallow the execution of that command.
#               May be used with `|` for blocking subcommands (e.g "-config|set")
#  +@ 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.
#  +|first-arg  Allow a specific first argument of an otherwise
#                        disabled command. It is only supported on commands with
#                        no sub-commands, and is not allowed as negative form
#                        like -SELECT|1, only additive starting with "+". This
#                        feature is deprecated and may be removed in the future.
#  allcommands  Alias for +@all. Note that it implies the ability to execute
#               all the future commands loaded via the modules system.
#  nocommands   Alias for -@all.
#  ~   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.
# %R~  Add key read pattern that specifies which keys can be read 
#               from.
# %W~  Add key write pattern that specifies which keys can be
#               written to. 
#  allkeys      Alias for ~*
#  resetkeys    Flush the list of allowed keys patterns.
#  &   Add a glob-style pattern of Pub/Sub channels that can be
#               accessed by the user. It is possible to specify multiple channel
#               patterns.
#  allchannels  Alias for &*
#  resetchannels            Flush the list of allowed channel patterns.
#  >  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).
#  <  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
#               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" status. After "resetpass" the user has no associated
#               passwords and there is no way to authenticate without adding
#               some password (or setting it as "nopass" later).
#  reset        Performs the following actions: resetpass, resetkeys, off,
#               -@all. The user returns to the same state it has immediately
#               after its creation.
# ()   Create a new selector with the options specified within the
#               parentheses and attach it to the user. Each option should be 
#               space separated. The first character must be ( and the last 
#               character must be ).
# clearselectors            Remove all of the currently attached selectors. 
#                           Note this does not change the "root" user permissions,
#                           which are the permissions directly applied onto the
#                           user (outside the parentheses).
#
# 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:
#
#   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:
#
#   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.
#
# Basically ACL rules are processed left-to-right.
#
# The following is a list of command categories and their meanings:
# * keyspace - Writing or reading from keys, databases, or their metadata 
#     in a type agnostic way. Includes DEL, RESTORE, DUMP, RENAME, EXISTS, DBSIZE,
#     KEYS, EXPIRE, TTL, FLUSHALL, etc. Commands that may modify the keyspace,
#     key or metadata will also have `write` category. Commands that only read
#     the keyspace, key or metadata will have the `read` category.
# * read - Reading from keys (values or metadata). Note that commands that don't
#     interact with keys, will not have either `read` or `write`.
# * write - Writing to keys (values or metadata)
# * admin - Administrative commands. Normal applications will never need to use
#     these. Includes REPLICAOF, CONFIG, DEBUG, SAVE, MONITOR, ACL, SHUTDOWN, etc.
# * dangerous - Potentially dangerous (each should be considered with care for
#     various reasons). This includes FLUSHALL, MIGRATE, RESTORE, SORT, KEYS,
#     CLIENT, DEBUG, INFO, CONFIG, SAVE, REPLICAOF, etc.
# * connection - Commands affecting the connection or other connections.
#     This includes AUTH, SELECT, COMMAND, CLIENT, ECHO, PING, etc.
# * blocking - Potentially blocking the connection until released by another
#     command.
# * fast - Fast O(1) commands. May loop on the number of arguments, but not the
#     number of elements in the key.
# * slow - All commands that are not Fast.
# * pubsub - PUBLISH / SUBSCRIBE related
# * transaction - WATCH / MULTI / EXEC related commands.
# * scripting - Scripting related.
# * set - Data type: sets related.
# * sortedset - Data type: zsets related.
# * list - Data type: lists related.
# * hash - Data type: hashes related.
# * string - Data type: strings related.
# * bitmap - Data type: bitmaps related.
# * hyperloglog - Data type: hyperloglog related.
# * geo - Data type: geo related.
# * stream - Data type: streams related.
#
# For more information about ACL configuration please refer to
# 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.
acllog-max-len 128

# Using an external ACL file
#
# 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.
#
# 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  as usually, or more explicitly with AUTH default 
# if they follow the new protocol: both will work.
#
# The requirepass is not compatible with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared

# New users are initialized with restrictive permissions by default, via the
# equivalent of this ACL rule 'off resetkeys -@all'. Starting with Redis 6.2, it
# is possible to manage access to Pub/Sub channels with ACL rules as well. The
# default Pub/Sub channels permission if new users is controlled by the
# acl-pubsub-default configuration directive, which accepts one of these values:
#
# allchannels: grants access to all Pub/Sub channels
# resetchannels: revokes access to all Pub/Sub channels
#
# From Redis 7.0, acl-pubsub-default defaults to 'resetchannels' permission.
#
# acl-pubsub-default resetchannels

# 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.
#
# 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.
################################## 安全配置 ###################################

警告:由于 Redis 的速度相当快,一个外部用户对于一个现代的盒子每秒可以尝试 100 万个密码。这意
# 味着你应该使用非常强大的密码,否则将非常容易被破解。请注意,因为密码实际上是客户端和服务器之
# 间的共享秘密,不应该被任何人类记住,密码可以很容易第从 /dev/urandom 或者其它什么地方得到一
# 个长字符串,所以通过使用一个长的和不可猜测的密码,来防止暴力攻击。

# Redis ACL用户的定义格式如下:
#
# user  ... acl rules ...
#
# 例如:
#
# user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
#
# 特殊的用户名 "default" 被用于新的连接。如果这个用户有 "nopass" 规则,那么新连接将立即被认证
# 为 "default" 用户,而不需要通过 AUTH 命令提供任何密码。否则,如果 "default" 用户没有标记为 
# "nopass" ,那么连接将以未认证状态开始,并需要 AUTH (或者 HELLO 命令的 AUTH 选项)才能被认
# 证并开始工作。
#
# 描述一个用户可以做什么的 ACL 规则如下:
#
# on                    启用该用户:可以作为该用户进行认证。
# off                   禁用该用户:不在可能以该用户身份进行认证,但是已经认证的连接将继续可以工作。
# skip-sanitize-payload RESTORE dump-payload 的消毒处理被跳过。
# sanitize-payload      RESTORE dump-payload 是已经消毒的(默认)。
# +            允许执行该命令。
                        可以与 "|" 一起使用,允许执行子命令(例如:"+config|get")。
# -            不允许执行该命令。
                        可以与 "|" 一起使用,以阻止子命令的执行(例如:"-config|get")。
# +@          允许执行该类别的所有命令。
                        有效的类别包括 @admin,@set,@sortedset,...等等,请参阅 server.c 文件中的完整列表,其中描述
                        和定义了 Redis 命令表。特殊类别 @all 表示所有命令,但目前存在于服务器中,将来会通过模块加载。
# +|first-arg  允许在其他情况下禁用的命令中加入一个特定的第一个参数。它只支持没有子命令的命令,
                        并且不允许负数形式的功能被废弃,将来可能会被删除。
# allcommands  Alias for +@all.    注意,他意味着能够执行所有通过模块系统加载的未来命令。
# nocommands   Alias for -@all.
# ~            添加一个可以被提及的键的模式,作为命令的一部分,例如:~* 允许素有的键。该模式是一个类似于 
                        KEYS 的 glob 风格的模式,可以指定多个模式。
# %R~          添加键的读取模式,指定哪些键可以被读取。
# %W~          添加键的写入模式,指定哪些键可以被写入。
# allkeys      Alias for ~*
# resetkeys             刷新允许的键模式列表。
# &            添加一个用户可以访问的 Pub/Sub 通道的 glob 风格模式,它可以指定多个频道模式。
# allchannels  Alias for &*
# resetchannels         刷新允许的频道模式的列表。
# >           把这个密码添加到用户的有效密码列表中,例如:>mypass 将添加 "mypass" 到列表中。这条指令清除了 "nopass" 标志(见下文)
# <           从有效的密码列表中删除此密码。
# nopass                该用户所有设置的密码都被删除,并且该用户被标记为不需要密码:这意味着每一个密码都将对该用户有效。如果这个指令被用于默认用户,
                        每一个新的连接将被立即认证为默认用户而不需要任何明确的 AUTH 命令,请注意,"resetpass" 指令将清除这一条件。
# resetpass             刷新允许的密码列表,此外,还删除了 "nopass" 状态,在 "resetpass" 之后,用户没有相关的密码,如果不添加一些密
                        码(或者以后设置为 "nopass"),就没有办法进行认证。
# reset                 执行以下操作:resetpass, resetkeys, off, -@all。用户返回到其创建后立即具有的状态。
# ()           用括号内指定的选项创建一个新的现在容器,并将其附加到用户身上,每个选项应以空格分隔。第一个字符必须是(最后一个字符也必须是)
# clearselectors        删除所有当前附加的选择器。 注意这不会改变 "根" 用户的权限,这是直接应用于用户的权限(在括号外)。
#
# ACL 规则可以以任何顺序指定:例如,你可以从密码开始,然后是标志,或钥匙模式。
# 但是请注意,加法和减法规则的含义会根据顺序的不同而改变。
# 请参考下面的例子:
#
# user alice on +@all -DEBUG ~* >somepassword
# 
# 这将允许 "alice "使用所有的命令,但 DEBUG 命令除外,因为 +@all 将所有的命令添加到 alice 可以使用的命令集合中,
# 后来 DEBUG 被删除。然而,如果我们颠倒两个 ACL 规则的顺序,结果将是不同的。
#
# user alice on -DEBUG +@all ~* >somepassword
#
# 现在,当 alice 在允许的命令集合中还没有命令时,DEBUG 被删除了,后来所有的命令都被加入了,所以用户将能够执行所有的命令。
#
# 基本上 ACL 规则是从左到右处理的。
#
# 下面是一个命令类别及其含义列表:
# * keyspace    —— 以不分类型的方式从键、数据库或其元数据中写入或读取。包括DEL, RESTORE, DUMP, RENAME, EXISTS, 
                    DBSIZE, KEYS, EXPIRE, TTL, FLUSHALL, 等。可以修改钥匙空间、钥匙或元数据的命令也会有 "写 "的
                    类别。只读取钥匙空间、钥匙或元数据的命令将有`读`类别。
# * read        —— 从键(值或元数据)读取。注意,不与键交互的命令不会有`读`或`写`。
# * write       —— 向键值(值或元数据)写入。
# * admin       —— 管理命令。普通的应用程序永远不需要使用这些命令。包括 REPLICAOF, CONFIG, DEBUG, SAVE, MONITOR, 
                    ACL, SHUTDOWN, 等。
# * dangerous   —— 潜在的危险(由于各种原因,每个人都应该谨慎考虑)。这包括FLUSHALL, MIGRATE, RESTORE, SORT, KEYS, 
                    CLIENT, DEBUG, INFO, CONFIG, SAVE, REPLICAOF, 等等。
# * connection  —— 影响该连接或其他连接的命令。这包括AUTH, SELECT, COMMAND, CLIENT, ECHO, PING, 等。
# * blocking    —— 可能会阻断连接,直到被其他命令释放。
# * fast        —— 快速的O(1)命令。可能在参数的数量上循环,但不包括元素的数量进行循环。
# * slow        —— 所有不属于快速的命令。
# * pubsub      —— PUBLISH / SUBSCRIBE相关的命令。
# * transaction —— WATCH / MULTI / EXEC 相关的命令。
# * scripting   —— 与脚本有关。
# * set         —— 数据类型:集合相关。
# * sortedset   —— 数据类型:zsets相关。
# * list        —— 数据类型:列表相关。
# * hash        —— 数据类型:哈希值相关。
# * string      —— 数据类型:字符串相关。
# * bitmap      —— 数据类型:与位图相关。
# * hyperloglog —— 数据类型:超日志相关。
# * geo         —— 数据类型:与地理有关。
# * stream      —— 数据类型:与流有关。
#
# 关于ACL配置的更多信息,请参考Redis网站:https://redis.io/topics/acl

# ACL 日志
#
# ACL 日志跟踪与 ACL 相关的失败命令和认证事件。ACL 日志对于解决被 ACL 阻止的失败命令很有用。
# ACL 日志被存储在内存中。你可以用 ACL LOG RESET 来回收内存。定义 ACL 日志的最大条目长度如下。
acllog-max-len 128

# 使用一个外部的 ACL 文件
#
# 不在此文件中配置用户,可以使用一个独立的文件,只列出用户。这两种方法不能混用:如果你在这里配置用户,
# 同时激活外部 ACL 文件,服务器将拒绝启动。
#
# 外部 ACL 用户文件的格式与 redis.conf 中用于描述用户的格式完全相同。
#
# aclfile /etc/redis/users.acl

# 重要提示:从 Redis 6开始,"requirepass "只是新 ACL 系统之上的一个兼容层。该选项的作用只是为默认用户设置密码。
# 客户端仍将像往常一样使用 AUTH  进行认证,或者更明确地使用 AUTH default ,
# 如果他们遵循新的协议:两者都可以工作。
#
# requirepass 与 aclfile 选项和 ACL LOAD 命令不兼容,这些将导致 requirepass 被忽略。
#
# requirepass foobared

# requirepass 与 aclfile 选项和 ACL LOAD不兼容,新用户默认以限制性权限初始化,通过相当于这个 ACL 规则 'off resetkeys -@all'。
# 从 Redis 6.2 开始,也可以用 ACL 规则管理对 Pub/Sub 通道的访问。如果是新用户,默认的 Pub/Sub 通道权限是由 acl-pubsub-default 
# 配置指令控制的,它接受以下值之一。
#
# allchannels   :  授予所有的 Pub/Sub 通道的访问权限
# resetchannels :  撤销对所有的 Pub/Sub 通道的访问权限
#
# 从 Redis 7.0 开始,acl-pubsub-default 默认为 "resetchannels" 权限。
#
# acl-pubsub-default resetchannels

# 命令重命名(弃用)
#
# ------------------------------------------------------------------------
# 警告:如果可能的话,避免使用这个选项。取而代之的是使用 ACL 从默认用户中删除命令,只把
# 它们放在你为管理目的而创建的一些管理员用户中。
# ------------------------------------------------------------------------
#
# 在一个共享环境中,有可能改变危险命令的名称。例如,CONFIG 命令可以被重新命名为难以猜测的名字,这样它仍然可以用于内部使用的工具,
# 但不能用于普通客户。
#
# 示例:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# 也可以通过将一个命令重命名为一个空字符串:
#
# rename-command CONFIG ""
#
# 请注意,改变记录在 AOF 文件中或传送到副本中的命令的名称可能会导致问题。
11、CLIENTS(客户端配置)
################################### 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).
#
# Once the limit is reached Redis will close all the new connections sending
# an error '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.
#
# maxclients 10000
################################### 客户端 ####################################

# 设置同时连接的客户端的最大数量。默认情况下,这个限制被设置为 10000 个客户端,但是如果 Redis 服务器无法配置进程文件限制以允许指定的限制,
# 那么允许的最大客户端数量被设置为当前文件限制减去 32(因为 Redis 保留了一些文件描述符供内部使用)。
#
# 一旦达到限制,Redis 将关闭所有新的连接,并发送一个错误 "达到最大客户数"。
#
# 重要:当使用 Redis 集群时,最大连接数也与集群总线共享:集群中的每个节点将使用两个连接,一个传入,另一个传出。在集群非常大的情况下,相应地
# 确定限制的大小是很重要的。
#
# maxclients 10000
12、MEMORY MANAGEMENT(内存管理)
############################## 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).
#
# If Redis can't remove keys according to the policy, or if the policy is
# set to 'noeviction', Redis will start to reply with errors to commands
# that would use more memory, like SET, LPUSH, and so on, and will continue
# to reply to read-only commands like GET.
#
# This option is usually useful when using Redis as an LRU or LFU cache, or to
# set a hard memory limit for an instance (using the 'noeviction' policy).
#
# 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.
#
# 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 

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
#
# 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)
# noeviction -> Don't evict anything, just return an error on write operations.
#
# LRU means Least Recently Used
# LFU means Least Frequently Used
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
#
# Note: with any of the above policies, when there are no suitable keys for
# eviction, Redis will return an error on write operations that require
# more memory. These are usually commands that create new keys, add data or
# modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,
# SORT (due to the STORE argument), and EXEC (if the transaction includes any
# command that requires memory).
#
# 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.
#
# 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.
#
# maxmemory-samples 5

# Eviction processing is designed to function well with the default setting.
# If there is an unusually large amount of write traffic, this value may need to
# be increased.  Decreasing this value may reduce latency at the risk of
# eviction processing effectiveness
#   0 = minimum latency, 10 = default, 100 = process without regard to latency
#
# maxmemory-eviction-tenacity 10

# 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.
#
# 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.
#
# 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.
#
# 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.
#
# active-expire-effort 1
############################## 内存管理 ################################

# 设置一个内存使用限制到指定的字节数。当达到内存限制时,Redis 将尝试根据所选择的驱逐策
# 略(见 maxmemory-policy)来删除键。
#
# 如果 Redis 不能根据策略删除键,或者策略被设置为 "noeviction",Redis 将开始对会使用
# 更多内存的命令做出错误回复,如 SET、LPUSH 等,并将继续回复 GET 等只读命令。
#
# 这个选项通常在使用 Redis 作为 LRU 或 LFU 缓存时很有用,或者为一个实例设置一个硬性的内
# 存限制(使用 "noeviction "策略)。
#
# 警告:如果你在一个开着 maxmemory 的实例上安装了复制器,那么需要给复制器提供的输出缓冲区
# 的大小将从使用的内存数中减去,这样网络问题/重新同步就不会触发一个循环,即键被驱逐,反过来,
# 复制器的输出缓冲区被驱逐的键的 DEL 充满,触发更多键的删除,以此类推直到数据库被完全清空。
#
# 简而言之......如果你有副本,建议你为 maxmemory 设置一个下限,以便系统上有一些空闲的 RAM 
# 用于副本输出缓冲区(但如果策略是'noeviction'就不需要)。
#
# maxmemory 

# MAXMEMORY 政策:当达到 maxmemory 时,Redis 将如何选择要删除的内容。你可以从以下行为中选择一个:
#
# valatitle-lru     ->  使用近似的 LRU 进行驱逐,只清除有过期设置的键。
# allkeys-lru       ->  使用近似的 LRU 来驱逐任何钥匙。
# volatile-lfu      ->  使用近似的 LFU 进行驱逐,只有有过期集的钥匙。
# allkeys-lfu       ->  使用近似的 LFU 驱逐任何钥匙。
# volatile-random   ->  删除一个有过期集的随机钥匙。
# allkeys-random    ->  删除一个随机钥匙,任何钥匙。
# volatile-ttl      ->  删除具有最近过期时间(次要TTL)的钥匙。
# noeviction        ->  不要驱逐任何东西,只是在写操作时返回一个错误。
#
# LRU 指的是最近使用最少的
# LFU 指的是最不经常使用的
#
# LRU、LFU 和 volatile-ttl 都是使用近似的随机化算法实现的。
#
# 注意:在上述任何一种策略下,当没有合适的键用于驱逐时,Redis 将在需要更多内存的写操作上返回错误。
# 这些通常是创建新键、添加数据或修改现有键的命令。几个例子是: SET、INCR、HSET、LPUSH、SUNIONSTORE、
# SORT(由于 STORE 参数)和 EXEC(如果事务包括任何需要内存的命令)。
#
# 默认设置为:
#
# maxmemory-policy noeviction

# LRU、LFU 和最小 TTL 算法不是精确的算法,而是近似的算法(为了节省内存),所以你可以根据速度或准确性来调整它。
# 默认情况下,Redis 将检查五个键,并挑选最近使用最少的一个,你可以使用以下配置指令改变样本大小。
#
# 默认的 5 产生足够好的结果。10 非常接近真正的 LRU,但要花费更多的 CPU。3 比较快,但不是很准确。
#
# maxmemory-samples 5

# 驱逐处理被设计为在默认设置下运行良好。如果有异常大的写入流量,这个值可能需要增加。 降低这个值可能会减少延迟,
# 但会有驱逐处理的风险 0=最小延迟,10=默认,100=不考虑延迟的处理
#
# maxmemory-eviction-tenacity 10

# 从 Redis 5 开始,默认情况下,副本将忽略它的最大内存设置(除非它在故障切换后被提升到主站或手动)。这意味着键
# 的驱逐将由主站处理,在主站的键驱逐中向副本发送 DEL 命令。
#
# 这种行为确保主站和副本保持一致,通常是你想要的,但是如果你的副本是可写的,或者你希望副本有不同的内存设置,并且
# 你确信对副本进行的所有写入都是空闲的,那么你可以改变这个默认值(但是要确保理解你在做什么)。
#
# 请注意,由于复制体默认不驱逐,它最终使用的内存可能比通过 maxmemory 设置的更多(有一些缓冲区可能在复制体上更大,
# 或者数据结构有时可能占用更多的内存等等)。因此,确保你监控你的副本,并确保它们有足够的内存,在主服务器达到配置的 
# maxmemory 设置之前,永远不会遇到真正的内存不足的情况。
#
# replica-ignore-maxmemory yes

# Redis 以两种方式回收过期的钥匙:当发现这些钥匙过期时,在访问时回收;也可以在后台回收,即所谓的 "主动过期钥匙"。
# 密钥空间被缓慢地、交互式地扫描,寻找要回收的过期密钥,这样就有可能释放那些过期的、在短时间内不会再被访问的密钥
# 的内存。
#
# 过期周期的默认努力将尽量避免有超过百分之十的过期钥匙仍在内存中,并将尽量避免消耗超过总内存的 25%,并增加系统的
# 延迟。然而,可以将通常设置为 "1" 的过期 "effort" 增加到更大的数值,最高为 "10" 值。在其最大值下,系统将使用
# 更多的 CPU,更长的周期(在技术上可能会引入更多的延迟),并将容忍更少的已经过期的钥匙仍然存在于系统中。这是内存、
# CPU 和延迟之间的一个权衡。
#
# active-expire-effort 1
13、LAZY FREEING(懒惰释放)
############################# 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.
#
# 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.
#
# 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:
#
# 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.
# 2) Because of expire: when a key with an associated time to live (see the
#    EXPIRE command) must be deleted from memory.
# 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.
# 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.
#
# In all the above cases the default is to delete objects in a blocking way,
# like if DEL was called. However you can configure each case specifically
# in order to instead release memory in a non-blocking way like if UNLINK
# was called, using the following configuration directives.

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

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

lazyfree-lazy-user-del no

# FLUSHDB, FLUSHALL, SCRIPT FLUSH and FUNCTION FLUSH support both asynchronous and synchronous
# deletion, which can be controlled by passing the [SYNC|ASYNC] flags into the
# commands. When neither flag is passed, this directive will be used to determine
# if the data should be deleted asynchronously.

lazyfree-lazy-user-flush no
############################# 懒惰释放 ####################################

# Redis 有两个原语来删除键。一个被称为 DEL,是一个阻塞的对象的删除。这意味着服务器停止处理新的命令,
# 以便以同步的方式回收与一个对象相关的所有内存。如果删除的键与一个小对象相关联,那么执行 DEL 命令所需
# 的时间非常小,与 Redis 中大多数其他 O(1) 或 O(log_N) 命令相当。然而,如果键与一个包含数百万元素的
# 聚合值相关联,服务器可能会阻塞很长时间(甚至几秒钟)以完成该操作。
#
# 由于上述原因,Redis 还提供了非阻塞性的删除原语,如 UNLINK(非阻塞性 DEL)和 FLUSHALL 和 FLUSHDB 
# 命令的 ASYNC 选项,以便在后台回收内存。这些命令是在恒定时间内执行的。另一个线程将以最快的速度在后台逐
# 步释放对象。
#
# FLUSHALL 和 FLUSHDB 的 DEL、UNLINK 和 ASYNC 选项是用户控制的。这取决于应用程序的设计,以了解何时
# 使用一个或另一个是个好主意。然而 Redis 服务器有时不得不删除键或刷新整个数据库作为其他操作的副作用。特
# 别是 Redis 在以下情况下独立于用户调用而删除对象。
#
# 1)在驱逐时,由于 maxmemory 和 maxmemory 策略的配置,为了给新数据腾出空间,而不超过指定的内存限制。
# 2) 因为 expire:当一个有相关生存时间的键(见 EXPIRE 命令)必须从内存中删除。
# 3)因为一个命令的副作用,在一个可能已经存在的键上存储数据。例如,RENAME 命令在用另一个键替换时可能会删除
# 旧的键内容。同样,SUNIONSTORE 或带有 STORE 选项的 SORT 也可能删除现有的键。SET 命令本身会删除指定键
# 的任何旧内容,以便用指定的字符串替换它。
# 4) 在复制过程中,当一个副本与它的主副本进行完全重新同步时,整个数据库的内容被删除,以便加载刚刚转
# 移的 RDB 文件。
#
# 在上述所有情况下,默认是以阻塞的方式删除对象,就像调用 DEL一样。然而,你可以使用下面的配置指令,
# 具体配置每种情况,以便以非阻塞的方式释放内存,就像调用 UNLINK 一样。

lazyf free-lazy-eviction no
lazyf free-lazy-expire no
lazyf free-lazy-server-del no
replica-lazy-flush no

# 也可以用以下配置指令修改 DEL 命令的默认行为,使之与 UNLINK 完全一样。

lazyfree-lazy-user-del no

# FLUSHDB、FLUSHALL、SCRIPT FLUSH和FUNCTION FLUSH 同时支持异步和同步删除,这可以通过在命令中传递 [SYNC|ASYNC] 标志来控制。
# 当这两个标志都没有通过时,这个指令将被用来确定数据是否应该被异步删除。

lazyf free-lazy-user-flush no
14、THREADED I/O(线程配置)
################################ 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.
#
# 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.
#
# 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-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:
#
# 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. Also, this feature currently does not work when SSL is
# enabled.
#
# 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.
################################ 线程 I/O #################################

# Redis 大部分是单线程的,然而有一些线程操作,如:UNLINK、慢速 I/O 访问和其它一些在侧线程上执行的东西
#
# 现在也可以在不同的 I/O 线程中处理 Redis 客户端套接字的读取和写入。由于写入速度很慢,通常 Redis 用户
# 会使用流水线来加快每个核心的 Redis 性能,并生成多个实例,以便扩展。使用 I/O 线程可以很容易地提高 Redis
# 的速度,而不需要使用管道或实例的分片。
#
# 默认情况下,线程是禁用的,我们建议只在至少有 4 个或更多内核的机器上启动它,并留下至少一个备用内核。
# 使用 8 个以上的线程不大可能有什么帮助。我们还建议只有在你确实有性能问题时才使用线程 I/O ,Redis 实例
# 能够使用相当大比例的 CPU 时间,否则使用这个功能就没有意义。
#
# 因此,在具体的实例中,如果你有一个四核的 CPU,尽量使用 2 或 3 个 I/O 线程,如果你有一个 8 核的 CPU,
# 尽量使用 6 个线程。为了启用 I/O 线程,请使用以下配置命令
#
# io-threads 4
#
# 将 "io-threads" 设置为 1 会像往常一样使用主线程。当 I/O 线程被启用时,我们只使用线程进行写入,也就是
# 对 "write(2)" 系统调用进行线程优化,并将客户端的缓冲区传输到套接字。然而,也可以使用下面的配置指令来启
# 用读取和协议解析的线程,把它设置为 "yes"
#
# io-threads-do-reads no
#
# 通常情况下,线程读取并没有什么帮助。
#
# 注意1:这个配置指令不能在运行时通过 CONFIG SET 来改变,另外,这个功能目前在启用 SSL 的情况下不工作。
#
# 注意2:如果你想使用 redis-benchmark 测试 Redis 的速度,确保你也在线程模式下运行基准测试本身,使
# 用 --threads 选项来匹配 Redis 线程的数量,否则你将无法注意到改进。
15、KERNEL OOM CONTROL(内核控制)
############################ 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.
#
# 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 supports these options:
#
# no:       Don't make changes to oom-score-adj (default).
# yes:      Alias to "relative" see below.
# absolute: Values in oom-score-adj-values are written as is to the kernel.
# relative: Values are used relative to the initial value of oom_score_adj when
#           the server starts and are then clamped to a range of -1000 to 1000.
#           Because typically the initial value is 0, they will often match the
#           absolute values.
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 -2000 to
# 2000 (higher means more likely to be killed).
#
# Unprivileged processes (not root, and without CAP_SYS_RESOURCE capabilities)
# can freely increase their value, but not decrease it below its initial
# settings. This means that setting oom-score-adj to "relative" and setting the
# oom-score-adj-values to positive values will always succeed.
oom-score-adj-values 0 200 800
############################ 内核 OOM 控制 ##############################

# 在 Linux 系统中,可以提示内核 OOM 杀手在内存耗尽的时候,应该首先杀死哪些进程。
#
# 启用此功能使 Redis 主动控制其所有进程的 oom-score-adj 值,这取决于它们的角色。
# 默认的分数将视图让后台子进程在所有其它进程之前被杀死,而复制进程在主进程之前被杀死。
#
# Redis 支持这些选项:
#
# no        不对 oom-score-adj 进行修改(默认)
# yes       别名为 "相对",见下文
# absolute  oom-score-adj-values 的值会被原样写入内核
# relative  当服务器启动时,数值是相对于 oom-score-adj 的初始值使用的,然后被夹在 -1000 到 1000 的范围内,
            因为通常初始值是 0 ,所以它们通常与绝对值相匹配。
oom-score-adj no

# 当使用 oom-score-adj 时,改指令控制用于主进程、副本和后台子进程的具体数值。值的范围是 -2000 到 2000 
# (越高意味着越有可能被杀死)
#
# 没有特权的进程(非root,且没有 CAP_SYS_RESOURCE 功能)可以自由增加其数值,但不能将其降低到低于其初始设置。
# 这意味着将 oom-score-adj 设置为 "relative",并将 oom-score-adj-values 设置为正值,总会成功。
oom-score-adj-values 0 200 800
16、KERNEL transparent hugepage CONTROL(内核透明大页控制)
#################### KERNEL transparent hugepage CONTROL ######################

# Usually the kernel Transparent Huge Pages control is set to "madvise" or
# or "never" by default (/sys/kernel/mm/transparent_hugepage/enabled), in which
# case this config has no effect. On systems in which it is set to "always",
# redis will attempt to disable it specifically for the redis process in order
# to avoid latency problems specifically with fork(2) and CoW.
# If for some reason you prefer to keep it enabled, you can set this config to
# "no" and the kernel global to "always".

disable-thp yes
#################### 内核透明大页控制 ######################

# 通常情况下,内核透明巨大页控制默认设置为 "madvise "或 "never"(/sys/kernel/mm/transparent_hugepage/enabled),
# 在这种情况下,这个配置没有影响。在它被设置为 "always"的系统中,redis 将尝试专门为 redis 进程禁用它,以避免特别是 fork(2) 
# 和 CoW 的延迟问题。如果出于某种原因,你喜欢保持它的启用状态,你可以把这个配置设置为 "no",把内核全局设置为 "always"。

disable-thp yes
17、APPEND ONLY MODE(AOF 配置)
############################## 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).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check https://redis.io/topics/persistence for more information.

appendonly no

# The base name of the append only file.
#
# Redis 7 and newer use a set of append-only files to persist the dataset
# and changes applied to it. There are two basic types of files in use:
#
# - Base files, which are a snapshot representing the complete state of the
#   dataset at the time the file was created. Base files can be either in
#   the form of RDB (binary serialized) or AOF (textual commands).
# - Incremental files, which contain additional commands that were applied
#   to the dataset following the previous file.
#
# In addition, manifest files are used to track the files and the order in
# which they were created and should be applied.
#
# Append-only file names are created by Redis following a specific pattern.
# The file name's prefix is based on the 'appendfilename' configuration
# parameter, followed by additional information about the sequence and type.
#
# For example, if appendfilename is set to appendonly.aof, the following file
# names could be derived:
#
# - appendonly.aof.1.base.rdb as a base file.
# - appendonly.aof.1.incr.aof, appendonly.aof.2.incr.aof as incremental files.
# - appendonly.aof.manifest as a manifest file.

appendfilename "appendonly.aof"

# For convenience, Redis stores all persistent append-only files in a dedicated
# directory. The name of the directory is determined by the appenddirname
# configuration parameter.

appenddirname "appendonlydir"

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# 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.
#
# In order to mitigate this problem it's possible to use the following option
# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
#
# This means that while another child is saving, the durability of Redis is
# the same as "appendfsync no". In practical terms, this means that it is
# possible to lose up to 30 seconds of log in the worst scenario (with the
# default Linux settings).
#
# If you have latency problems turn this to "yes". Otherwise leave it as
# "no" that is the safest pick from the point of view of durability.

no-appendfsync-on-rewrite no

# Automatic rewrite of the append only file.
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
#
# This is how it works: Redis remembers the size of the AOF file after the
# latest rewrite (if no rewrite has happened since the restart, the size of
# the AOF at startup is used).
#
# This base size is compared to the current size. If the current size is
# bigger than the specified percentage, the rewrite is triggered. Also
# you need to specify a minimal size for the AOF file to be rewritten, this
# is useful to avoid rewriting the AOF file even if the percentage increase
# is reached but it is still pretty small.
#
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.

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

# An AOF file may be found to be truncated at the end during the Redis
# startup process, when the AOF data gets loaded back into memory.
# This may happen when the system where Redis is running
# crashes, especially when an ext4 filesystem is mounted without the
# data=ordered option (however this can't happen when Redis itself
# crashes or aborts but the operating system still works correctly).
#
# Redis can either exit with an error when this happens, or load as much
# data as possible (the default now) and start if the AOF file is found
# to be truncated at the end. The following option controls this behavior.
#
# If aof-load-truncated is set to yes, a truncated AOF file is loaded and
# the Redis server starts emitting a log to inform the user of the event.
# Otherwise if the option is set to no, the server aborts with an error
# and refuses to start. When the option is set to no, the user requires
# to fix the AOF file using the "redis-check-aof" utility before to restart
# the server.
#
# Note that if the AOF file will be found to be corrupted in the middle
# the server will still exit with an error. This option only applies when
# Redis will try to read more data from the AOF file but not enough bytes
# will be found.
aof-load-truncated yes

# Redis can create append-only base files in either RDB or AOF formats. Using
# the RDB format is always faster and more efficient, and disabling it is only
# supported for backward compatibility purposes.
aof-use-rdb-preamble yes

# Redis supports recording timestamp annotations in the AOF to support restoring
# the data from a specific point-in-time. However, using this capability changes
# the AOF format in a way that may not be compatible with existing AOF parsers.
aof-timestamp-enabled no
############################## AOF 配置 ###############################

# 默认情况下,Redis 异步地将数据集转储到磁盘上。这种模式在许多应用中已经很好了,
# 但如果 Redis 进程出现问题或停电,可能会导致几分钟的写入量损失(取决于配置的保存点)。
#
# AOF 模式是一种替代的持久化模式,提供了更好的持久性。例如:使用默认的数据 sync 策略
# (见后面的配置文件),Redis 可以在服务器断电这样的戏剧性事件中只损失一秒钟的写入量,
# 或者在 Redis 进程本身发生问题,当操作系统仍然正常运行的情况下,只损失一次写入量。
#
# AOF 和 RDB 持久化可以同时启用,没有问题。如果 AOF 在启动时被启用,Redis 将加载 AOF,
# 那是具有更好的持久性保证的文件。
#
# 请查看 https://redis.io/topics/persistence 了解更多信息。

appendonly no

# AOF 文件名称
#
# Redis 7 和更新的版本使用一组仅有附录的文件来持久化数据集和应用于它的变化。有两种基本类型的文件
# 在使用:
#
# - Base files,它是一个快照,代表了文件创建时数据集的完整状态。基本文件可以是 RDB(二进制序列化)
# 或者 AOF(文本命令)的形式。
# - Incremental files,其中包含在前一个文件之后应用于数据集的额外命令。
#
# 此外,清单文件被用来跟踪文件和它们被创建的顺序,并被应用。
#
# AOF 文件名是由 Redis 按照特定模式创建的。文件名的前缀是基于 "appendfilename" 配置参数,后面是关于
# 序列和类型的附加信息。
#
# 例如:如果 "appendfilename" 被设置为 appendonly.aof ,一下文件名称可以被导出:
#
# - appendonly.aof.1.base.rdb   作为基础文件。
# - appendonly.aof.1.incr.aof, appendonly.aof.2.incr.aof 作为增值文件。
# - appendonly.aof.manifest 作为一个清单文件。

appendfilename "appendonly.aof"

# 为方便起见,Redis 将所有持久化的 AOF 文件存储在一个专用目录中。该目录的名称由 "appenddirname" 配置决定。

appenddirname "appendonlydir"

# fsync() 调用告诉操作系统实际写数据到磁盘上,而不是等待输出缓冲区中的更多数据。有些操作系统会真的
# 吧数据冲到磁盘上,有些操作系统只是先尽快完成。
#
# Redis 支持三种不同的模式:
#
# no        不要 fsync。只是让操作系统在它想的时候刷新数据。更快。
# always    在每次写入 append only log 之后进行 fsync ,慢但是更加安全。
# everysec  每秒只进行一次 fsync,妥当。
#
# 默认是 "everysec",因为这通常是速度和数据安全之间的正确折中。这取决于你是否能把它放宽到 "no",
# 让操作系统在它想要的时候刷新输出缓冲区,以获得更好的性能(但如果你能接受一些数据丢失的想法,可以
# 考虑默认的持久化模式,即快照),或者相反,使用 "always" ,这样非常慢,但比 "everysec" 更安全一些。
#
# 更多细节请查看以下文档:
# http://antirez.com/post/redis-persistence-demystified.html
#
# 如果不确定,请使用 "everysec"。

# appendfsync always
appendfsync everysec
# appendfsync no

# 当 AOF fsync 策略被设置为 "always" 或者 "veverysec",并且后台保存进程(后台保存或者 AOF 日志后台重写)
# 正在对磁盘执行大量的 I/O ,在一些 Linux 配置中,Redis 可能会在 fsync() 调用中阻塞太长时间。请注意,目前
# 还没有解决这个文件,因为即使在不同的线程中执行 fsync 也会阻塞我们的同步 write(2) 调用。
#
# 为了缓解这个问题,可以使用下面的选项,当 BGSAVE 或者 BGREWRITEAOF 正在进行时,防止主进程中调用 fsync()。
#
# 这意味着,当另一个子进程在保存时,Redis 的耐久性与 "appendfsync no" 相同。在实际操作中,这意味着在最坏的
# 情况下,有可能损失多达 30 秒的日志(默认的 Linux 设置)
#
# 如果你有延迟问题,就把它变成 "yes"。否则就把它设置为 "no",从耐久性的角度来看,这是最安全的选择。

no-appendfsync-on-rewrite no

# 自动重写 AOF 文件
# 当 AOF 日志大小增长到指定的百分比时,Redis 能够自动重写日志文件,隐试调用 BGREWRITEAOF。
#
# 它是这样工作的,Redis 会记住最近一次重写 AOF 文件的大小(如果重启后没有发生重写,则使用启动时 AOF 的大小)。
#
# 这个基本大小与当前大小进行比较。如果当前大小大于指定的百分比,就会触发重写。另外,你还需要指定一个 AOF 文件被重写
# 的最小尺寸,这对避免重写 AOF 文件很有用,即使达到了增加的百分比,但还是相当小。
#
# 指定一个百分比为零,以便禁用自动 AOF 重写功能。

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

# 在 Redis 启动过程中,当 AOF 数据被加载回内存时,可能会发现 AOF 文件在末端被截断了。这可能发生在 Redis 运行的系统
# 崩溃时,特别是当 ext4 文件系统被挂载而没有 data=ordered 选项时(然而这不会发生在 Redis 本身崩溃或中止但操作系统
# 仍然正常工作时)。
#
# 当这种情况发生时,Redis 可以以错误退出,或者尽可能多地加载数据(现在的默认情况),如果发现 AOF 文件在末端被截断,
# 则启动。下面的选项可以控制这种行为。
#
# 如果 aof-load-truncated 被设置为 yes,一个被截断的 AOF 文件被加载,Redis 服务器开始发出一个日志来通知用户这个
# 事件。否则,如果该选项被设置为 "no",服务器会以错误的方式中止,并拒绝启动。当该选项被设置为 "no "时,用户需要在重启
# 服务器之前使用 "redis-check-aof "工具修复 AOF 文件。
#
# 请注意,如果 AOF 文件在中间被发现损坏,服务器仍然会以错误退出。这个选项只适用于 Redis 试图从 AOF 文件中读取更多的数据,
# 但没有找到足够的字节。
aof-load-truncated yes

# Redis 可以以 RDB 或 AOF 格式创建仅有附录的基础文件。使用 RDB 格式总是更快、更有效,禁用它只是为了向后兼容的目的。
aof-use-rdb-preamble yes

# Redis 支持在 AOF 中记录时间戳注释,以支持从一个特定的时间点恢复数据。然而,使用这种能力改变了 AOF 的格式,可能与现有
# 的 AOF 解析器不兼容。
aof-timestamp-enabled no
18、SHUTDOWN(停止配置)
################################ SHUTDOWN #####################################

# Maximum time to wait for replicas when shutting down, in seconds.
#
# During shut down, a grace period allows any lagging replicas to catch up with
# the latest replication offset before the master exists. This period can
# prevent data loss, especially for deployments without configured disk backups.
#
# The 'shutdown-timeout' value is the grace period's duration in seconds. It is
# only applicable when the instance has replicas. To disable the feature, set
# the value to 0.
#
# shutdown-timeout 10

# When Redis receives a SIGINT or SIGTERM, shutdown is initiated and by default
# an RDB snapshot is written to disk in a blocking operation if save points are configured.
# The options used on signaled shutdown can include the following values:
# default:  Saves RDB snapshot only if save points are configured.
#           Waits for lagging replicas to catch up.
# save:     Forces a DB saving operation even if no save points are configured.
# nosave:   Prevents DB saving operation even if one or more save points are configured.
# now:      Skips waiting for lagging replicas.
# force:    Ignores any errors that would normally prevent the server from exiting.
#
# Any combination of values is allowed as long as "save" and "nosave" are not set simultaneously.
# Example: "nosave force now"
#
# shutdown-on-sigint default
# shutdown-on-sigterm default
################################ 停机配置 #####################################

# 关闭时等待复制的最长时间,单位是秒。
#
# 在关闭期间,一个宽限期允许任何落后的复制体在主站存在之前赶上最新的复制偏移。这个时期可以防止
# 数据丢失,特别是对于没有配置磁盘备份的部署。
#
# "shutdown-timeout" 的值是宽限期的持续时间,单位是秒。它只适用于实例有复制的情况,要禁用该
# 功能,将该值设置为 0
#
# shutdown-timeout 10

# 当 Redis 收到 SIGINT 或 SIGTERM 时,就会启动关机,如果配置了保存点,默认情况下,RDB 快照
# 会以阻塞操作的方式写入磁盘。
# 关机信号可以使用的选项包含如下:
# default       : 仅在配置了保存点的情况下保存 RDB 快照。等待落后的复制体追赶上来。
# save          : 即使没有配置保存点,也会强制进行 DB 保存操作。
# nosave        : 即使配置了一个或多个保存点,也会阻止 DB 保存操作。
# now           : 跳过等待落后的副本。
# force         : 忽略任何通常会阻止服务器退出的错误。
#
# 只要不同时设置 "save "和 "nosave",就可以允许任何数值的组合。
# 示例:"nosave force now"
#
# shutdown-on-sigint default
# shutdown-on-sigterm default
19、NON-DETERMINISTIC LONG BLOCKING COMMANDS(非决定性的长阻断命令)
################ NON-DETERMINISTIC LONG BLOCKING COMMANDS #####################

# Maximum time in milliseconds for EVAL scripts, functions and in some cases
# modules' commands before Redis can start processing or rejecting other clients.
#
# If the maximum execution time is reached Redis will start to reply to most
# commands with a BUSY error.
#
# In this state Redis will only allow a handful of commands to be executed.
# For instance, SCRIPT KILL, FUNCTION KILL, SHUTDOWN NOSAVE and possibly some
# module specific 'allow-busy' commands.
#
# SCRIPT KILL and FUNCTION KILL will only be able to stop a script that did not
# yet call any write commands, so SHUTDOWN NOSAVE may be the only way to stop
# the server in the case a write command was already issued by the script when
# the user doesn't want to wait for the natural termination of the script.
#
# The default is 5 seconds. It is possible to set it to 0 or a negative value
# to disable this mechanism (uninterrupted execution). Note that in the past
# this config had a different name, which is now an alias, so both of these do
# the same:
# lua-time-limit 5000
# busy-reply-threshold 5000
################ 非决定性的长阻断命令 #####################

# 在 Redis 开始处理或拒绝其他客户之前,EVAL 脚本、函数和某些情况下模块的命令的最大时间,以毫秒为单位。
#
# 如果达到最大执行时间,Redis 将开始以 BUSY 错误回复大多数命令。
#
# 在这种状态下,Redis 只允许执行少数几个命令。
# 例如,SCRIPT KILL、FUNCTION KILL、SHUTDOWN NOSAVE 以及可能的一些特定模块的 "允许忙 "命令。
#
# SCRIPT KILL 和 FUNCTION KILL 只能停止一个尚未调用任何写命令的脚本,所以 SHUTDOWN NOSAVE 可能
# 是在脚本已经发出写命令的情况下停止服务器的唯一方法。
# 在脚本已经发出了写命令的情况下,当用户不想等待脚本的自然终止时,SHUTDOWN NOSAVE 可能是停止服务器的唯一方法。
#
# 默认是 5 秒。可以把它设置为 0 或一个负值来禁用这个机制(不间断地执行)。注意,在过去这个配置有一个不同的名字,
# 现在是一个别名,所以这两个的作用是一样的:
# lua-time-limit 5000
# busy-reply-threshold 5000
20、REDIS CLUSTER(集群配置)
################################ REDIS CLUSTER  ###############################

# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
#
# 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.
#
# 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

# The cluster port is the port that the cluster bus will listen for inbound connections on. When set 
# to the default value, 0, it will be bound to the command port + 10000. Setting this value requires 
# you to specify the cluster bus port when executing cluster meet.
# cluster-port 0

# 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.
#
# 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
#
# 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.
#
# 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).
#
# 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 or
# set cluster-allow-replica-migration to 'no'.
# A value of 0 can be set but is useful only for debugging and dangerous
# in production.
#
# cluster-migration-barrier 1

# Turning off this option allows to use less automatic cluster configuration.
# It both disables migration to orphaned masters and migration from masters
# that became empty.
#
# Default is 'yes' (allow automatic migrations).
#
# cluster-allow-replica-migration yes

# 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.
#
# However sometimes you want the subset of the cluster which is working,
# to continue to accept queries for the part of the key space that is still
# covered. In order to do so, just set the cluster-require-full-coverage
# option to no.
#
# cluster-require-full-coverage yes

# This option, when set to yes, prevents replicas from trying to failover its
# master during master failures. However the replica 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.
#
# cluster-replica-no-failover no

# This option, when set to yes, allows nodes to serve read traffic while the
# cluster is in a down state, as long as it believes it owns the slots.
#
# 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.
#
# cluster-allow-reads-when-down no

# This option, when set to yes, allows nodes to serve pubsub shard traffic while
# the cluster is in a down state, as long as it believes it owns the slots.
#
# This is useful if the application would like to use the pubsub feature even when
# the cluster global stable state is not OK. If the application wants to make sure only
# one shard is serving a given channel, this feature should be kept as yes.
#
# cluster-allow-pubsubshard-when-down yes

# Cluster link send buffer limit is the limit on the memory usage of an individual
# cluster bus link's send buffer in bytes. Cluster links would be freed if they exceed
# this limit. This is to primarily prevent send buffers from growing unbounded on links
# toward slow peers (E.g. PubSub messages being piled up).
# This limit is disabled by default. Enable this limit when 'mem_cluster_links' INFO field
# and/or 'send-buffer-allocated' entries in the 'CLUSTER LINKS` command output continuously increase.
# Minimum limit of 1gb is recommended so that cluster link buffer can fit in at least a single
# PubSub message by default. (client-query-buffer-limit default value is 1gb)
#
# cluster-link-sendbuf-limit 0
 
# Clusters can configure their announced hostname using this config. This is a common use case for 
# applications that need to use TLS Server Name Indication (SNI) or dealing with DNS based
# routing. By default this value is only shown as additional metadata in the CLUSTER SLOTS
# command, but can be changed using 'cluster-preferred-endpoint-type' config. This value is 
# communicated along the clusterbus to all nodes, setting it to an empty string will remove 
# the hostname and also propagate the removal.
#
# cluster-announce-hostname ""

# Clusters can advertise how clients should connect to them using either their IP address,
# a user defined hostname, or by declaring they have no endpoint. Which endpoint is
# shown as the preferred endpoint is set by using the cluster-preferred-endpoint-type
# config with values 'ip', 'hostname', or 'unknown-endpoint'. This value controls how
# the endpoint returned for MOVED/ASKING requests as well as the first field of CLUSTER SLOTS. 
# If the preferred endpoint type is set to hostname, but no announced hostname is set, a '?' 
# will be returned instead.
#
# When a cluster advertises itself as having an unknown endpoint, it's indicating that
# the server doesn't know how clients can reach the cluster. This can happen in certain 
# networking situations where there are multiple possible routes to the node, and the 
# server doesn't know which one the client took. In this case, the server is expecting
# the client to reach out on the same endpoint it used for making the last request, but use
# the port provided in the response.
#
# cluster-preferred-endpoint-type ip

# In order to setup your cluster make sure to read the documentation
# available at https://redis.io web site.
################################ Redis 集群配置  ###############################

# 普通的 Redis 实例不能成为 Redis 集群的一部分;只有作为集群节点启动的节点可以。为了将 Redis 实例作为集群节点启动,
# 启用集群支持,请取消以下注释。
#
# cluster-enabled yes

# 每个集群节点都有一个集群配置文件。这个文件不打算用手编辑。它是由 Redis 节点创建和更新的。每个 Redis 集群节点都需要
# 一个不同的集群配置文件。确保在同一系统中运行的实例没有重叠的集群配置文件名称。
#
# cluster-config-file nodes-6379.conf

# 集群节点超时是指一个节点必须在无法到达的情况下被认为处于失败状态的毫秒数量。大多数其他内部时间限制是节点超时的倍数。
#
# cluster-node-timeout 15000

# 集群端口是集群总线监听入站连接的端口。当设置为默认值 0 时,它将被绑定到命令端口 +10000。设置这个值需要你在执行集群满足
# 时指定集群总线的端口。
# cluster-port 0

# 如果一个失败的主站的副本的数据看起来太老了。
#
# 对于一个副本来说,没有简单的方法可以真正准确衡量其 "数据年龄",所以要进行以下两个检查:
#
# 1)如果有多个副本能够进行故障转移,它们会交换信息,以尝试让具有最佳复制偏移量的副本获得优势(从主站处理的数据更多)。
# 复制体将尝试通过偏移量获得它们的排名,并在故障转移开始时应用与它们的排名成比例的延迟。
#
# 2) 每个副本都要计算与其主站最后一次互动的时间。这可以是最后一次收到的ping或命令(如果主站仍然处于 "连接 "状态),或
# 者是与主站断开连接后的时间(如果复制链路目前是断开的)。如果最后的交互时间太长,复制体将根本不会尝试故障转移。
#
# 第二点可以由用户进行调整。具体来说,如果从最后一次与主站的互动开始,时间超过了,那么副本就不会执行故障转移。
#
# (node-timeout * cluster-replica-validity-factor) + repl-ping-replica-period
#
# 因此,举例来说,如果节点超时是 30 秒,集群-复制-有效性因素是 10,并假设默认的复制-平移-复制-周期为 10 秒,那么如果复制无法
# 与主站对话的时间超过 310 秒,就不会尝试故障转移。
#
# 一个大的 cluster-replica-validity-factor 可能允许数据太旧的复制体故障转移主站,而一个太小的值可能使集群
# 根本无法选出一个复制体。
#
# 为了获得最大的可用性,可以将集群-复制体-有效性因素设置为 0,这意味着复制体将始终尝试故障转移主站,无论它们最后一次与主站交互
# 是什么时候。(然而,它们总是试图应用一个与它们的偏移等级成比例的延迟)。
#
# 零是唯一能够保证当所有分区愈合时,集群将始终能够继续。
#
# cluster-replica-validity-factor 10

# 集群复制能够迁移到孤儿主站,也就是没有工作副本的主站。这提高了集群抵抗故障的能力,否则,如果一个无主的主站没有工作副本,
# 就不能在故障情况下被转移。
#
# 复制品只有在其旧主站至少还有一定数量的其他工作副本的情况下才会迁移到无主站。这个数字就是 "迁移障碍"。迁移障碍为 1,意味着只有
# 当主站至少有 1 个其他工作副本时,副本才会迁移,以此类推。它通常反映了你希望集群中每个主站的复制数量。
#
# 默认值是 1(只有当主站保持至少一个副本时,副本才会迁移)。要禁用迁移,只需将其设置为一个非常大的值,或者
# 将 cluster-allow-replica-migration 设置为 'no'。可以设置为 0,但只对调试有用,在生产中是很危险的。
#
# cluster-migration-barrier 1

# 关掉这个选项可以减少自动集群配置的使用。它既禁止向无主的主站迁移,也禁止从变成空的主站迁移。
#
# 默认值是 "yes"(允许自动迁移)
#
# cluster-allow-replica-migration yes

# 默认情况下,如果 Redis 集群节点检测到至少有一个哈希槽未被覆盖(没有可用的节点为其服务),则停止接受查询。这样一来,
# 如果集群部分瘫痪(例如,一系列的哈希槽不再被覆盖),所有的集群最终都变得不可用。一旦所有的槽被覆盖,它就会自动恢复可用。
#
# 然而,有时你想让正在工作的集群的子集继续接受对仍被覆盖的那部分密钥空间的查询。为了做到这一点,只需将
# cluster-require-full-coverage 选项设置为 no。
#
# cluster-require-full-coverage yes

# 这个选项,当设置为 "yes" 时,可以防止复制体在主站故障时尝试故障转移其主站。然而,如果被迫这样做,复制体仍然可以执行手动
# 故障转移。
#
# 这在不同的情况下是很有用的,特别是在多个数据中心运行的情况下,如果不是在 DC 完全故障的情况下,我们希望一方永远不会被提升。
#
# cluster-replica-no-failover no

# 这个选项设置为 "yes" 时,允许节点在集群处于停机状态时为读取流量提供服务,只要它认为自己拥有这些槽位。
#
# 这在两种情况下是有用的。 第一种情况是,当一个应用程序在节点故障或网络分区时不需要数据的一致性。这方面的一个例子是缓存,
# 只要节点拥有数据,它就应该能够提供服务。
#
# 第二个用例是不符合推荐的三个分片的配置,但想启用集群模式,以后再进行扩展。在 1 或 2 个分片的配置中,如果没有设置这个选项,
# 主站的中断会导致整个集群的读/写中断,如果设置了这个选项,就只有写中断。如果没有主站的法定人数,插槽所有权不会自动改变。
#
# cluster-allow-reads-when-down no

# 这个选项设置为 "yes" 时,允许节点在集群处于停机状态时为 pubsub 分片流量提供服务,只要它认为自己拥有这些槽位。
#
# 如果应用程序希望在集群全局稳定状态不确定时也能使用 pubsub 功能,这就很有用。如果应用程序想确保只有一个分片在为一个给
# 定的通道服务,这个功能应该保持为 yes。
#
# cluster-allow-pubsubshard-when-down yes

# 集群链接发送缓冲区限制是指单个集群总线链接的发送缓冲区的内存使用限制,单位是直接。如果集群链接超过这个限制,它们将被释放。
# 这主要是为了防止朝向慢速对等体的链接上的发送缓冲区无限制地增长(例如 PubSub 消息被堆积起来)。这个限制在默认情况下是禁用的。
# 当 'mem_cluster_links' INFO 字段和/或 'CLUSTER LINKS' 命令输出中的 'send-buffer-allocated' 条目持续增加时,启用这个
# 限制。建议最小限制为 1GB,这样集群链接缓冲区在默认情况下至少可以容纳一个 PubSub 消息。(client-query-buffer-limit 默认值是 1gb)
#
# cluster-link-sendbuf-limit 0

# 集群可以使用这个配置来配置他们宣布的主机名。这是需要使用 TLS 服务器名称指示(SNI)或处理基于 DNS 路由的应用程序的常见用例。
# 默认情况下,这个值只在 CLUSTER SLOTS 命令中显示为额外的元数据,但可以使用 'cluster-preferred endpoint-type'
# 配置来改变。这个值会沿着集群总线传达给所有节点,将其设置为空字符串会删除主机名,同时也会传播删除。
#
# cluster-announce-hostname ""

# 集群可以宣传客户应该如何使用他们的 IP 地址、用户定义的主机名或通过声明他们没有端点来连接他们。哪一个端点被显示为首选端点是通过
# 使用 cluster-preferred-endpoint-type 配置来设置的,其值为 "ip"、"hostname "或 "unknown-endpoint"。这个值控制了
# MOVED/ASKING 请求以及 CLUSTER SLOTS 的第一个字段所返回的端点的方式。 如果首选端点类型被设置为 hostname,但没有设置公布
# 的 hostname,将返回一个'?'
#
# 当一个集群宣传自己有一个未知的端点时,它表明服务器不知道客户如何能到达该集群。这可能发生在某些网络情况下,即有多条可能的路线通往该节点,
# 而服务器不知道客户采取哪条路线。在这种情况下,服务器希望客户在它用于发出最后一次请求的同一端点上进行联系,但使用响应中提供的端口。
#
# cluster-preferred-endpoint-type ip

# 为了设置你的集群,请确保阅读文件
# 可在https://redis.io 网站上找到。
21、CLUSTER DOCKER/NAT support(集群容器/NAT支持)
########################## CLUSTER DOCKER/NAT support  ########################

# In certain deployments, Redis Cluster nodes address discovery fails, because
# addresses are NAT-ted or because ports are forwarded (the typical case is
# Docker and other containers).
#
# In order to make Redis Cluster working in such environments, a static
# configuration where each node knows its public address is needed. The
# following four options are used for this scope, and are:
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-tls-port
# * cluster-announce-bus-port
#
# Each instructs the node about its address, client ports (for connections
# without and with TLS) 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 cluster-tls is set to yes and cluster-announce-tls-port is omitted or set
# to zero, then cluster-announce-port refers to the TLS port. Note also that
# cluster-announce-tls-port has no effect if cluster-tls is set to no.
#
# If the above options are not used, the normal Redis Cluster auto-detection
# will be used instead.
#
# 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.
#
# Example:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-tls-port 6379
# cluster-announce-port 0
# cluster-announce-bus-port 6380
########################## 集群容器/NAT支持  ########################

# 在某些部署中,Redis 集群节点的地址发现失败,因为地址被 NAT-ted 或端口被转发(典型情况是 Docker 和其他容器)。
#
# 为了让 Redis Cluster 在这种环境下工作,需要一个静态配置,让每个节点知道它的公共地址。以下四个选项用于这个范围,
# 它们是:
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-tls-port
# * cluster-announce-bus-port
#
# 每个节点都会指示它的地址、客户端端口(用于没有 TLS 的连接和有 TLS 的连接)和集群消息总线端口。这些信息会被公布在总线数据包的头部,
# 这样其他节点就能正确地映射出公布信息的节点的地址。
#
# 如果 cluster-tls 设置为 yes,而 cluster-announce-tls-port 被省略或设置为 0,那么 cluster-announce-port 就是指 TLS 端口。
# 还要注意的是,如果 cluster-tls 被设置为 no,cluster-announce-tls-port 就没有作用。
#
# 如果不使用上述选项,将使用正常的 Redis 集群自动检测。
#
# 请注意,当重新映射时,总线端口可能不在 client port + 10000 的固定偏移处,所以你可以指定任何端口和总线端口,这取决于它们如何被重新映射。
# 如果没有设置总线端口,将照常使用 10000 的固定偏移。
#
# 示例:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-tls-port 6379
# cluster-announce-port 0
# cluster-announce-bus-port 6380
22、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).
#
# You can configure the slow log with two parameters: one tells Redis
# what is the execution time, in microseconds, to exceed in order for the
# command to get logged, and the other parameter is the length of the
# slow log. When a new command is logged the oldest one is removed from the
# queue of logged commands.

# The following time is expressed in microseconds, so 1000000 is equivalent
# to one second. Note that a negative number disables the slow log, while
# a value of zero forces the logging of every command.
slowlog-log-slower-than 10000

# There is no limit to this length. Just be aware that it will consume memory.
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128
################################## 慢日志配置 ###################################

# Redis 慢速日志是一个记录超过指定执行时间的查询的系统。执行时间不包括 I/O 操作,如与客户交谈、发送回复等,
# 而只是实际执行命令所需的时间(这是命令执行的唯一阶段,线程被阻塞,在此期间不能为其他请求服务)。
#
# 你可以用两个参数来配置慢速日志:一个是告诉 Redis 超过多少执行时间(以微秒为单位),命令才会被记录下来,
# 另一个参数是慢速日志的长度。当一个新的命令被记录下来时,最旧的命令会从记录的命令队列中被删除。

# 下面的时间用微秒表示,所以 1000000 相当于一秒钟。请注意,负数会禁用慢速日志,而零值会强制记录每一条命令。
slowlog-log-slower-than 10000

# 这个长度没有限制。只是要注意它将消耗内存。你可以用 SLOWLOG RESET 来回收慢速日志所使用的内存。
slowlog-max-len 128
23、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.
#
# Via the LATENCY command this information is available to the user that can
# print graphs and obtain reports.
#
# The system only logs operations that were performed in a time equal or
# greater than the amount of milliseconds specified via the
# latency-monitor-threshold configuration directive. When its value is set
# to zero, the latency monitor is turned off.
#
# By default latency monitoring is disabled since it is mostly not needed
# if you don't have latency issues, and collecting data has a performance
# impact, that while very small, can be measured under big load. Latency
# monitoring can easily be enabled at runtime using the command
# "CONFIG SET latency-monitor-threshold " if needed.
latency-monitor-threshold 0
################################ 延迟监控 ##############################

# Redis 延迟监控子系统在运行时对不同的操作进行采样,以收集与 Redis 实例可能的延迟来源有关的数据。
#
# 通过 LATENCY 命令,这些信息可以提供给用户,用户可以打印图表和获得报告。
#
# 系统只记录那些在等于或大于通过 latency-monitor-threshold 配置指令指定的毫秒量的时间内执行的操作。
# 当它的值被设置为零时,延迟监控就会被关闭。
#
# 默认情况下,延迟监控是被禁用的,因为如果你没有延迟问题,大部分情况下是不需要的,而且收集数据对性能有影响,虽然非常小,
# 但可以在大负荷下测量。如果需要的话,可以使用 "CONFIG SET latency-monitor-threshold "
# 命令在运行时轻松启用延迟监控。
latency-monitor-threshold 0
24、LATENCY TRACKING(延迟追踪)
################################ LATENCY TRACKING ##############################

# The Redis extended latency monitoring tracks the per command latencies and enables
# exporting the percentile distribution via the INFO latencystats command,
# and cumulative latency distributions (histograms) via the LATENCY command.
#
# By default, the extended latency monitoring is enabled since the overhead
# of keeping track of the command latency is very small.
# latency-tracking yes

# By default the exported latency percentiles via the INFO latencystats command
# are the p50, p99, and p999.
# latency-tracking-info-percentiles 50 99 99.9
################################ 延迟追踪 ##############################

# Redis 扩展的延迟监控跟踪每个命令的延迟,并能通过 INFO latencystats 命令导出百分位数分布,以及通过 LATENCY 
# 命令导出累积延迟分布(直方图)。
#
# 默认情况下,扩展的延迟监控是启用的,因为跟踪命令延迟的开销非常小。
# latency-tracking yes
# 默认情况下,通过 INFO latencystats 命令导出的延时百分位数是 p50、p99 和 p999。
# latency-tracking-info-percentiles 50 99 99.9
25、EVENT NOTIFICATION(事件通知)
############################# EVENT NOTIFICATION ##############################

# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at https://redis.io/topics/notifications
#
# For instance if keyspace events notification is enabled, and a client
# performs a DEL operation on key "foo" stored in the Database 0, two
# messages will be published via Pub/Sub:
#
# PUBLISH __keyspace@0__:foo del
# PUBLISH __keyevent@0__:del foo
#
# It is possible to select the events that Redis will notify among a set
# of classes. Every class is identified by a single character:
#
#  K     Keyspace events, published with __keyspace@__ prefix.
#  E     Keyevent events, published with __keyevent@__ prefix.
#  g     Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
#  $     String commands
#  l     List commands
#  s     Set commands
#  h     Hash commands
#  z     Sorted set commands
#  x     Expired events (events generated every time a key expires)
#  e     Evicted events (events generated when a key is evicted for maxmemory)
#  n     New key events (Note: not included in the 'A' class)
#  t     Stream commands
#  d     Module key type events
#  m     Key-miss events (Note: It is not included in the 'A' class)
#  A     Alias for g$lshzxetd, so that the "AKE" string means all the events
#        (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:
#
#  notify-keyspace-events Elg
#
#  Example 2: to get the stream of the expired keys subscribing to channel
#             name __keyevent@0__:expired use:
#
#  notify-keyspace-events Ex
#
#  By default all notifications are disabled because most users don't need
#  this feature and the feature has some overhead. Note that if you don't
#  specify at least one of K or E, no events will be delivered.
notify-keyspace-events ""
############################# 事件通知 ##############################

# Redis 可以通知 Pub/Sub 客户端在钥匙空间中发生的事件。这个功能的文档在 https://redis.io/topics/notifications
#
# 例如,如果钥匙空间事件通知被启用,并且客户端对存储在数据库 0 中的钥匙 "foo" 执行了 DEL 操作,两个消息将通过Pub/Sub发布:
#
# PUBLISH __keyspace@0__:foo del
# PUBLISH __keyevent@0__:del foo
#
# 可以在一组类中选择 Redis 将通知的事件。每个类都由一个字符来标识。
#
# K 关键空间事件,用__keyspace@__前缀发布。
# E 关键事件,用__keyevent@__前缀发布。
# g 通用命令(非特定类型),如DEL, EXPIRE, RENAME, ...
# $ 字符串命令
# l 列表命令
# s 设置命令
# h 哈希命令
# z 排序的集合命令
# x 过期事件(每次密钥过期时产生的事件)。
# e 驱逐事件(当一把钥匙被驱逐到最大内存时产生的事件)。
# n 新钥匙事件(注意:不包括在'A'类中)。
# t 流命令
# d 模块键类型事件
# m 钥匙丢失事件(注意:不包括在'A'类中)
# A g$lshzxetd的别名,因此 "AKE "字符串表示所有的事件(除了钥匙丢失事件,由于其独特的性质,不包括在 "A "中)。
#
# "notify-keyspace-events" 的参数是一个由零或多个字符组成的字符串。空字符串意味着通知被禁用。
#
# 示例:要启用列表和通用事件,从事件名称的角度,使用:
#
#  notify-keyspace-events Elg
#
# 例子2:获取订阅通道的过期密钥流
# name __keyevent@0__:expired use:
#
# notify-keyspace-events Ex
#
# 默认情况下,所有的通知都是禁用的,因为大多数用户不需要这个功能,而且这个功能有一些开销。注意,如果你没有指定 K 或 E 中
# 的至少一个,就不会有事件被传递。
notify-keyspace-events ""
26、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-listpack-entries 512
hash-max-listpack-value 64

# Lists are also encoded in a special way to save a lot of space.
# The number of entries allowed per internal list node can be specified
# as a fixed maximum size or a maximum number of elements.
# For a fixed maximum size, use -5 through -1, meaning:
# -5: max size: 64 Kb  <-- not recommended for normal workloads
# -4: max size: 32 Kb  <-- not recommended
# -3: max size: 16 Kb  <-- probably not recommended
# -2: max size: 8 Kb   <-- good
# -1: max size: 4 Kb   <-- good
# Positive numbers mean store up to _exactly_ that number of elements
# per list node.
# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
# but if your use case is unique, adjust the settings as necessary.
list-max-listpack-size -2

# Lists may also be compressed.
# Compress depth is the number of quicklist ziplist nodes from *each* side of
# the list to *exclude* from compression.  The head and tail of the list
# are always uncompressed for fast push/pop operations.  Settings are:
# 0: disable all list compression
# 1: depth 1 means "don't start compressing until after 1 node into the list,
#    going from either the head or tail"
#    So: [head]->node->node->...->node->[tail]
#    [head], [tail] will always be uncompressed; inner nodes will compress.
# 2: [head]->[next]->node->node->...->node->[prev]->[tail]
#    2 here means: don't compress head or head->next or tail->prev or tail,
#    but compress all nodes between them.
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
# etc.
list-compress-depth 0

# Sets have a special encoding in just one case: when a set is composed
# of just strings that happen to be integers in radix 10 in the range
# of 64 bit signed integers.
# The following configuration setting sets the limit in the size of the
# set in order to use this special memory saving encoding.
set-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-listpack-entries 128
zset-max-listpack-value 64

# HyperLogLog sparse representation bytes limit. The limit includes the
# 16 bytes header. When an HyperLogLog using the sparse representation crosses
# this limit, it is converted into the dense representation.
#
# A value greater than 16000 is totally useless, since at that point the
# dense representation is more memory efficient.
#
# The suggested value is ~ 3000 in order to have the benefits of
# the space efficient encoding without slowing down too much PFADD,
# which is O(N) with the sparse encoding. The value can be raised to
# ~ 10000 when CPU is not a concern, but space is, and the data set is
# composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
hll-sparse-max-bytes 3000

# 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 entries limit by setting max-bytes to 0 and max-entries to the desired
# value.
stream-node-max-bytes 4096
stream-node-max-entries 100

# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
# order to help rehashing the main Redis hash table (the one mapping top-level
# keys to values). The hash table implementation Redis uses (see dict.c)
# performs a lazy rehashing: the more operation you run into a hash table
# that is rehashing, the more rehashing "steps" are performed, so if the
# server is idle the rehashing is never complete and some more memory is used
# by the hash table.
#
# The default is to use this millisecond 10 times every second in order to
# actively rehash the main dictionaries, freeing memory when possible.
#
# If unsure:
# use "activerehashing no" if you have hard latency requirements and it is
# not a good thing in your environment that Redis can reply from time to time
# to queries with 2 milliseconds delay.
#
# use "activerehashing yes" if you don't have such hard requirements but
# want to free memory asap when possible.
activerehashing yes

# 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
#
# The syntax of every client-output-buffer-limit directive is the following:
#
# client-output-buffer-limit    
#
# A client is immediately disconnected once the hard limit is reached, or if
# the soft limit is reached and remains reached for the specified number of
# seconds (continuously).
# So for instance if the hard limit is 32 megabytes and the soft limit is
# 16 megabytes / 10 seconds, the client will get disconnected immediately
# if the size of the output buffers reach 32 megabytes, but will also get
# disconnected if the client reaches 16 megabytes and continuously overcomes
# the limit for 10 seconds.
#
# By default normal clients are not limited because they don't receive data
# without asking (in a push way), but just after a request, so only
# asynchronous clients may create a scenario where data is requested faster
# than it can read.
#
# Instead there is a default limit for pubsub and replica clients, since
# subscribers and replicas receive data in a push fashion.
#
# Note that it doesn't make sense to set the replica clients output buffer
# limit lower than the repl-backlog-size config (partial sync will succeed
# and then replica will get disconnected).
# Such a configuration is ignored (the size of repl-backlog-size will be used).
# This doesn't have memory consumption implications since the replica client
# will share the backlog buffers memory.
#
# Both the hard or the soft limit can be disabled by setting them to zero.
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

# Client query buffers accumulate new commands. They are limited to a fixed
# amount by default in order to avoid that a protocol desynchronization (for
# instance due to a bug in the client) will lead to unbound memory usage in
# the query buffer. However you can configure it here if you have very special
# needs, such us huge multi/exec requests or alike.
#
# client-query-buffer-limit 1gb

# In some scenarios client connections can hog up memory leading to OOM
# errors or data eviction. To avoid this we can cap the accumulated memory
# used by all client connections (all pubsub and normal clients). Once we
# reach that limit connections will be dropped by the server freeing up
# memory. The server will attempt to drop the connections using the most 
# memory first. We call this mechanism "client eviction".
#
# Client eviction is configured using the maxmemory-clients setting as follows:
# 0 - client eviction is disabled (default)
#
# A memory value can be used for the client eviction threshold,
# for example:
# maxmemory-clients 1g
#
# A percentage value (between 1% and 100%) means the client eviction threshold
# is based on a percentage of the maxmemory setting. For example to set client
# eviction at 5% of maxmemory:
# maxmemory-clients 5%

# 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
#
# proto-max-bulk-len 512mb

# Redis calls an internal function to perform many background tasks, like
# closing connections of clients in timeout, purging expired keys that are
# never requested, and so forth.
#
# Not all tasks are performed with the same frequency, but Redis checks for
# tasks to perform according to the specified "hz" value.
#
# By default "hz" is set to 10. Raising the value will use more CPU when
# Redis is idle, but at the same time will make Redis more responsive when
# there are many keys expiring at the same time, and timeouts may be
# handled with more precision.
#
# The range is between 1 and 500, however a value over 100 is usually not
# a good idea. Most users should use the default of 10 and raise this up to
# 100 only in environments where very low latency is required.
hz 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.
#
# 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.
dynamic-hz yes

# When a child rewrites the AOF file, if the following option is enabled
# the file will be fsync-ed every 4 MB of data generated. This is useful
# in order to commit the file to the disk more incrementally and avoid
# big latency spikes.
aof-rewrite-incremental-fsync yes

# When redis saves RDB file, if the following option is enabled
# the file will be fsync-ed every 4 MB of data generated. This is useful
# in order to commit the file to the disk more incrementally and avoid
# big latency spikes.
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.
#
# 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:
#
# 1. A random number R between 0 and 1 is extracted.
# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).
# 3. The counter is incremented only if R < P.
#
# The default lfu-log-factor is 10. This is a table of how the frequency
# counter changes with a different number of accesses with different
# logarithmic factors:
#
# +--------+------------+------------+------------+------------+------------+
# | factor | 100 hits   | 1000 hits  | 100K hits  | 1M hits    | 10M hits   |
# +--------+------------+------------+------------+------------+------------+
# | 0      | 104        | 255        | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 1      | 18         | 49         | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 10     | 10         | 18         | 142        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 100    | 8          | 11         | 49         | 143        | 255        |
# +--------+------------+------------+------------+------------+------------+
#
# NOTE: The above table was obtained by running the following commands:
#
#   redis-benchmark -n 1000000 incr foo
#   redis-cli object freq foo
#
# NOTE 2: The counter initial value is 5 in order to give new objects a chance
# to accumulate hits.
#
# The counter decay time is the time, in minutes, that must elapse in order
# for the key counter to be divided by two (or decremented if it has a value
# less <= 10).
#
# The default value for the lfu-decay-time is 1. A special value of 0 means to
# decay the counter every time it happens to be scanned.
#
# lfu-log-factor 10
# lfu-decay-time 1
############################### 高级配置 ###############################

# 当哈希值有少量的条目,并且最大的条目不超过一个给定的阈值时,哈希值就会使用一个内存效率高的数据结构进行编码。
# 这些阈值可以通过以下指令来配置。
hash-max-listpack-entries 512
hash-max-listpack-value 64

# 列表也以一种特殊的方式进行编码,以节省大量的空间。每个内部列表节点允许的条目数可以指定为一个固定的最大尺寸或最大元素数。
# 对于一个固定的最大尺寸,使用-5到-1,意思是:
# -5: 最大尺寸: 64 Kb   <-- 不建议用于正常工作负载
# -4:最大尺寸:32 Kb   <-- 不建议使用
# -3:最大尺寸:16 Kb   <-- 可能不建议使用
# -2:最大尺寸:8 Kb    <-- 良好
# -1: 最大尺寸:4 Kb    <-- 良好
# 正数意味着每一个列表节点最多存储_个元素的数量。性能最高的选项通常是-2(8 Kb大小)或-1(4 Kb大小),但如果你的使用情况特殊,
# 可以根据需要调整设置。
list-max-listpack-size -2

# 列表也可以被压缩。压缩深度是指从列表的 *each* 边开始 *exclude* 压缩的快速列表 ziplist 节点的数量。 列表的头部和尾部
# 总是未被压缩的,以便进行快速推/拉操作。 设置如下:
# 0: 禁用所有的列表压缩。
# 1:深度 1 意味着 "在列表的 1 个节点之后才开始压缩,从头部或尾部开始"。
#   因此:[head]->node->node->...->节点->[tail]
#    [head], [tail]将永远是未压缩的;内部节点将被压缩
# 2: [head]->[next]->node->node->...->node->[prev]->[tail] 。
#   2 在这里的意思是:不要压缩 head 或 head->next 或 tail->prev 或 tail,而是压缩它们之间的所有节点。
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail] 等等。
list-compress-depth 0

# 集合只在一种情况下有特殊的编码:当一个集合只是由刚好是 64 位有符号整数范围内的 radix 10 的字符串组成时。
# 下面的配置设置设置了集合的大小限制,以便使用这种特殊的节省内存的编码。
set-max-intset-entries 512

# 与哈希值和列表类似,排序集也被特别编码,以节省大量空间。这种编码只有在排序集的长度和元素低于以下限制时才会使用。
zset-max-listpack-entries 128
zset-max-listpack-value 64

# HyperLogLog 稀疏表示法的字节数限制。这个限制包括 16 字节的标题。当使用稀疏表示法的 HyperLogog 超过这个限制时,
# 它将被转换成密集表示法。
#
# 一个大于 16000 的值是完全没有用的,因为在这一点上,密集表示法的内存效率更高。
#
# 建议的值是 ~3000,以获得空间效率编码的好处,而不至于使 PFADD 的速度太慢,因为稀疏编码的速度是O(N)。当 CPU 不是问题,
# 但空间是问题,并且数据集是由许多 cardinality 在 0-15000 范围内的 HyperLogLogs 组成时,该值可以提高到 ~10000。
hll-sparse-max-bytes 3000

# 流的大节点最大尺寸/项目。流数据结构是一个大节点的弧度树,里面编码了多个项目。使用这个配置,可以配置单个节点的字节数有多大,
# 以及在追加新的流条目时切换到一个新的节点之前,它可能包含的最大项目数。如果下面的任何一个设置被设置为 0,那么这个
# 限制就会被忽略,所以举例来说,可以通过将 max-byte 设置为 0,max-entries设置为所需的值来设置最大条目限制。
stream-node-max-bytes 4096
stream-node-max-entries 100

# 主动重新洗牌每 100 毫秒使用1毫秒的 CPU 时间,以帮助重新洗牌 Redis 的主哈希表(将顶层键映射到值的哈希表)。Redis 
# 使用的哈希表实现(见dict.c)执行了一个懒惰的重洗:你越是碰到正在重洗的哈希表的操作,就会执行更多的重洗 "步骤",
# 所以如果服务器是空闲的,重洗永远不会完成,还有一些内存被哈希表使用。
#
# 默认情况下,每秒钟使用这个毫秒 10 次,以便主动重新洗刷主字典,尽可能释放内存。
#
# 如果不确定:使用 "activerehashing no",如果你有硬性的延迟要求,而且在你的环境中,Redis 可以不时地回复 2 毫秒延迟的查询,
# 这不是一件好事。
#
# 如果你没有这样的硬性要求,但又想尽可能地释放内存,就使用 
activerehashing yes

# 客户端输出缓冲区的限制可以用来强制断开那些由于某种原因不能快速从服务器上读取数据的客户端(一个常见的原因是 Pub/Sub 客户端消耗信息的
# 速度比不上发布者产生信息的速度)。
#
# 对于三种不同类别的客户端,可以设置不同的限制:
#
# normal    -> 普通客户端,包括 MONITOR 客户端
# replica   -> replica 客户端
# pubsub    -> 客户端至少订阅了一个 pubsub 频道或模式
#
# 每个client-output-buffer-limit指令的语法如下:
#
# client-output-buffer-limit    
#
# 一旦达到硬限制,或达到软限制并保持在指定的秒数(连续),客户端将立即断开连接。因此,例如,如果硬限制是 32 兆字节,软限制是 16 兆字节/10 秒,
# 如果输出缓冲区的大小达到 32 兆字节,客户端将立即断开连接,但如果客户端达到 16 兆字节并连续克服 10 秒的限制,也将被断开连接。
#
# 默认情况下,正常的客户端不会受到限制,因为他们不会在没有询问的情况下接收数据(以推送的方式),而只是在请求之后,所以只有异步客户端可能会创造一个场景,
# 即请求数据的速度比它能读取的速度快。
#
# 相反,对 pubsub 和 replica 客户端有一个默认的限制,因为订阅者和复制者是以推送方式接收数据的。
#
# 请注意,将复制客户端的输出缓冲区限制设置为低于 rep-backlog-size 的配置是没有意义的(部分同步会成功,然后复制会被断开)。这样的配置会被忽略
# (repl-backlog-size 的大小将被使用)。这对内存消耗没有影响,因为复制客户端将共享积压缓冲区的内存。
#
# 硬限制或软限制都可以通过设置为零来禁用
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

# 客户端查询缓冲区会积累新的命令。默认情况下,它们被限制在一个固定的数量,以避免协议的不同步(例如由于客户端的一个错误)会导致查询缓冲区的内存使用
# 不受限制。然而,如果你有非常特殊的需求,例如巨大的多/执行请求或类似的需求,你可以在这里配置它。
#
# client-query-buffer-limit 1gb

# 在某些情况下,客户端连接会占用内存,导致 OOM 错误或数据驱逐。为了避免这种情况,我们可以对所有客户端连接(所有 pubsub 和普通客户端)所使用的
# 累积内存设置上限。一旦我们达到这个上限,服务器就会放弃连接,释放出内存。服务器将尝试首先放弃使用最多内存的连接。我们称这种机制为 "客户端驱逐"。
#
# 客户端驱逐是通过maxmemory-clients设置来配置的,如下所示:
# 0 - 客户端驱逐被禁用(默认)
#
# 可以使用一个内存值作为客户端驱逐的阈值
# 例如:
# maxmemory-clients 1g
#
# 百分比值(在 1% 和 100% 之间)意味着客户端驱逐阈值是基于 maxmemory 设置的一个百分比。例如,将客户端驱逐设置为最大内存的 5%。
# maxmemory-clients 5%

# 在 Redis 协议中,批量请求,也就是代表单个字符串的元素,通常被限制在 512mb。然而,你可以在这里改变这个限制,但必须是 1mb 或更大。
#
# proto-max-bulk-len 512mb

# Redis 调用一个内部函数来执行许多后台任务,比如在超时时关闭客户的连接,清除从未被请求的过期密钥,等等。
#
# 并非所有的任务都以相同的频率执行,但 Redis 会根据指定的 "hz" 值检查要执行的任务。
#
# 默认情况下,"hz" 被设置为 10。提高该值会在 Redis 空闲时使用更多的 CPU,但同时会使 Redis 在有许多键同时到期时反应更快,
# 而且超时的处理可能更精确。
#
# 范围在 1 到 500 之间,然而超过 100 的值通常不是一个好主意。大多数用户应该使用默认的 10,只有在需要非常低的延迟的环境下,
# 才可以将其提高到100。
hz 10

# 通常情况下,有一个与连接的客户数量成比例的 HZ 值是很有用的。这很有用,例如,为了避免每个后台任务的调用有太多的客户被处理,
# 以避免延迟的高峰期。
#
# 由于默认的 HZ 值被保守地设置为 10,Redis 提供并默认启用了使用自适应 HZ 值的能力,当有很多连接的客户端时,HZ 值会暂时提高。
#
# 当启用动态 HZ 时,实际配置的 HZ 将被用作基线,但一旦有更多的客户端连接,配置的 HZ 值的倍数将根据需要被实际使用。通过这种方式,
# 一个空闲的实例将使用很少的 CPU 时间,而一个繁忙的实例将有更多的响应。
dynamic-hz yes

# 当一个孩子重写 AOF 文件时,如果启用以下选项,该文件将每产生 4MB 的数据就进行一次同步。这对于将文件更多地提交到磁盘并避免
# 大的延迟峰值很有用。
aof-rewrite-incremental-fsync yes

# 当 redis 保存 RDB 文件时,如果启用以下选项,该文件将每产生 4MB 的数据就进行一次 fsync。这对于以更多的增量将文件提交到磁
# 盘并避免大的延迟峰值非常有用。
rdb-save-incremental-fsync yes

# Redis 的 LFU 驱逐(见 maxmemory 设置)可以被调整。然而,从默认设置开始是个好主意,只有在调查了如何改善性能和 LFU 键随时间变化
# 的情况后才能改变它们,这可以通过 OBJECT FREQ 命令来检查。
#
# 在 Redis LFU 的实现中,有两个可调整的参数:计数器的对数因子和计数器的衰减时间。在改变这两个参数之前,了解这两个参数的含义
# 是很重要的。
#
# LFU 计数器每个键只有 8 位,它的最大值是 255,所以 Redis 使用了一个具有对数行为的概率递增。考虑到旧的计数器的值,当一个键
# 被访问时,计数器会以这种方式递增。
#
# 1. 在 0 和 1 之间提取一个随机数 R。
# 2. 一个概率 P 被计算为1/(old_value*lfu_log_factor+1)。
# 3. 只有当 R

27、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.
#
# 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.
#
# 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.
#
# 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.
#
# 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".
#
# 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.

# Active defragmentation is disabled by default
# activedefrag no

# Minimum amount of fragmentation waste to start active defrag
# active-defrag-ignore-bytes 100mb

# Minimum percentage of fragmentation to start active defrag
# active-defrag-threshold-lower 10

# Maximum percentage of fragmentation at which we use maximum effort
# 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
# active-defrag-max-scan-fields 1000

# Jemalloc background thread for purging will be enabled by default
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.
#
# 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.
#
# 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:
#
# Set redis server/io threads to cpu affinity 0,2,4,6:
# server_cpulist 0-7:2
#
# Set bio threads to cpu affinity 1,3:
# bio_cpulist 1,3
#
# Set aof rewrite child process to cpu affinity 8,9,10,11:
# aof_rewrite_cpulist 8-11
#
# Set bgsave child process to cpu affinity 1,10,11
# bgsave_cpulist 1,10-11

# In some cases redis will emit warnings and even refuse to start if it detects
# that the system is in bad state, it is possible to suppress these warnings
# by setting the following config which takes a space delimited list of warnings
# to suppress
#
# ignore-warnings ARM64-COW-BUG
########################### 主动碎片整理 #######################
#
# 什么是主动碎片整理?
# -------------------------------
#
# 主动(在线)碎片整理允许 Redis 服务器压缩内存中小的数据分配和去分配之间
# 留下的空间,从而允许重新获得内存。
#
# 分片是一个自然过程,每个分配器(但幸运的是,Jemalloc 较少)和某些工作负
# 载都会发生。通常情况下,为了减少碎片,需要重新启动服务器,或者至少要冲走所
# 有的数据并重新创建。然而,由于 Oran Agra 为 Redis 4.0实现的这个功能,
# 这个过程可以在运行时以 "hot" 的方式发生,而服务器正在运行。
#
# 基本上,当碎片化超过一定程度时(见下面的配置选项),Redis 将开始利用某些
# 特定的 Jemalloc 功能在连续的内存区域创建新的值副本(以了解分配是否导致碎
# 片化并将其分配在更好的地方),同时,将释放数据的旧副本。这个过程,对所有的
# 键重复递增,将导致碎片化下降到正常值。
#
# 需要理解的重要事情:
#
# 1. 这个功能默认是禁用的,只有在你编译 Redis 时使用了我们随 Redis 源代码
#    提供的 Jemalloc 副本时才会起作用。这是 Linux 构建时的默认情况。
#
# 2. 如果你没有碎片问题,你永远不需要启用这个功能。
#
# 3. 一旦你遇到碎片问题,你可以在需要时用 "CONFIG SET activedefrag yes"
#    命令来启用这个功能。
#
# 配置参数能够对碎片整理过程的行为进行微调。如果你不确定它们是什么意思,最好
# 不要触动默认值。

# 主动碎片整理在默认情况下是禁用的
# activedefrag no

# 内存碎片占用空间达到 100mb 的时候开始清理
# active-defrag-ignore-bytes 100mb

# 启动主动碎片整理的最小碎片百分比
# active-defrag-threshold-lower 10

# 零碎的最大百分比,在这个百分比上我们使用最大的努力
# active-defrag-threshold-upper 100

# 以 CPU 百分比计算的最小碎片整理工作量,在达到较低的阈值时使用
# active-defrag-cycle-min 1

# 以 CPU 百分比计算的碎片整理的最大努力,在达到上限时使用
# active-defrag-cycle-max 25

# 从主字典扫描中处理的 set/hash/zset/list 字段的最大数量
# active-defrag-max-scan-fields 1000

# 默认情况下,用于清除的 Jemalloc 后台线程将被启用
jemalloc-bg-thread yes

# 可以将 Redis 的不同线程和进程固定在系统中的特定 CPU 上,以使服务器的
# 性能最大化。这对于将不同的 Redis 线程固定在不同的 CPU 上是很有用的,
# 同时也可以确保在同一主机上运行的多个 Redis 实例被固定在不同的 CPU 上。
#
# 通常情况下,你可以使用 "taskset "命令来做到这一点,但是在 Linux 和 
# FreeBSD 中,也可以通过 Redis 配置直接做到这一点。
#
# 你可以将服务器/IO线程、bio线程、aof重写子进程和bgsave子进程固定下来。
# 指定 cpu 列表的语法与 taskset 命令相同。
#
# 将redis服务器/io线程设置为cpu亲和力0,2,4,6。
# server_cpulist 0-7:2
#
# 将bio线程设置为cpu亲和度1,3。
# bio_cpulist 1,3
#
# 设置aof重写子进程为cpu亲和力8,9,10,11:
# aof_rewrite_cpulist 8-11
#
# 设置bgsave子进程为cpu亲和力1,10,11
# bgsave_cpulist 1,10-11

# 在某些情况下,如果 redis 检测到系统处于不良状态,它会发出警告,甚至拒绝启动,
# 可以通过设置以下配置来抑制这些警告,该配置需要一个以空格分隔的警告列表来抑制
# 这些警告
#
# ignore-warnings ARM64-COW-BUG

你可能感兴趣的:(redis)