1. 程式人生 > >Redis配置檔案最詳細解讀

Redis配置檔案最詳細解讀

         之前在網上查詢過好多關於redis的配置檔案講解,但是上面的文章大多講解都不太詳細,在這裡,我個人總結了一下,如有不對或不全的還請各位大神指導。

# Redis配置檔案樣例

# Note on units: when memory size is needed, it is possible to specifiy # it in the usual form of 1k 5GB 4M and so forth:

#當你需要為某個配置項指定記憶體大小的時候,必須要帶上單位,通常的格式就是 1k 5gb 4m 等:

# # 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預設不是以守護程序的方式執行,可以通過該配置項修改,使用yes啟用守護程序 # 啟用守護程序後,Redis會把pid寫到一個pidfile中,在/var/run/redis.pid檔案裡面。 daemonize no

# 3.2裡的引數,是否開啟保護模式,預設開啟。要是配置裡沒有指定bind和密碼。開啟該引數後,redis只會本地進行訪問,拒絕外部訪問。要是開啟了密碼 和bind,可以開啟。否 則最好關閉,設定為no。

# protected-mode yes

# 當Redis以守護程序方式執行時,Redis預設會把pid寫入/var/run/redis.pid檔案,可以通過pidfile指定

# 但是你可以在這裡自己制定它的檔案位置。 pidfile /var/run/redis.pid

# 指定Redis監聽埠,預設埠為6379 # 如果指定0埠,表示Redis將不在 socket 上監聽任何客戶端連線

port 6379

# 繫結的主機地址 # 你可以繫結單一介面,如果沒有繫結,所有介面都會監聽到來的連線

#  預設情況下,redis 在 server 上所有有效的網路介面上監聽客戶端連線(就是注掉)。

# 你如果只想讓它在一個網路介面上監聽,那你就繫結一個IP或者多個IP,其他IP的訪問就會被拒絕。 # bind 127.0.0.1

# 示例,多個IP用空格隔開:

# bind 192.168.1.110  10.99.49.248

# Specify the path for the unix socket that will be used to listen for # incoming connections. There is no default, so Redis will not listen # on a unix socket when not specified.

# 指定 unix socket 的路徑

#  # unixsocket /tmp/redis.sock # unixsocketperm 755

#指定在一個 client 空閒多少秒之後關閉連線,如果指定為0,表示關閉該功能

timeout 0

# TCP 監聽的最大容納數量

# 此引數確定了TCP連線中已完成佇列(完成三次握手之後)的長度, 當然此值必須不大於Linux系統定義的/proc/sys/net/core/somaxconn值,預設是511,而Linux的預設引數值是128。當系統併發量大並且客戶端速度緩慢的時候,可以將這二個引數一起參考設定。該核心引數預設值一般是128,對於負載很大的服務程式來說大大的不夠。一般會將它修改為2048或者更大。在/etc/sysctl.conf中新增:net.core.somaxconn = 2048,然後在終端中執行sysctl -p。 所以你要修改這兩個值才能達到你的預期。

#  tcp-backlog 511

#  tcp 心跳包。如果設定不為0,就使用配置tcp的SO_KEEPALIVE值,使用keepalive有兩個好處:檢測掛掉的對端。降低中間裝置出問題而導致網路看似連線卻已經與對端埠的問題。在Linux核心中,設定了keepalive,redis會定時給對端傳送ack。檢測到對端關閉需要兩倍的設定值。

# 這個之所有有用,主要由兩個原因:

# 1) 防止死的 peers

# 2) Take the connection alive from the point of view of network equipment in the middle.

#  推薦一個合理的值就是60秒

# tcp-keepalive 0

# 指定日誌記錄級別,Redis總共支援四個級別:debug、verbose、notice、warning,預設為verbose # debug (很多資訊, 對開發/測試比較有用) # verbose (許多很少有用的資訊,但不會像除錯級別那樣混亂) # notice (適用於生產環境) # warning (僅僅一些重要的訊息被記錄) loglevel verbose

# 日誌記錄方式,預設為標準輸出,如果配置為redis為守護程序方式執行,而這裡又配置為標準輸出,則日誌將會發送給/dev/null logfile stdout

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

