Redis5.0.0配置文件

# redis版本 5.0.0
 
# 如果想要使用到配置文件,Redis服務必須以配置文件的路徑作爲第一個參數啓動。如:
./redis-server /path/to/redis.conf
 
# 單位說明:當需要指定內存大小時,可能會用到不同的單位,如1k、5GB、4M等,這裏給出其單位含義:
# 指定單位是大小寫不敏感。如1GB、1gB、1Gb是一樣的。
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
 
######################### 引用 #########################
 
# 不同redis server可以使用同一個模版配置作爲主配置,並引用其它配置文
# 件用於本server的個性化設置include並不會被CONFIG REWRITE命令覆蓋。
# 但是主配置文件的選項會被覆蓋。想故意覆蓋主配置的話就把include放文件前面,
# 否則最好放末尾
# include /path/to/local.conf
# include /path/to/other.conf
 
######################### 模塊 ######################### 
# 啓動時加載模塊。如果服務器無法加載模塊,則會中止。可以使用多個loadmodule指令。
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
 
######################### 網絡 #########################
 
# 不指定bind的話redis將會監聽所有網絡接口。這個配置是肯定需要指定的。
# Examples:
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
# 下面這個配置是隻允許本地客戶端訪問。
bind 127.0.0.1
 
# 是否開啓保護模式。默認開啓,如果沒有設置bind項的ip和redis密碼的話,服務將只允許本地訪問。
protected-mode yes
 
# 端口設置,默認爲 6379
# 如果port設置爲0 redis將不會監聽tcp socket
port 6379
 
# 在高併發環境下需要一個高backlog值來避免慢客戶端連接問題。注意Linux內核默默將這個值減小到/proc/sys/net/core/somaxconn的值,所以需要確認增大somaxconn和tcp_max_syn_backlog 兩個值來達到需要的效果。
tcp-backlog 511
 
# 指定用來監聽Unix套套接字的路徑。沒有默認值,沒有指定的情況下Redis不會監聽Unix socket
# unixsocket /tmp/redis.sock
# unixsocketperm 700
 
# 客戶端空閒多少秒後關閉連接(0爲不關閉)
timeout 0
 
# tcp-keepalive設置。如果非零,
# 則設置SO_KEEPALIVE選項來向空閒連接的客戶端發送ACK,用途如下:
# 1)能夠檢測無響應的對端
# 2)讓該連接中間的網絡設備知道這個連接還存活
# 在Linux上,這個指定的值(單位秒)就是發送ACK的時間間隔。
# 注意:要關閉這個連接需要兩倍的這個時間值。
# 在其他內核上這個時間間隔由內核配置決定
tcp-keepalive 300
 
######################### 通用 #########################
 
# 是否將Redis作爲守護進程運行。如果需要的話配置成'yes'
# 注意配置成守護進程後Redis會將進程號寫入文件/var/run/redis.pid
daemonize no
 
# 是否通過upstart或systemd管理守護進程。默認no沒有服務監控,其它選項有upstart, systemd, auto
supervised no
 
# pid文件在redis啓動時創建,退出時刪除。最佳實踐爲配置該項。
pidfile /var/run/redis_6379.pid
 
 
# 配置日誌級別。選項有debug, verbose, notice, warning
loglevel notice
 
# 日誌名稱。空字符串表示標準輸出。注意如果redis配置爲後臺進程,標準輸出中信息會發送到/dev/null
logfile ""
 
# 是否啓動系統日誌記錄。
# syslog-enabled no
 
# 指定系統日誌身份。
# syslog-ident redis
 
# 指定syslog設備。必須是user或LOCAL0 ~ LOCAL7之一。
# syslog-facility local0
 
# 設置數據庫個數。默認數據庫是 DB 0
# 可以通過SELECT where dbid is a number between 0 and 'databases'-1爲每個連接使用不同的數據庫。
databases 16
 
