Redis使用——Redis的redis.conf配置注釋詳解(二)
背景
日常我們開發(fā)時(shí)固蛾,我們會(huì)遇到各種各樣的奇奇怪怪的問(wèn)題(踩坑o(╯□╰)o)后室,這個(gè)常見問(wèn)題系列就是我日常遇到的一些問(wèn)題的記錄文章系列铸史,這里整理匯總后分享給大家换淆,讓其還在深坑中的小伙伴有繩索能爬出來(lái)。
同時(shí)在這里也歡迎大家把自己遇到的問(wèn)題留言或私信給我乱凿,我看看其能否給大家解決蚯撩。
開發(fā)環(huán)境
- 系統(tǒng):Ubuntu
- 工具:Docker
- 鏡像:Redis
- 官方配置:redis.conf
內(nèi)容
本節(jié)對(duì)于其Redis的redis.conf配置進(jìn)行注釋翻譯础倍,確定各個(gè)配置的主要用途,便于日后配置使用胎挎,由于redis.conf中的配置較多沟启,因此我們拆分為四節(jié)進(jìn)行,本節(jié)為第二篇犹菇,話不多說(shuō)下面開始德迹。
################################# REPLICATION #################################
# 主副本復(fù)制。使用replicaof 使Redis 實(shí)例復(fù)制另一個(gè)Redis服務(wù)器揭芍。
# 關(guān)于Redis復(fù)制的一些事情需要盡快了解胳搞。
#
# +------------------+ +---------------+
# | Master | ---> | Replica |
# | (receive writes) | | (exact copy) |
# +------------------+ +---------------+
#
# 1) Redis 復(fù)制是異步的,但您可以配置一個(gè) master 來(lái)停止接受寫入称杨,如果它似乎沒(méi)有連接到至少給定數(shù)量的副本肌毅。
# 2) Redis 副本能夠與master 如果復(fù)制鏈接丟失的時(shí)間相對(duì)較少時(shí)間。您可能需要配置復(fù)制積壓大辛辛怼(請(qǐng)參閱下一個(gè)此文件的部分)根據(jù)您的需要具有合理的值芽腾。
# 3) 復(fù)制是自動(dòng)的,不需要用戶干預(yù)页衙。之后網(wǎng)絡(luò)分區(qū)副本自動(dòng)嘗試重新連接到主節(jié)點(diǎn)并與它們重新同步摊滔。
#
# replicaof <masterip> <masterport>
# 如果 master 受密碼保護(hù)(使用“requirepass”配置下面的指令)可以告訴副本之前進(jìn)行身份驗(yàn)證開始復(fù)制同步過(guò)程,否則master會(huì)拒絕副本請(qǐng)求店乐。
#
# masterauth <master-password>
#
# 但是艰躺,如果您使用的是 Redis ACL,這還不夠(對(duì)于 Redis 版本6 或更高)眨八,并且默認(rèn)用戶無(wú)法運(yùn)行 PSYNC命令和/或復(fù)制所需的其他命令腺兴。
# 在這種情況下是最好配置一個(gè)特殊用戶用于復(fù)制,并指定
# masteruser 配置如下:
#
# masteruser <username>
#
# 當(dāng) masteruser 被指定時(shí)廉侧,副本將對(duì)其進(jìn)行身份驗(yàn)證master 使用新的 AUTH 形式: AUTH <username> <password>.
# 當(dāng)一個(gè)副本與主節(jié)點(diǎn)失去連接時(shí)页响,或者當(dāng)副本仍在進(jìn)行中,副本可以以兩種不同的方式運(yùn)行:
# is still in progress, the replica can act in two different ways:
#
# 1) 如果 replica-serve-stale-data 設(shè)置為“yes”(默認(rèn))段誊,副本將仍然回復(fù)客戶端請(qǐng)求闰蚕,可能有過(guò)時(shí)的數(shù)據(jù),或者如果這是第一次同步连舍,數(shù)據(jù)集可能只是空的没陡。
# 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) 如果 replica-serve-stale-data 設(shè)置為“no”,副本將回復(fù)除以下命令外,所有命令都出現(xiàn)錯(cuò)誤“SYNC with master in progress”:
# INFO, REPLICAOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, SUBSCRIBE,
# UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, COMMAND, POST,
# HOST and LATENCY.
#
replica-serve-stale-data yes
# 您可以配置副本實(shí)例接受或不接受寫入盼玄。寫反對(duì)副本實(shí)例可能有助于存儲(chǔ)一些臨時(shí)數(shù)據(jù)(因?yàn)閿?shù)據(jù)寫在副本上的在與主服務(wù)器重新同步后很容易被刪除)但是
# 如果客戶端因?yàn)橐粋€(gè)原因而寫入它贴彼,也可能會(huì)導(dǎo)致問(wèn)題錯(cuò)誤配置。
#
# 由于 Redis 2.6 默認(rèn)副本是只讀的埃儿。
#
# 注意:只讀副本不會(huì)暴露給不受信任的客戶端在網(wǎng)上器仗。它只是防止濫用實(shí)例的保護(hù)層。
# 仍然是只讀副本默認(rèn)導(dǎo)出所有管理命令如 CONFIG童番、DEBUG 等青灼。在有限的范圍內(nèi),您可以改進(jìn)只讀副本的安全性使用“rename-command”來(lái)隱藏所有管理/危險(xiǎn)命令妓盲。
#
replica-read-only yes
# 復(fù)制同步策略:disk 或 socket.
#
# 無(wú)法繼續(xù)的新副本和重新連接的副本復(fù)制過(guò)程只是接收差異杂拨,需要做所謂的"full synchronization"。RDB 文件從 master 傳輸?shù)礁北尽?#
# 傳輸可以通過(guò)兩種不同的方式發(fā)生:
#
# 1) Disk-backed: Redis master 創(chuàng)建一個(gè)新的進(jìn)程來(lái)寫入 RDB磁盤上的文件悯衬。后來(lái)文件由父級(jí)傳輸以增量方式處理副本弹沽。
# 2) Diskless: Redis master 創(chuàng)建一個(gè)新進(jìn)程,直接寫入RDB 文件復(fù)制套接字筋粗,根本不接觸磁盤策橘。
#
# 使用磁盤備份復(fù)制,在生成 RDB 文件的同時(shí)娜亿,更多的副本可以在當(dāng)前子進(jìn)程中排隊(duì)并與 RDB 文件一起提供服務(wù)生成 RDB 文件完成其工作丽已。
# 用無(wú)盤復(fù)制代替一旦傳輸開始,到達(dá)的新副本將排隊(duì)并生成一個(gè)新副本傳輸將在當(dāng)前終止時(shí)開始买决。
#
# 當(dāng)使用無(wú)盤復(fù)制時(shí)沛婴,master 等待一個(gè)可配置的數(shù)量開始傳輸前的時(shí)間(以秒為單位),希望多次個(gè)副本將到達(dá)督赤,傳輸可以并行化嘁灯。
#
# 使用慢速磁盤和快速(大帶寬)網(wǎng)絡(luò),無(wú)盤復(fù)制效果更好躲舌。
#
repl-diskless-sync no
# 啟用無(wú)盤復(fù)制時(shí)丑婿,可以配置延遲服務(wù)器等待以生成通過(guò)套接字傳輸 RDB 的子進(jìn)程到副本。
# 這很重要没卸,因?yàn)橐坏﹤鬏旈_始羹奉,就無(wú)法提供服務(wù)新副本到達(dá),將排隊(duì)等待下一次 RDB 傳輸约计,因此服務(wù)器等待延遲以便讓更多副本到達(dá)诀拭。
# 延遲以秒為單位指定,默認(rèn)為 5 秒病蛉。禁用它完全只是將其設(shè)置為 0 秒炫加,傳輸將盡快開始。
#
repl-diskless-sync-delay 5
# -----------------------------------------------------------------------------
# 警告:RDB 無(wú)盤負(fù)載是實(shí)驗(yàn)性的铺然。由于在此設(shè)置中復(fù)制品不會(huì)立即將 RDB 存儲(chǔ)在磁盤上俗孝,可能會(huì)導(dǎo)致數(shù)據(jù)丟失故障轉(zhuǎn)移。
# RDB無(wú)磁盤加載+ Redis模塊不處理I/O讀也可以在與master的初始同步階段魄健,如果出現(xiàn)I/O錯(cuò)誤赋铝,Redis將中止。只有當(dāng)你在做你正在做的事情時(shí)才使用沽瘦。
# -----------------------------------------------------------------------------
#
# Replica可以直接從replica加載它從replication link讀取的RDB套接字革骨,或者將RDB存儲(chǔ)到一個(gè)文件中,并在從主服務(wù)器完全接收到該文件后讀取該文件析恋。
#
# 在很多情況下良哲,磁盤比網(wǎng)絡(luò)慢,并且存儲(chǔ)和加載RDB文件可能會(huì)增加復(fù)制時(shí)間(甚至增加主服務(wù)器的Write內(nèi)存和緩沖)助隧。
# 然而筑凫,直接從套接字解析RDB文件可能意味著我們必須在接收到完整的RDB之前刷新當(dāng)前數(shù)據(jù)庫(kù)的內(nèi)容。為此并村,我們有以下選擇:
#
# "disabled" - 不要使用無(wú)盤加載(先將 rdb 文件存儲(chǔ)到磁盤)
# "on-empty-db" - 只有在完全安全的情況下才使用無(wú)盤加載巍实。
# "swapdb" - 在RAM中保留當(dāng)前db內(nèi)容的副本,同時(shí)直接從套接字解析數(shù)據(jù)哩牍。注意棚潦,這需要足夠的內(nèi)存,如果您沒(méi)有足夠的內(nèi)存膝昆,則可能會(huì)導(dǎo)致OOM死亡丸边。
repl-diskless-load disabled
# 副本以預(yù)定義的時(shí)間間隔向服務(wù)器發(fā)送ping〖苑酰可以使用repl_ping_replica_period選項(xiàng)更改這個(gè)間隔原环。默認(rèn)值是10秒。
#
# repl-ping-replica-period 10
# 以下選項(xiàng)設(shè)置復(fù)制超時(shí):
#
# 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).
#
# 重要的是要確保這個(gè)值大于為repp -ping-replica-period指定的值处窥,否則每次主服務(wù)器和副本之間的流量較低時(shí)都會(huì)檢測(cè)到超時(shí)嘱吗。默認(rèn)值是60秒。
#
# repl-timeout 60
# 在復(fù)制套接字同步后禁用TCP_NODELAY ?
#
# 如果選擇“yes”滔驾,Redis將使用更少的TCP包和更少的帶寬來(lái)發(fā)送數(shù)據(jù)到副本谒麦。但是,這可能會(huì)增加數(shù)據(jù)出現(xiàn)在副本端的延遲哆致,使用默認(rèn)配置的Linux內(nèi)核最高可達(dá)40毫秒绕德。
#
# 如果選擇“no”,數(shù)據(jù)在復(fù)制端出現(xiàn)的延遲將會(huì)減少摊阀,但更多的帶寬將被用于復(fù)制耻蛇。
#
# 默認(rèn)情況下踪蹬,我們優(yōu)化的是低延遲,但在非常高的流量條件下臣咖,或當(dāng)主服務(wù)器和副本有很多跳的時(shí)候跃捣,將此轉(zhuǎn)換為“yes”可能是一個(gè)好主意。
repl-disable-tcp-nodelay no
# 設(shè)置復(fù)制待辦事項(xiàng)大小夺蛇。backlog是一個(gè)緩沖區(qū)疚漆,當(dāng)副本斷開連接一段時(shí)間后,它會(huì)累積副本數(shù)據(jù)刁赦,因此當(dāng)一個(gè)副本想要重新連接時(shí)娶聘,通常不需要完全重同步
# 但部分重同步就足夠了,只需要傳遞副本在斷開連接時(shí)丟失的部分?jǐn)?shù)據(jù)甚脉。
#
# 復(fù)制積壓越大丸升,副本能夠承受斷開的時(shí)間就越長(zhǎng),并且稍后能夠執(zhí)行部分重同步牺氨。
#
# 只有至少有一個(gè)副本連接時(shí)才會(huì)分配積壓发钝。
#
# repl-backlog-size 1mb
# 當(dāng)主服務(wù)器沒(méi)有連接副本一段時(shí)間后,積壓將被釋放波闹。下面的選項(xiàng)配置從最后一個(gè)副本斷開連接時(shí)開始釋放待定緩沖區(qū)所需的秒數(shù)酝豪。
#
# 請(qǐng)注意,副本永遠(yuǎn)不會(huì)因?yàn)槌瑫r(shí)而釋放積壓精堕,因?yàn)樗鼈兛赡軙?huì)在稍后升級(jí)為主副本孵淘,并且應(yīng)該能夠正確地與其他副本“partially resynchronize”:因此,它們應(yīng)該總是積累積壓歹篓。
#
# 值為 0 表示永遠(yuǎn)不會(huì)釋放積壓瘫证。
#
# repl-backlog-ttl 3600
# 副本優(yōu)先級(jí)是Redis在INFO中發(fā)布的整數(shù)輸出。
# 當(dāng)主服務(wù)器不能正常工作時(shí)庄撮,Redis Sentinel使用它來(lái)選擇一個(gè)副本來(lái)提升到主服務(wù)器背捌。
# 優(yōu)先級(jí)低的副本被認(rèn)為更有利于提升,例如洞斯,如果有三個(gè)優(yōu)先級(jí)為10,100,25的副本毡庆,Sentinel將選擇優(yōu)先級(jí)為10的副本,這是最低的烙如。
#
# 然而么抗,一個(gè)特殊的優(yōu)先級(jí)為0的副本標(biāo)志著該副本不能執(zhí)行主角色,因此優(yōu)先級(jí)為0的副本永遠(yuǎn)不會(huì)被Redis Sentinel選擇進(jìn)行升級(jí)亚铁。
# 默認(rèn)優(yōu)先級(jí)為 100.
replica-priority 100
# 如果少于N 個(gè)副本連接蝇刀,延遲小于或等于 M 秒。
# N 個(gè)副本需要處于“在線”狀態(tài)徘溢。
#
# 延遲(以秒為單位)必須<=指定的值吞琐,該延遲是根據(jù)從副本收到的最后一個(gè)ping計(jì)算的捆探,該副本通常每秒發(fā)送一次。
#
# 這個(gè)選項(xiàng)并不保證N個(gè)副本將接受寫操作站粟,但是在沒(méi)有足夠的副本可用的情況下黍图,將暴露丟失寫操作的窗口限制在指定的秒數(shù)。
#
# 例如卒蘸,需要至少 3 個(gè)延遲 <= 10 秒的副本,請(qǐng)使用:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# 將一個(gè)或另一個(gè)設(shè)置為 0 將禁用該功能翻默。
#
# 默認(rèn)情況下缸沃,min-replicas-to-write 設(shè)置為 0(禁用功能)并且 min-replicas-max-lag 設(shè)置為 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
############################### KEYS TRACKING #################################
# Redis implements server assisted support for client side caching of values.
# This is implemented using an invalidation table that remembers, using
# 16 millions of slots, what clients may have certain subsets of keys. In turn
# this is used in order to send invalidation messages to clients. Please
# check this page to understand more about the feature:
#
# 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
################################## 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 <username> ... acl rules ...
#
# For example:
#
# user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
#
# The special username "default" is used for new connections. If this user
# has the "nopass" rule, then new connections will be immediately authenticated
# as the "default" user without the need of any password provided via the
# AUTH command. Otherwise if the "default" user is not flagged with "nopass"
# the connections will start in not authenticated state, and will require
# AUTH (or the HELLO command AUTH option) in order to be authenticated and
# start to work.
#
# 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.
# +<command> Allow the execution of that command
# -<command> Disallow the execution of that command
# +@<category> Allow the execution of all the commands in such category
# with valid categories are like @admin, @set, @sortedset, ...
# and so forth, see the full list in the server.c file where
# the Redis command table is described and defined.
# The special category @all means all the commands, but currently
# present in the server, and that will be loaded in the future
# via modules.
# +<command>|subcommand Allow a specific subcommand of an otherwise
# disabled command. Note that this form is not
# allowed as negative like -DEBUG|SEGFAULT, but
# only additive starting with "+".
# 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.
# ~<pattern> Add a pattern of keys that can be mentioned as part of
# commands. For instance ~* allows all the keys. The pattern
# is a glob-style pattern like the one of KEYS.
# It is possible to specify multiple patterns.
# allkeys Alias for ~*
# resetkeys Flush the list of allowed keys patterns.
# ><password> Add this password to the list of valid password for the user.
# For example >mypass will add "mypass" to the list.
# This directive clears the "nopass" flag (see later).
# <<password> Remove this password from the list of valid passwords.
# nopass All the set passwords of the user are removed, and the user
# is flagged as requiring no password: it means that every
# 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.
#
# 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.
#
# 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 <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# requirepass foobared
# Command renaming (DEPRECATED).
#
# ------------------------------------------------------------------------
# WARNING: avoid using this option if possible. Instead use ACLs to remove
# commands from the default user, and put them only in some admin user you
# create for administrative purposes.
# ------------------------------------------------------------------------
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
#
# Example:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to replicas may cause problems.
################################### CLIENTS ####################################
# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# 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
############################## 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 <bytes>
# 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, Redis will return an error on write
# operations, when there are no suitable keys for eviction.
#
# At the date of writing these commands are: set setnx setex append
# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
# getset mset msetnx exec sort
#
# The default is:
#
# maxmemory-policy noeviction
# 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
# 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
更多內(nèi)容詳見 Redis使用——Redis的redis.conf配置注釋詳解(三)
本文聲明:
88x31.png
知識(shí)共享許可協(xié)議
本作品由 cn華少 采用 知識(shí)共享署名-非商業(yè)性使用 4.0 國(guó)際許可協(xié)議 進(jìn)行許可。