# 要想把日誌記錄到系統日誌,就把它改成 yes,也可以可選擇性的更新其他的syslog 引數以達到你的要求

# syslog-enabled no

# Specify the syslog identity.

# 設定 syslog 的 identity。

# syslog-ident redis

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

# 設定 syslog 的 facility,必須是 USER 或者是 LOCAL0-LOCAL7 之間的值

# syslog-facility local0

# 設定資料庫的數目。

# 預設資料庫為 DB 0,你可以在每個連線上使用 select <dbid> 命令選擇一個不同的資料庫id # 但是 dbid 必須是一個介於 0 到 databasees - 1 之間的值

databases 16

################################ SNAPSHOTTING  ################################# # 指定在多長時間內,有多少次更新操作,就將資料同步到資料檔案,可以多個條件配合 # Save the DB on disk: # #   save <seconds> <changes> # #   Will save the DB if both the given number of seconds and the given #   number of write operations against the DB occurred. #

# 存 DB 到磁碟:

#

# 格式:save <間隔時間(秒)> <寫入次數> #

# 根據給定的時間間隔和寫入次數將資料儲存到磁碟

#

# 下面的例子的意思是:

# 900 秒內如果至少有 1 個 key 的值變化,則儲存

# 300 秒內如果至少有 10 個 key 的值變化,則儲存

# 60 秒內如果至少有 10000 個 key 的值變化,則儲存

#  

# 注意:你可以註釋掉所有的 save 行來停用儲存功能。

# 也可以直接一個空字串來實現停用: save  ""

save 900 1 save 300 10 save 60 10000

# 預設情況下,如果 redis 最後一次的後臺儲存失敗,redis 將停止接受寫操作,

#  這樣以一種強硬的方式讓使用者知道資料不能正確的持久化到磁碟,否則就會沒人注意到災難的發生。

# 如果後臺儲存程序重新啟動工作了,redis 也將自動的允許寫操作。

# 然而你要是安裝了靠譜的監控,你可能不希望 redis 這樣做,那你就改成 no 好了。

# stop-writes-on-bgsave-error yes

#是否校驗rdb檔案。從rdb格式的第五個版本開始,在rdb檔案的末尾會帶上CRC64的校驗和。這跟有利於檔案的容錯性,但是在儲存rdb檔案的時候,會有大概10%的效能損耗,所以如果你追求高效能,可以關閉該配置。

#rdbchecksum yes

# 指定儲存至本地資料庫時是否壓縮資料,預設為yes,Redis採用LZF壓縮,如果為了節省CPU時間,可以關閉該選項,但會導致資料庫檔案變的巨大 rdbcompression yes

# 指定本地資料庫檔名,預設值為dump.rdb dbfilename dump.rdb

# 工作目錄. # 指定本地資料庫存放目錄,檔名由上面dbfilename配置項指定 #  # Also the Append Only File will be created inside this directory. #  # 注意,這裡只能指定一個目錄,不能指定檔名 dir ./

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

# 主從複製。使用slaveof從 Redis伺服器來讓一個 redis 例項成為另一個reids 例項的副本。注意,該配置僅限於當前slave有效 # so for example it is possible to configure the slave to save the DB with a # different interval, or to listen to another port, and so on. # 設定當本機為slav服務時,設定master服務的ip地址及埠,在Redis啟動時,它會自動從master進行資料同步 # slaveof <masterip> <masterport>

# 當master服務設定了密碼保護時,slav服務連線master的密碼 # 下文的“requirepass”配置項可以指定密碼 # masterauth <master-password>

# When a slave lost the connection with the master, or when the replication # is still in progress, the slave can act in two different ways: # # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will #    still reply to client requests, possibly with out of data data, or the #    data set may just be empty if this is the first synchronization. # # 2) if slave-serve-stale data is set to 'no' the slave will reply with #    an error "SYNC with master in progress" to all the kind of commands #    but to INFO and SLAVEOF. #

# 當一個 slave 與 master 失去聯絡,或者複製正在進行的時候,slave 可能會有兩種表現:

# 1) 如果為 yes ,slave 仍然會應答客戶端請求,但返回的資料可能是過時,或者資料可能是空的在第一次同步的時候

# 2) 如果為 no ,在你執行除了 info he salveof 之外的其他命令時,slave 都將返回一個 "SYNC with master in progress" 的錯誤