# redis啓動時是否顯示Logo
always-show-logo yes
######################### 備份  #########################
# 持久化設置:
# 下面的例子將會進行把數據寫入磁盤的操作:
#  900秒(15分鐘)之後,且至少1次變更
#  300秒(5分鐘)之後,且至少10次變更
#  60秒之後,且至少10000次變更
# 不寫磁盤的話就把所有 "save" 設置註釋掉就行了。
# 通過添加一條帶空字符串參數的save指令也能移除之前所有配置的save指令,如: save ""
save 900 1
save 300 10
save 60 10000
 
# 默認情況下如果上面配置的RDB模式開啓且最後一次的保存失敗,redis 將停止接受寫操作,
# 讓用戶知道問題的發生。如果後臺保存進程重新啓動工作了,redis 也將自動的允許寫操作。
# 如果有其它監控方式也可關閉。
stop-writes-on-bgsave-error yes
 
# 是否在備份.rdb文件時是否用LZF壓縮字符串,默認設置爲yes。如果想節約cpu資源可以把它設置爲no。
rdbcompression yes
 
# 因爲版本5的RDB有一個CRC64算法的校驗和放在了文件的末尾。這將使文件格式更加可靠,
# 但在生產和加載RDB文件時,這有一個性能消耗(大約10%),可以關掉它來獲取最好的性能。
# 生成的關閉校驗的RDB文件有一個0的校驗和,它將告訴加載代碼跳過檢查
rdbchecksum yes
 
# rdb文件名稱
dbfilename dump.rdb
 
# 備份文件目錄,文件名就是上面的 "dbfilename" 的值。累加文件也放這裏。
# 注意你這裏指定的必須是目錄,不是文件名。
dir ./
 
######################### 主從同步 #########################
 
# 主從同步配置。
# 1) redis主從同步是異步的,但是可以配置在沒有指定slave連接的情況下使master停止寫入數據。
# 2) 連接中斷一定時間內,slave可以執行部分數據重新同步。
# 3) 同步是自動的,slave可以自動重連且同步數據。
# replicaof <masterip> <masterport>
 
# master連接密碼
# masterauth <master-password>
 
# 當一個slave失去和master的連接,或者同步正在進行中,slave的行爲有兩種可能:
# 1) 如果 replica-serve-stale-data 設置爲 "yes" (默認值),slave會繼續響應客戶端請求,可能是正常數據,也可能是還沒獲得值的空數據。
# 2) 如果 replica-serve-stale-data 設置爲 "no",slave會回覆"正在從master同步(SYNC with master in progress)"來處理各種請求,除了 INFO 和 SLAVEOF 命令。
replica-serve-stale-data yes
 
# 你可以配置salve實例是否接受寫操作。可寫的slave實例可能對存儲臨時數據比較有用(因爲寫入salve# 的數據在同master同步之後將很容被刪除),但是如果客戶端由於配置錯誤在寫入時也可能產生一些問題。
# 從Redis2.6默認所有的slave爲只讀
# 注意:只讀的slave不是爲了暴露給互聯網上不可信的客戶端而設計的。它只是一個防止實例誤用的保護層。
# 一個只讀的slave支持所有的管理命令比如config,debug等。爲了限制你可以用'rename-command'來隱藏所有的管理和危險命令來增強只讀slave的安全性。
replica-read-only yes
 
# 同步策略: 磁盤或socket,默認磁盤方式
repl-diskless-sync no
 
# 如果非磁盤同步方式開啓,可以配置同步延遲時間,以等待master產生子進程通過socket傳輸RDB數據給slave。
# 默認值爲5秒,設置爲0秒則每次傳輸無延遲。
repl-diskless-sync-delay 5
 
# slave根據指定的時間間隔向master發送ping請求。默認10秒。
# repl-ping-replica-period 10
 
# 同步的超時時間
# 1)slave在與master SYNC期間有大量數據傳輸,造成超時
# 2)在slave角度,master超時,包括數據、ping等
# 3)在master角度,slave超時,當master發送REPLCONF ACK pings# 確保這個值大於指定的repl-ping-slave-period,否則在主從間流量不高時每次都會檢測到超時
# repl-timeout 60
 
# 是否在slave套接字發送SYNC之後禁用 TCP_NODELAY
# 如果選擇yes,Redis將使用更少的TCP包和帶寬來向slaves發送數據。但是這將使數據傳輸到slave上有延遲,Linux內核的默認配置會達到40毫秒。
# 如果選擇no,數據傳輸到salve的延遲將會減少但要使用更多的帶寬。
# 默認我們會爲低延遲做優化,但高流量情況或主從之間的跳數過多時,可以設置爲“yes”。
repl-disable-tcp-nodelay no
 
# 設置數據備份的backlog大小。backlog是一個slave在一段時間內斷開連接時記錄salve數據的緩衝,所以一個slave在重新連接時,不必要全量的同步,而是一個增量同步就足夠了,將在斷開連接的這段# 時間內把slave丟失的部分數據傳送給它。
# 同步的backlog越大,slave能夠進行增量同步並且允許斷開連接的時間就越長。
# backlog只分配一次並且至少需要一個slave連接。
# repl-backlog-size 1mb
 
# 當master在一段時間內不再與任何slave連接,backlog將會釋放。以下選項配置了從最後一個
# slave斷開開始計時多少秒後,backlog緩衝將會釋放。
# 0表示永不釋放backlog
# repl-backlog-ttl 3600
 
# slave的優先級是一個整數展示在Redis的Info輸出中。如果master不再正常工作了,sentinel將用它來選擇一個slave提升爲master。
# 優先級數字小的salve會優先考慮提升爲master,所以例如有三個slave優先級分別爲10,100,25,sentinel將挑選優先級最小數字爲10的slave。
# 0作爲一個特殊的優先級,標識這個slave不能作爲master,所以一個優先級爲0的slave永遠不會被# sentinel挑選提升爲master。
# 默認優先級爲100
slave-priority 100
 
# 如果master少於N個延時小於等於M秒的已連接slave,就可以停止接收寫操作。
# N個slave需要是“oneline”狀態。
# 延時是以秒爲單位,並且必須小於等於指定值,是從最後一個從slave接收到的ping(通常每秒發送)開始計數。
# 該選項不保證N個slave正確同步寫操作,但是限制數據丟失的窗口期。
# 例如至少需要3個延時小於等於10秒的slave用下面的指令:
# min-replicas-to-write 3
# min-replicas-max-lag 10
 
# 兩者之一設置爲0將禁用這個功能。
# 默認 min-replicas-to-write 值是0(該功能禁用)並且 min-replicas-max-lag 值是10。
 
# A Redis master is able to list the address and port of the attached
# replicas in different ways. For example the "INFO replication" section
# offers this information, which is used, among other tools, by
# Redis Sentinel in order to discover replica instances.
# Another place where this info is available is in the output of the
# "ROLE" command of a master.
#
# The listed IP and address 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 be actually reachable via different IP and port
# pairs. The following two options can be used by a replica in order to
# report to its master a specific set of IP and port, so that both INFO
# and ROLE will report those values.
#
# 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
 
######################### 安全 #########################
 
# 要求客戶端在處理任何命令時都要驗證身份和密碼。
# requirepass foobared
 
# 命令重命名
# 在共享環境下,可以爲危險命令改變名字。比如,你可以爲 CONFIG 改個其他不太容易猜到的名字,這樣內部的工具仍然可以使用。
# 例如:
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
# 也可以通過改名爲空字符串來完全禁用一個命令
# rename-command CONFIG ""
# 請注意:改變命令名字被記錄到AOF文件或被傳送到從服務器可能產生問題。
 
######################### 限制 #########################
 
# 設置最多同時連接的客戶端數量。默認這個限制是10000個客戶端,然而如果Redis服務器不能配置
# 處理文件的限制數來滿足指定的值,那麼最大的客戶端連接數就被設置成當前文件限制數減32(因爲Redis服務器保留了一些文件描述符作爲內部使用)
# 一旦達到這個限制,Redis會關閉所有新連接併發送錯誤'max number of clients reached'
# maxclients 10000
 