slave-serve-stale-data yes

# 你可以配置一個 slave 實體是否接受寫入操作。

# 通過寫入操作來儲存一些短暫的資料對於一個 slave 例項來說可能是有用的,

# 因為相對從 master 重新同步數而言,據資料寫入到 slave 會更容易被刪除。

# 但是如果客戶端因為一個錯誤的配置寫入,也可能會導致一些問題。

# 從 redis 2.6 版起,預設 slaves 都是隻讀的

# 注意:只讀的 slaves 沒有被設計成在 internet 上暴露給不受信任的客戶端。

# 它僅僅是一個針對誤用例項的一個保護層。

# slave-read-only yes

# 是否使用socket方式複製資料。目前redis複製提供兩種方式,disk和socket。如果新的slave連上來或者重連的slave無法部分同步,就會執行全量同步,master會生成rdb檔案。有2種方式:disk方式是master建立一個新的程序把rdb檔案儲存到磁碟,再把磁碟上的rdb檔案傳遞給slave。socket是master建立一個新的程序,直接把rdb檔案以socket的方式發給slave。disk方式的時候,當一個rdb儲存的過程中,多個slave都能共享這個rdb檔案。socket的方式就的一個個slave順序複製。在磁碟速度緩慢,網速快的情況下推薦用socket方式。

repl-diskless-sync no

# diskless複製的延遲時間,防止設定為0。一旦複製開始,節點不會再接收新slave的複製請求直到下一個rdb傳輸。所以最好等待一段時間,等更多的slave連上來。

repl-diskless-sync-delay 5

# Slaves send PINGs to server in a predefined interval. It's possible to change # this interval with the repl_ping_slave_period option. The default value is 10 # seconds. #

# Slaves 在一個預定義的時間間隔內傳送 ping 命令到 server 。你可以改變這個時間間隔。預設為 10 秒。

# repl-ping-slave-period 10

# The following option sets a timeout for both Bulk transfer I/O timeout and # master data or ping response timeout. The default value is 60 seconds. # # It is important to make sure that this value is greater than the value # specified for repl-ping-slave-period otherwise a timeout will be detected # every time there is low traffic between the master and the slave. #

# 設定主從複製過期時間,這個值一定要比 repl-ping-slave-period 大

# repl-timeout 60

# 是否禁止複製tcp連結的tcp nodelay引數,可傳遞yes或者no。預設是no,即使用tcp nodelay。如果master設定了yes來禁止tcp nodelay設定,在把資料複製給slave的時候,會減少包的數量和更小的網路頻寬。但是這也可能帶來資料的延遲。預設我們推薦更小的延遲,但是在資料量傳輸很大的場景下,建議選擇yes。

# repl-disable-tcp-nodelay no

#

# 設定主從複製容量大小。這是一個環形複製緩衝區,用來儲存最新複製的命令。這樣在slave離線的時候,不需要完全複製master的資料,如果可以執行部分同步,只需要把緩衝區的部分資料複製給slave,就能恢復正常複製狀態。緩衝區的大小越大,slave離線的時間可以更長,複製緩衝區只有在有slave連線的時候才分配記憶體。沒有slave的一段時間,記憶體會被釋放出來,預設1m。

# repl-backlog-size 1mb

# 在某些時候,master 不再連線 slaves,backlog 將被釋放。如果設定為 0 ,意味著絕不釋放 backlog 。

# repl-backlog-ttl 3600

# 當 master 不能正常工作的時候,Redis Sentinel 會從 slaves 中選出一個新的 master,

# 這個值越小,就越會被優先選中,但是如果是 0 , 那是意味著這個 slave 不可能被選中。預設優先順序為 100。

# slave-priority 100

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

# Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. # 設定Redis連線密碼,如果配置了連線密碼,客戶端在連線Redis時需要通過auth <password>命令提供密碼,預設關閉 # requirepass foobared

# 設定成一個空的值,可以禁止一個命令

# rename-command CONFIG ""

# Command renaming. # # It is possilbe to change the name of dangerous commands in a shared # environment. For instance the CONFIG command may be renamed into something # of hard to guess so that it will be still available for internal-use # tools but not available for general clients. # # Example: # # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 # # It is also possilbe to completely kill a command renaming it into # an empty string: # # rename-command CONFIG ""