# 不要使用比設置的上限更多的內存。一旦內存使用達到上限,Redis會根據選定的回收策略(參見:maxmemmory-policy)刪除key。
# 如果因爲刪除策略Redis無法刪除key,或者策略設置爲 "noeviction",Redis會回覆需要更多內存的錯誤信息給命令。例如,SET,LPUSH等等,但是會繼續響應像Get這樣的只讀命令。
# 在使用Redis作爲LRU緩存,或者爲實例設置了硬性內存限制的時候(使用 "noeviction" 策略)的時候,這個選項通常事很有用的。
# 警告:當有多個slave連上達到內存上限時,master爲同步slave的輸出緩衝區所需內存不計算在使用內存中。這樣當移除key時,就不會因網絡問題 / 重新同步事件觸發移除key的循環,反過來slaves的輸出緩衝區充滿了key被移除的DEL命令,這將觸發刪除更多的key,直到這個數據庫完全被清空爲止。
# 總之,如果你需要附加多個slave,建議你設置一個稍小maxmemory限制,這樣系統就會有空閒的內存作爲slave的輸出緩存區(但是如果最大內存策略設置爲"noeviction"的話就沒必要了)
# maxmemory <bytes>
 
# 最大內存策略:如果達到內存限制了,Redis如何選擇刪除key。
# volatile-lru -> 根據LRU算法刪除設置過期時間的key
# allkeys-lru -> 根據LRU算法刪除任何key
# volatile-lfu -> 根據LFU算法刪除設置過期時間的key
# allkeys-lfu -> 根據LFU算法刪除任何key
# volatile-random -> 隨機移除設置過過期時間的key
# allkeys-random -> 隨機移除任何key
# volatile-ttl -> 移除即將過期的key(minor TTL)
# noeviction -> 不移除任何key,只返回一個寫錯誤
# 注意:對所有策略來說,如果Redis找不到合適的可以刪除的key都會在寫操作時返回一個錯誤。# 目前爲止涉及的命令: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
# 默認策略:
# maxmemory-policy noeviction
 
# LRU和最小TTL算法的實現都不是很精確,但是很接近(爲了省內存),所以你可以用樣本量做檢測。 例如:默認Redis會檢查3個key然後取最舊的那個,你可以通過下面的配置指令來設置樣本的個數。
# 默認值爲5,數字越大結果越精確但是會消耗更多CPU。
# 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
 
######################### APPEND ONLY MODE #########################
# 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
 
 
# 默認情況下,Redis是異步的把數據導出到磁盤上。這種模式在很多應用裏已經足夠好,但Redis進程出問題或斷電時可能造成一段時間的寫操作丟失(這取決於配置的save指令)。
# AOF是一種提供了更可靠的替代持久化模式,例如使用默認的數據寫入文件策略(參見後面的配置)。
# 在遇到像服務器斷電或單寫情況下Redis自身進程出問題但操作系統仍正常運行等突發事件時,Redis能只丟失1秒的寫操作。
# AOF和RDB持久化能同時啓動並且不會有問題。
# 如果AOF開啓,那麼在啓動時Redis將加載AOF文件,它更能保證數據的可靠性。
appendonly no
 
# AOF文件名(默認:"appendonly.aof")
appendfilename "appendonly.aof"
 
# fsync() 系統調用告訴操作系統把數據寫到磁盤上,而不是等更多的數據進入輸出緩衝區。
# 有些操作系統會真的把數據馬上刷到磁盤上;有些則會盡快去嘗試這麼做。
# Redis支持三種不同的模式:
# no:不要立刻刷,只有在操作系統需要刷的時候再刷。比較快。
# always:每次寫操作都立刻寫入到aof文件。慢,但是最安全。
# everysec:每秒寫一次。折中方案。
# 默認的 "everysec" 通常來說能在速度和數據安全性之間取得比較好的平衡。
# appendfsync always
appendfsync everysec
# appendfsync no
 
# 如果AOF的同步策略設置成 "always" 或者 "everysec",並且後臺的存儲進程(後臺存儲或寫入AOF 日誌)會產生很多磁盤I/O開銷。某些Linux的配置下會使Redis因爲 fsync()系統調用而阻塞很久。
# 注意,目前對這個情況還沒有完美修正,甚至不同線程的 fsync() 會阻塞我們同步的write(2)調用。
# 爲了緩解這個問題,可以用下面這個選項。它可以在 BGSAVE 或 BGREWRITEAOF 處理時阻止fsync()。
# 這就意味着如果有子進程在進行保存操作,那麼Redis就處於"不可同步"的狀態。
# 這實際上是說,在最差的情況下可能會丟掉30秒鐘的日誌數據。(默認Linux設定)
# 如果把這個設置成"yes"帶來了延遲問題,就保持"no",這是保存持久數據的最安全的方式。
no-appendfsync-on-rewrite no
 
# 自動重寫AOF文件。如果AOF日誌文件增大到指定百分比,Redis能夠通過 BGREWRITEAOF 自動重寫AOF日誌文件。# 工作原理:Redis記住上次重寫時AOF文件的大小(如果重啓後還沒有寫操作,就直接用啓動時的AOF大小)
# 這個基準大小和當前大小做比較。如果當前大小超過指定比例,就會觸發重寫操作。你還需要指定被重寫日誌的最小尺寸,這樣避免了達到指定百分比但尺寸仍然很小的情況還要重寫。
# 指定百分比爲0會禁用AOF自動重寫特性。
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
 
# 如果設置爲yes,如果一個因異常被截斷的AOF文件被redis啓動時加載進內存,redis將會發送日誌通知用戶。如果設置爲no,erdis將會拒絕啓動。此時需要用"redis-check-aof"工具修復文件。
aof-load-truncated yes
 
# [RDB file][AOF tail]
# 加載時Redis識別出AOF文件以“REDIS”開頭字符串,
# 並加載帶此前綴的RDB文件,然後繼續加載AOF
# 尾巴。
aof-use-rdb-preamble yes
######################### LUA腳本 #########################
 
# Lua 腳本的最大執行時間,毫秒爲單位
lua-time-limit 5000
 
######################### 集羣 #########################
 
# 只有開啓了以下選項,redis才能成爲集羣服務的一部分
# cluster-enabled yes
 
# 配置redis自動生成的集羣配置文件名。確保同一系統中運行的各redis實例該配置文件不要重名。
# cluster-config-file nodes-6379.conf
 
# 集羣節點超時毫秒數。超時的節點將被視爲不可用狀態。
# cluster-node-timeout 15000
 
# 如果數據太舊,集羣中的不可用master的slave節點會避免成爲備用master。如果slave和master失聯時間超過:(node-timeout * slave-validity-factor) + repl-ping-slave-period則不會被提升爲master。
# 如node-timeout爲30秒,slave-validity-factor爲10, 默認default repl-ping-slave-period爲10秒,失聯時間超過310秒slave就不會成爲master。
# 較大的slave-validity-factor值可能允許包含過舊數據的slave成爲master,同時較小的值可能會阻止集羣選舉出新master。
#爲了達到最大限度的高可用性,可以設置爲0,即slave不管和master失聯多久都可以提升爲master
# cluster-replica-validity-factor 10
 
# 只有在之前master有其它指定數量的工作狀態下的slave節點時,slave節點才能提升爲master。默認爲1(即該集羣至少有3個節點,1 master+2 slaves,master宕機,仍有另外1個slave的情況下其中1個slave可以提升)
# 測試環境可設置爲0,生成環境中至少設置爲1
# cluster-migration-barrier 1
 
# 默認情況下如果redis集羣如果檢測到至少有1個hash slot不可用,集羣將停止查詢數據。
# 如果所有slot恢復則集羣自動恢復。
# 如果需要集羣部分可用情況下仍可提供查詢服務,設置爲no。
# cluster-require-full-coverage yes
 
# 選項設置爲yes時,會阻止replicas嘗試對其master在主故障期間進行故障轉移
# 然而,master仍然可以執行手動故障轉移,如果強制這樣做的話。
# cluster-replica-no-failover no
 
########################## 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 two options are used for this scope, and are:
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-bus-port
#
# Each instruct the node about its address, client port, and cluster message
# bus port. The information is then published in the header of the bus packets
# so that other nodes will be able to correctly map the address of the node
# publishing the information.
#
# 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 usually.
#
# Example:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380
 