################################### LIMITS ####################################

# 設定同一時間最大客戶端連線數,預設無限制,Redis可以同時開啟的客戶端連線數為Redis程序可以開啟的最大檔案描述符數, # 如果設定maxclients 0,表示不作限制。當客戶端連線數到達限制時,Redis會關閉新的連線並向客戶端返回max Number of clients #reached錯誤資訊 # maxclients 128

# 如果你設定了這個值,當快取的資料容量達到這個值, redis 將根據你選擇的eviction 策略來移除一些 keys。

# 如果 redis 不能根據策略移除 keys ,或者是策略被設定為 ‘noeviction’,redis 將開始響應錯誤給命令,如 set,lpush 等等,

# 並繼續響應只讀的命令,如 get

# Don't use more memory than the specified amount of bytes. # When the memory limit is reached Redis will try to remove keys with an # EXPIRE set. It will try to start freeing keys that are going to expire # in little time and preserve keys with a longer time to live. # Redis will also try to remove objects from free lists if possible. # # If all this fails, Redis will start to reply with errors to commands # that will use more memory, like SET, LPUSH, and so on, and will continue # to reply to most read-only commands like GET. # # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a # 'state' server or cache, not as a real DB. When Redis is used as a real # database the memory usage will grow over the weeks, it will be obvious if # it is going to use too much memory in the long run, and you'll have the time # to upgrade. With maxmemory after the limit is reached you'll start to get # errors for write operations, and this may even lead to DB inconsistency. # 指定Redis最大記憶體限制,Redis在啟動時會把資料載入到記憶體中,達到最大記憶體後,Redis會先嚐試清除已到期或即將到期的Key, # 當此方法處理後,仍然到達最大記憶體設定,將無法再進行寫入操作,但仍然可以進行讀取操作。 # Redis新的vm機制,會把Key存放記憶體,Value會存放在swap區 # maxmemory <bytes>

# 最大記憶體策略,你有 5 個選擇。

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory # is reached? You can select among five behavior: #  # volatile-lru -> remove the key with an expire set using an LRU algorithm

# volatile-lru -> 使用 LRU 演算法移除包含過期設定的 key 。 # allkeys-lru -> remove any key accordingly to the LRU algorithm

# allkeys-lru -> 根據 LRU 演算法移除所有的 key 。 # volatile-random -> remove a random key with an expire set # allkeys->random -> remove a random key, any key # volatile-ttl -> remove the key with the nearest expire time (minor TTL) # noeviction -> don't expire at all, just return an error on write operations

# noeviction -> 不讓任何 key 過期,只是給寫入操作返回一個錯誤 #  # Note: with all the kind of policies, Redis will return an error on write #       operations, when there are not suitable keys for eviction. # #       At the date of writing this 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 volatile-lru

# LRU and minimal TTL algorithms are not precise algorithms but approximated # algorithms (in order to save memory), so you can select as well the sample # size to check. For instance for default Redis will check three keys and # pick the one that was used less recently, you can change the sample size # using the following configuration directive. #

#lru檢測的樣本數。使用lru或者ttl淘汰演算法,從需要淘汰的列表中隨機選擇sample個key,選出閒置時間最長的key移除。

# maxmemory-samples 3

############################## APPEND ONLY MODE ###############################

#  # Note that you can have both the async dumps and the append only file if you # like (you have to comment the "save" statements above to disable the dumps). # Still if append only mode is enabled Redis will load the data from the # log file at startup ignoring the dump.rdb file.

預設redis使用的是rdb方式持久化,這種方式在許多應用中已經足夠用了。但是redis如果中途宕機,會導致可能有幾分鐘的資料丟失,根據save來策略進行持久化,Append Only File是另一種持久化方式,可以提供更好的持久化特性。Redis會把每次寫入的資料在接收後都寫入 appendonly.aof 檔案,每次啟動時Redis都會先把這個檔案的資料讀入記憶體裡,先忽略RDB檔案。