######################### 慢查詢日誌 #########################
 
# 慢查詢日誌,記錄超過多少微秒的查詢命令。查詢的執行時間不包括客戶端的IO執行和網絡通信時間,只是查詢命令執行時間。
# 1000000等於1秒,設置爲0則記錄所有命令
slowlog-log-slower-than 10000
 
# 記錄大小,可通過SLOWLOG RESET命令重置
slowlog-max-len 128
 
 
 
######################### LATENCY MONITOR #########################
# redis延時監控系統在運行時會採樣一些操作,以便收集可能導致延時的數據根源。
# 通過 LATENCY命令 可以打印一些圖樣和獲取一些報告,方便監控
# 這個系統僅僅記錄那個執行時間大於或等於預定時間(毫秒)的操作,
# 這個預定時間是通過latency-monitor-threshold配置來指定的,
# 當設置爲0時,這個監控系統處於停止狀態
latency-monitor-threshold 0
 
 
######################### 事件通知 #########################
# K 	鍵空間通知,所有通知以 __keyspace@<db>__ 爲前綴
# E 	鍵事件通知,所有通知以 __keyevent@<db>__ 爲前綴
# g 	DEL 、 EXPIRE 、 RENAME 等類型無關的通用命令的通知
# $ 	字符串命令的通知
# l 	列表命令的通知
# s 	集合命令的通知
# h 	哈希命令的通知
# z 	有序集合命令的通知
# x 	過期事件:每當有過期鍵被刪除時發送
# e 	驅逐(evict)事件:每當有鍵因爲 maxmemory 政策而被刪除時發送
# A 	參數 g$lshzxe 的別名
#  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
# Redis能通知 Pub/Sub 客戶端關於鍵空間發生的事件,默認關閉
notify-keyspace-events ""
 
############################### ADVANCED CONFIG ###############################
 
# 當hash只有少量的entry時,並且最大的entry所佔空間沒有超過指定的限制時,會用一種節省內存的
# 數據結構來編碼。可以通過下面的指令來設定限制
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
 
 
# 當取正值的時候,表示按照數據項個數來限定每個quicklist節點上的ziplist長度。比如,當這個參數配置
# 成5的時候,表示每個quicklist節點的ziplist最多包含5個數據項。
# 當取負值的時候,表示按照佔用字節數來限定每個quicklist節點上的ziplist長度。這時,它只能取-1到-5
# 這五個值,每個值含義如下:
#    -5: 每個quicklist節點上的ziplist大小不能超過64 Kb。(注:1kb => 1024 bytes)
#    -4: 每個quicklist節點上的ziplist大小不能超過32 Kb。
#    -3: 每個quicklist節點上的ziplist大小不能超過16 Kb。
#    -2: 每個quicklist節點上的ziplist大小不能超過8 Kb。(-2是Redis給出的默認值)
#    -1: 每個quicklist節點上的ziplist大小不能超過4 Kb。
list-max-ziplist-size -2
 
# 這個參數表示一個quicklist兩端不被壓縮的節點個數。
# 注:這裏的節點個數是指quicklist雙向鏈表的節點個數,而不是指ziplist裏面的數據項個數。
# 實際上,一個quicklist節點上的ziplist,如果被壓縮,就是整體被壓縮的。
# 參數list-compress-depth的取值含義如下:
#    0: 是個特殊值,表示都不壓縮。這是Redis的默認值。
#    1: 表示quicklist兩端各有1個節點不壓縮,中間的節點壓縮。
#    2: 表示quicklist兩端各有2個節點不壓縮,中間的節點壓縮。
#    3: 表示quicklist兩端各有3個節點不壓縮,中間的節點壓縮。
#    依此類推…
# 由於0是個特殊值,很容易看出quicklist的頭節點和尾節點總是不被壓縮的,以便於在表的兩端進行快速存取。
list-compress-depth 0
 
 
# set有一種特殊編碼的情況:當set數據全是十進制64位有符號整型數字構成的字符串時。
# 下面這個配置項就是用來設置set使用這種編碼來節省內存的最大長度。
set-max-intset-entries 512
 