# 指定是否在每次更新操作後進行日誌記錄,預設redis使用的是rdb方式持久化,這種方式在許多應用中已經足夠用了。但是redis如果中途宕機,會導致可能有幾分鐘的資料丟失,根據save來策略進行持久化,Append Only File是另一種持久化方式,可以提供更好的持久化特性。Redis會把每次寫入的資料在接收後都寫入 appendonly.aof 檔案,每次啟動時Redis都會先把這個檔案的資料讀入記憶體裡,先忽略RDB檔案。如果不開啟,可能會在斷電時導致一段時間內的資料丟失。 # 因為redis本身同步資料檔案是按上面save條件來同步的,所以有的資料會在一段時間內只存在於記憶體中。預設為no # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append # log file in background when it gets too big.

appendonly no

# 指定更新日誌檔名,預設為appendonly.aof # appendfilename appendonly.aof

# The fsync() call tells the Operating System to actually write data on disk # instead to wait 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.

# 指定更新日誌條件,共有3個可選值: # no:表示等作業系統進行資料快取同步到磁碟(快) # always:表示每次更新操作後手動呼叫fsync()將資料寫到磁碟(慢,安全) # everysec:表示每秒同步一次(折衷,預設值)

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 none", that in pratical terms means that it is # possible to lost 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.

#在aof重寫或者寫入rdb檔案的時候,會執行大量IO,此時對於everysec和always的aof模式來說,執行fsync會造成阻塞過長時間,no-appendfsync-on-rewrite欄位設定為預設設定為no。如果對延遲要求很高的應用,這個欄位可以設定為yes,否則還是設定為no,這樣對持久化特性來說這是更安全的選擇。設定為yes表示rewrite期間對新寫操作不fsync,暫時存在記憶體中,等rewrite完成後再寫入,預設為no,建議yes。Linux的預設fsync策略是30秒。可能丟失30秒資料。

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 will growth by the specified percentage. #  # This is how it works: Redis remembers the size of the AOF file after the # latest rewrite (or if no rewrite 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 precentage of zero in order to disable the automatic AOF # rewrite feature.

#aof自動重寫配置。當目前aof檔案大小超過上一次重寫的aof檔案大小的百分之多少進行重寫,即當aof檔案增長到一定大小的時候Redis能夠呼叫bgrewriteaof對日誌檔案進行重寫。當前AOF檔案大小是上次日誌重寫得到AOF檔案大小的二倍(設定為100)時,自動啟動新的日誌重寫過程。

auto-aof-rewrite-percentage 100

#設定允許重寫的最小aof檔案大小,避免了達到約定百分比但尺寸仍然很小的情況還要重寫

auto-aof-rewrite-min-size 64mb

# aof檔案可能在尾部是不完整的,當redis啟動的時候,aof檔案的資料被載入記憶體。重啟可能發生在redis所在的主機作業系統宕機後,尤其在ext4檔案系統沒有加上data=ordered選項(redis宕機或者異常終止不會造成尾部不完整現象。)出現這種現象,可以選擇讓redis退出,或者匯入儘可能多的資料。如果選擇的是yes,當截斷的aof檔案被匯入的時候,會自動釋出一個log給客戶端然後load。如果是no,使用者必須手動redis-check-aof修復AOF檔案才可以。

# aof-load-truncated yes

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

#slog log是用來記錄redis執行中執行比較慢的命令耗時。當命令的執行超過了指定時間,就記錄在slow log中,slog log儲存在記憶體中,所以沒有IO操作。 #執行時間比slowlog-log-slower-than大的請求記錄到slowlog裡面,單位是微秒,所以1000000就是1秒。注意,負數時間會禁用慢查詢日誌,而0則會強制記錄所有命令。

slowlog-log-slower-than 10000

# There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET.

#慢查詢日誌長度。當一個新的命令被寫進日誌的時候,最老的那個記錄會被刪掉。這個長度沒有限制。只要有足夠的記憶體就行。你可以通過 SLOWLOG RESET 來釋放記憶體。

slowlog-max-len 1024

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

#延遲監控功能是用來監控redis中執行比較緩慢的一些操作,用LATENCY列印redis例項在跑命令時的耗時圖表。只記錄大於等於下邊設定的值的操作。0的話,就是關閉監視。預設延遲監控功能是關閉的,如果你需要開啟,也可以通過CONFIG SET命令動態設定。 l

# atency-monitor-threshold 0

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

#鍵空間通知使得客戶端可以通過訂閱頻道或模式,來接收那些以某種方式改動了 Redis 資料集的事件。因為開啟鍵空間通知功能需要消耗一些 CPU ,所以在預設配置下,該功能處於關閉狀態。

#notify-keyspace-events 的引數可以是以下字元的任意組合,它指定了伺服器該傳送哪些型別的通知:

##K 鍵空間通知,所有通知以 [email protected]__ 為字首 ##E 鍵事件通知,所有通知以 [email protected]__ 為字首

##g DEL 、 EXPIRE 、 RENAME 等型別無關的通用命令的通知

##$ 字串命令的通知 ##l 列表命令的通知 ##s 集合命令的通知

##h 雜湊命令的通知 ##z 有序集合命令的通知

##x 過期事件:每當有過期鍵被刪除時傳送

##e 驅逐(evict)事件:每當有鍵因為 maxmemory 政策而被刪除時傳送

##A 引數 g$lshzxe 的別名 #輸入的引數中至少要有一個 K 或者 E,否則的話,不管其餘的引數是什麼,都不會有任何 通知被分發。詳細使用可以參考http://redis.io/topics/notifications

# notify-keyspace-events ""

################################ VIRTUAL MEMORY ###############################

### WARNING! Virtual Memory is deprecated in Redis 2.4 ### The use of Virtual Memory is strongly discouraged.

### WARNING! Virtual Memory is deprecated in Redis 2.4 ### The use of Virtual Memory is strongly discouraged.

# Virtual Memory allows Redis to work with datasets bigger than the actual # amount of RAM needed to hold the whole dataset in memory. # In order to do so very used keys are taken in memory while the other keys # are swapped into a swap file, similarly to what operating systems do # with memory pages. # 指定是否啟用虛擬記憶體機制,預設值為no, # VM機制將資料分頁存放,由Redis將訪問量較少的頁即冷資料swap到磁碟上,訪問多的頁面由磁碟自動換出到記憶體中 # 把vm-enabled設定為yes,根據需要設定好接下來的三個VM引數,就可以啟動VM了 vm-enabled no # vm-enabled yes

# This is the path of the Redis swap file. As you can guess, swap files # can't be shared by different Redis instances, so make sure to use a swap # file for every redis process you are running. Redis will complain if the # swap file is already in use. # # Redis交換檔案最好的儲存是SSD(固態硬碟) # 虛擬記憶體檔案路徑,預設值為/tmp/redis.swap,不可多個Redis例項共享 # *** WARNING *** if you are using a shared hosting the default of putting # the swap file under /tmp is not secure. Create a dir with access granted # only to Redis user and configure Redis to create the swap file there. vm-swap-file /tmp/redis.swap

# With vm-max-memory 0 the system will swap everything it can. Not a good # default, just specify the max amount of RAM you can in bytes, but it's # better to leave some margin. For instance specify an amount of RAM # that's more or less between 60 and 80% of your free RAM. # 將所有大於vm-max-memory的資料存入虛擬記憶體,無論vm-max-memory設定多少,所有索引資料都是記憶體儲存的(Redis的索引資料就是keys) # 也就是說當vm-max-memory設定為0的時候,其實是所有value都存在於磁碟。預設值為0 vm-max-memory 0

# Redis swap檔案分成了很多的page,一個物件可以儲存在多個page上面,但一個page上不能被多個物件共享,vm-page-size是要根據儲存的資料大小來設定的。 # 建議如果儲存很多小物件,page大小最後設定為32或64bytes;如果儲存很大的物件,則可以使用更大的page,如果不確定,就使用預設值 vm-page-size 32

# 設定swap檔案中的page數量由於頁表(一種表示頁面空閒或使用的bitmap)是存放在記憶體中的,在磁碟上每8個pages將消耗1byte的記憶體 # swap空間總容量為 vm-page-size * vm-pages # # With the default of 32-bytes memory pages and 134217728 pages Redis will # use a 4 GB swap file, that will use 16 MB of RAM for the page table. # # It's better to use the smallest acceptable value for your application, # but the default is large in order to work in most conditions. vm-pages 134217728