# 與hash和list相似,有序集合也可以用一種特別的編碼方式來節省大量空間。
# 這種編碼只適合長度和元素都小於下面限制的有序集合
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
 
# HyperLogLog稀疏結構表示字節的限制。該限制包括
# 16個字節的頭。當HyperLogLog使用稀疏結構表示
# 這些限制,它會被轉換成密度表示。
# 值大於16000是完全沒用的,因爲在該點
# 密集的表示是更多的內存效率。
# 建議值是3000左右,以便具有的內存好處, 減少內存的消耗
hll-sparse-max-bytes 3000
 
# Streams宏節點最大大小/項目。 流數據結構是基數編碼內部多個項目的大節點樹。 使用此配置
# 可以配置單個節點的字節數,以及切換到新節點之前可能包含的最大項目數
# 追加新的流條目。 如果以下任何設置設置爲0,忽略限制,因此例如可以設置一個
# 大入口限制將max-bytes設置爲0,將max-entries設置爲所需的值
stream-node-max-bytes 4096
stream-node-max-entries 100
 
# 啓用哈希刷新,每100個CPU毫秒會拿出1個毫秒來刷新Redis的主哈希表(頂級鍵值映射表)
activerehashing yes
 
# 客戶端的輸出緩衝區的限制,可用於強制斷開那些因爲某種原因從服務器讀取數據的速度不夠快的客戶端
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
 
# 客戶端查詢緩衝區累積新命令。 它們僅限於固定的默認情況下,
# 多數情況下爲了避免協議不同步導致客戶端查詢緩衝區中未綁定的內存使用量的錯誤
# 但是,如果你有使用的話,你可以在這裏配置它,比如我們有很多執行請求或類似的。
# client-query-buffer-limit 1gb
 
# 在Redis協議中,批量請求,即表示單個的元素strings,通常限制爲512 MB。
# 但是,您可以z更改此限制
# proto-max-bulk-len 512mb
 
# 默認情況下,“hz”的被設定爲10。提高該值將在Redis空閒時使用更多的CPU時,但同時當有多個key
# 同時到期會使Redis的反應更靈敏,以及超時可以更精確地處理
hz 10
 
# Normally it is useful to have an HZ value which is proportional to the
# number of clients connected. This is useful in order, for instance, to
# avoid too many clients are processed for each background task invocation
# in order to avoid latency spikes.
#
# Since the default HZ value by default is conservatively set to 10, Redis
# offers, and enables by default, the ability to use an adaptive HZ value
# which will temporary raise when there are many connected clients.
#
# When dynamic HZ is enabled, the actual configured HZ will be used as
# as a baseline, but multiples of the configured HZ value will be actually
# used as needed once more clients are connected. In this way an idle
# instance will use very little CPU time while a busy instance will be
# more responsive.
dynamic-hz yes
 
# 當一個子進程重寫AOF文件時,如果啓用下面的選項,則文件每生成32M數據會被同步
aof-rewrite-incremental-fsync yes
 
 
# 當redis保存RDB文件時,如果啓用了以下選項,每生成32 MB數據,文件將被fsync-ed。 
# 這很有用,以便以遞增方式將文件提交到磁盤並避免大延遲峯值。
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
 
########################### ACTIVE DEFRAGMENTATION #######################
 
# 啓用主動碎片整理
# activedefrag yes
 
# 啓動活動碎片整理的最小碎片浪費量
# active-defrag-ignore-bytes 100mb
 
# 啓動碎片整理的最小碎片百分比
# active-defrag-threshold-lower 10
 
# 使用最大消耗時的最大碎片百分比
# active-defrag-threshold-upper 100
 
# 在CPU百分比中進行碎片整理的最小消耗
# active-defrag-cycle-min 5
 
# 磁盤碎片整理的最大消耗
# active-defrag-cycle-max 75
 
# 將從主字典掃描處理的最大set / hash / zset / list字段數
# active-defrag-max-scan-fields 1000
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章