# Max number of VM I/O threads running at the same time. # This threads are used to read/write data from/to swap file, since they # also encode and decode objects from disk to memory or the reverse, a bigger # number of threads can help with big objects even if they can't help with # I/O itself as the physical device may not be able to couple with many # reads/writes operations at the same time. # 設定訪問swap檔案的I/O執行緒數,最後不要超過機器的核數,如果設定為0,那麼所有對swap檔案的操作都是序列的,可能會造成比較長時間的延遲,預設值為4 vm-max-threads 4

############################### ADVANCED CONFIG ###############################

# 資料量小於等於hash-max-ziplist-entries的用ziplist,大於hash-max-ziplist-entries用hash

hash-max-ziplist-entries 512

# value大小小於等於hash-max-ziplist-value的用ziplist,大於hash-max-ziplist-value用hash。

hash-max-ziplist-value 64

# 資料量小於等於list-max-ziplist-entries用ziplist,大於list-max-ziplist-entries用list。

list-max-ziplist-entries 512

# value大小小於等於list-max-ziplist-value的用ziplist,大於list-max-ziplist-value用list。

list-max-ziplist-value 64

# 資料量小於等於set-max-intset-entries用iniset,大於set-max-intset-entries用set。

set-max-intset-entries 512

# 資料量小於等於zset-max-ziplist-entries用ziplist,大於zset-max-ziplist-entries用zset。

zset-max-ziplist-entries 128

# value大小小於等於zset-max-ziplist-value用ziplist,大於zset-max-ziplist-value用zset。

zset-max-ziplist-value 64

# value大小小於等於hll-sparse-max-bytes使用稀疏資料結構(sparse),大於hll-sparse-max-bytes使用稠密的資料結構(dense)。一個比16000大的value是幾乎沒用的,建議的value大概為3000。如果對CPU要求不高,對空間要求較高的,建議設定到10000左右。

hll-sparse-max-bytes 3000

# Redis將在每100毫秒時使用1毫秒的CPU時間來對redis的hash表進行重新hash,可以降低記憶體的使用。當你的使用場景中,有非常嚴格的實時性需要,不能夠接受Redis時不時的對請求有2毫秒的延遲的話,把這項配置為no。如果沒有這麼嚴格的實時性要求,可以設定為yes,以便能夠儘可能快的釋放記憶體。

activerehashing yes

# 對客戶端輸出緩衝進行限制可以強迫那些不從伺服器讀取資料的客戶端斷開連線,用來強制關閉傳輸緩慢的客戶端。 #對於normal client,第一個0表示取消hard limit,第二個0和第三個0表示取消soft limit,normal client預設取消限制,因為如果沒有尋問,他們是不會接收資料的。

client-output-buffer-limit normal 0 0 0

# 對於slave client和MONITER client,如果client-output-buffer一旦超過256mb,又或者超過64mb持續60秒,那麼伺服器就會立即斷開客戶端連線。

client-output-buffer-limit slave 256mb 64mb 60

# 對於pubsub client,如果client-output-buffer一旦超過32mb,又或者超過8mb持續60秒,那麼伺服器就會立即斷開客戶端連線。

client-output-buffer-limit pubsub 32mb 8mb 60

# redis執行任務的頻率為1s除以hz。

hz 10

# 在aof重寫的時候,如果打開了aof-rewrite-incremental-fsync開關,系統會每32MB執行一次fsync。這對於把檔案寫入磁碟是有幫助的,可以避免過大的延遲峰值。

aof-rewrite-incremental-fsync yes

################################## INCLUDES ###################################

# 假如說你有一個可用於所有的 redis server 的標準配置模板,

# 但針對某些 server 又需要一些個性化的設定,

# 你可以使用 include 來包含一些其他的配置檔案,這對你來說是非常有用的。

# 但是要注意哦,include 是不能被 config rewrite 命令改寫的

# 由於 redis 總是以最後的加工線作為一個配置指令值,所以你最好是把 include 放在這個檔案的最前面,

# 以避免在執行時覆蓋配置的改變,相反,你就把它放在後面。

# 指定包含其他的配置檔案,可以在同一主機上多個Redis例項之間使用同一份配置檔案,而同時各例項又擁有自己的特定配置檔案 # include /path/to/local.conf # include /path/to/other.conf