redis配置詳解(中英文)

V2.8.21: (中英字幕同步)html

# Redis configuration file example
#* Redis
配置文件例子

node

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

#
注意內存單位: 當使用內存大小的限制須要設置時, 在這裏能夠設置它的大小格式
#
例如: 1k 5GB 4M 等等都是能夠的:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
#
單位不區分大小寫所以 so 1GB 1Gb 1gB 都是同樣的.

################################## 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.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf

#
要包含其餘額外的配置文件在這裏設置. 這個設置對於有本身的redis標準配置模板頗有用
#
#
本身聲明的配置文件不會被命令"CONFIG REWRITE"重寫
# redis
使用最後一個配置文件做爲重寫的文件,若是不行被重寫,
#
那麼請放在前面聲明本身的配置文件
#
最後一行的配置就會被重寫
#
# include /path/to/local.conf
# include /path/to/other.conf


################################ 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.
#
默認狀況下Redis不是運行在守護進程的模式. 若是你須要運行在守護進程的模式,請設置爲'yes'.
#
當運行在守護進程模式,則會寫到一個pid文件: /var/run/redis.pid.

daemonize no

# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
#
當運行在守護進程模式,Redis會默認寫到/var/run/redis.pid
#
你能夠在這裏設置修改
pidfile /var/run/redis.pid

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
# Redis
監聽端口來接收鏈接,默認端口是 6379
#
若是端口是0, Redis不會監聽TCP socket
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections 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.

#
在高併發環境下你須要一個高backlog值來避免慢客戶端鏈接問題。注意Linux內核默默地將這個值減少
#
/proc/sys/net/core/somaxconn的值,因此須要確認增大somaxconntcp_max_syn_backlog
#
兩個值來達到想要的效果。
# [syn queue && accept queue,
慢客戶端會形成accept queue 比較長, 因此加大一些若是客戶端太慢的話]
tcp-backlog 511

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
#
默認Redis監聽服務器上全部可用網絡接口的鏈接。能夠用"bind"配置指令跟一個或多個ip地址來實現
#
監聽一個或多個網絡接口
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1


# 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套套接字的路徑。沒有默認值,因此在沒有指定的狀況下Redis不會監聽Unix套接字
# unixsocket /tmp/redis.sock
# unixsocketperm 700


# Close the connection after a client is idle for N seconds (0 to disable)
#
一個客戶端空閒多少秒後關閉鏈接。(0表明禁用,永不關閉)
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) Take the connection alive from the point of view of network
# equipment in the middle.
#
# 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 60 seconds.
# TCP keepalive.

#
若是非零,則設置SO_KEEPALIVE選項來向空閒鏈接的客戶端發送ACK,因爲如下兩個緣由這是頗有用的:
#
# 1
)可以檢測無響應的對端
# 2
)讓該鏈接中間的網絡設備知道這個鏈接還存活
#
#
Linux上,這個指定的值(單位:秒)就是發送ACK的時間間隔。
#
注意:要關閉這個鏈接須要兩倍的這個時間值。
#
在其餘內核上這個時間間隔由內核配置決定
#
#
這個選項的一個合理值是60

tcp-keepalive 0

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

#
指定服務器調試等級
#
可能值:
# debug
(大量信息,對開發/測試有用)
# verbose
(不少精簡的有用信息,可是不像debug等級那麼多)
# notice
(適量的信息,基本上是你生產環境中須要的)
# warning
(只有很重要/嚴重的信息會記錄下來)
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

#
指明日誌文件名。也可使用""來強制讓Redis把日誌信息寫到標準輸出上。
#
注意:若是Redis以守護進程方式運行,而設置日誌顯示到標準輸出的話,日誌會發送到/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" "yes" 就能夠了。
#
而後根據須要設置其餘一些syslog參數就能夠了。
# syslog-enabled no

# Specify the syslog identity.
#
指明syslog身份
# syslog-ident redis

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
#
指明syslog的設備。必須是userLOCAL0 ~ LOCAL7之一。
# syslog-facility local0

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
#
設置數據庫個數。默認數據庫是 DB 0
#
能夠經過select <dbid> (0 <= dbid <= 'databases' - 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.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
#
# Note: you can disable saving completely by commenting out all "save" lines.
#
# It is also possible to remove all the previously configured save
# points by adding a save directive with a single empty string argument
# like in the following example:
#
# save ""

#
#
把數據庫存到磁盤上:
#
# save <seconds> <changes>
#
#
會在指定秒數和數據變化次數以後把數據庫寫到磁盤上。
#
#
下面的例子將會進行把數據寫入磁盤的操做:
# 900
秒(15分鐘)以後,且至少1次變動
# 300
秒(5分鐘)以後,且至少10次變動
# 60
秒以後,且至少10000次變動
#
#
注意:你要想不寫磁盤的話就把全部 "save" 設置註釋掉就好了。
#
#
經過添加一條帶空字符串參數的save指令也能移除以前全部配置的save指令
#
像下面的例子:
# save ""

save 900 1
save 300 10
save 60 10000


# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
# This will make the user aware (in a hard way) that data is not persisting
# on disk properly, otherwise chances are that no one will notice and some
# disaster will happen.
#
# If the background saving process will start working again Redis will
# automatically allow writes again.
#
# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.

#
默認若是開啓RDB快照(至少一條save指令)而且最新的後臺保存失敗,Redis將會中止接受寫操做
#
這將使用戶知道數據沒有正確的持久化到硬盤,不然可能沒人注意到而且形成一些災難。
#
#
若是後臺保存進程能從新開始工做,Redis將自動容許寫操做
#
#
然而若是你已經部署了適當的Redis服務器和持久化的監控,你可能想關掉這個功能以便於即便是
#
硬盤,權限等出問題了Redis也可以像平時同樣正常工做
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
#
當導出到 .rdb 數據庫時是否用LZF壓縮字符串對象?
#
默認設置爲 "yes",由於幾乎在任何狀況下它都是不錯的。
#
若是你想節省CPU的話你能夠把這個設置爲 "no",可是若是你有可壓縮的keyvalue的話,
#
那數據文件就會更大了。
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.

#
由於版本5RDB有一個CRC64算法的校驗和放在了文件的最後。這將使文件格式更加可靠但在
#
生產和加載RDB文件時,這有一個性能消耗(大約10%),因此你能夠關掉它來獲取最好的性能。
#
#
生成的關閉校驗的RDB文件有一個0的校驗和,它將告訴加載代碼跳過檢查
rdbchecksum yes

# The filename where to dump the DB
#
持久化數據庫的文件名
dbfilename dump.rdb

# 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.
#
工做目錄
#
#
數據庫會寫到這個目錄下,文件名就是上面的 "dbfilename" 的值。
#
#
累加文件也放這裏。
#
#
注意你這裏指定的必須是目錄,不是文件名。
dir ./

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

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 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 slaves.
# 2) Redis slaves 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 slaves automatically try to reconnect to masters
# and resynchronize with them.

#
主從同步。經過 slaveof 指令來實現Redis實例備份其餘實例。
#
理解redis asap備份的幾個要點以下:
# 1) redis
備份是異步的,可是你能夠配置達到必定數量的從redis能夠工做時,redis才進行備份,不然中止接受寫操做。
# 2) redis
支持跟主redis分步從新同步數據,若是這個鏈接斷開比較短的時間,你能夠配置這個分步同步的buffer
# 3)
同步是自動進行的,無須要用戶參與,當從redis主動從新鏈接上主redis後,這個同步就會自動進行。
#
注意,這裏是本地從遠端複製數據。也就是說,本地能夠有不一樣的數據庫文件、綁定不一樣的IP、監聽
#
不一樣的端口。
#
# slaveof <masterip> <masterport>

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
#
若是master設置了密碼保護(經過 "requirepass" 選項來配置),那麼slave在開始同步以前必須
#
進行身份驗證,不然它的同步請求會被拒絕。
# masterauth <master-password>

# When a slave loses its 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 date 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)
若是 slave-serve-stale-data 設置爲 "yes" (默認值)slave會繼續響應客戶端請求,
#
多是正常數據,或者是過期了的數據,也多是還沒得到值的空數據。
# 2)
若是 slave-serve-stale-data 設置爲 "no"slave會回覆"正在從master同步
#
SYNC with master in progress"來處理各類請求,除了 INFO SLAVEOF 命令。
#
slave-serve-stale-data yes

# You can configure a slave instance to accept writes or not. Writing against
# a slave instance may be useful to store some ephemeral data (because data
# written on a slave 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 slaves are read-only.
#
# Note: read only slaves 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 slave 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 slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
#
#
你能夠配置salve實例是否接受寫操做。可寫的slave實例可能對存儲臨時數據比較有用(由於寫入salve
#
的數據在同master同步以後將很容被刪除),可是若是客戶端因爲配置錯誤在寫入時也可能產生一些問題。
#
#
Redis2.6默認全部的slave爲只讀
#
#
注意:只讀的slave不是爲了暴露給互聯網上不可信的客戶端而設計的。它只是一個防止實例誤用的保護層。
#
一個只讀的slave支持全部的管理命令好比config,debug等。爲了限制你能夠用'rename-command'
#
隱藏全部的管理和危險命令來加強只讀slave的安全性
slave-read-only yes

# Replication SYNC strategy: disk or socket.
#
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
#
# New slaves and reconnecting slaves 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 slaves.
# 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 slaves incrementally.
# 2) Diskless: The Redis master creates a new process that directly writes the
# RDB file to slave sockets, without touching the disk at all.
#
# With disk-backed replication, while the RDB file is generated, more slaves
# 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 slaves 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 slaves
# will arrive and the transfer can be parallelized.
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
#
#
主從備份策略: 寫磁盤方式或者socket方式.
#
# -------------------------------------------------------
#
注意: 當前主從無磁盤備份還處於試驗階段
# -------------------------------------------------------
#
#
新的從redis或者那些不能進行部分同步備份的redis須要進行"全磁盤備份".
#
一個RDB文件會從主redis傳輸到從redis.
#
這個傳輸可使用兩種不一樣的策略:
#
# 1)
磁盤方式: redis會建立一個子進程進行寫RDB文件到磁盤中,
#
以後這個文件會被父進程傳送給從redis.
# 2)
無磁盤方式: redis會建立一個子進程進行直接將RDB文件經過socket傳送給從redis
#
而無需使用到磁盤.
#
#
使用磁盤主從備份的方式, 當這個RDB文件產生以後, 多個從redis能夠進行排隊等待當前子進程
#
完成這個RDB文件的寫工做後進行同步。
#
使用無磁盤主從備份的方式,一旦這個傳輸已經開始,那麼新鏈接進來的從redis須要等待新的一次
#
全新的傳輸,這個須要等待上一次傳輸的完成。
#
#
當採用無磁盤備份的方式以後, redis會等待必定的時間以後纔會開始傳輸, 以便儘量多的
#
對多個從redis進行同時備份,即平衡備份。這個時間能夠在這裏配置,單位爲秒。
#
即配置 repl-diskless-sync-delay x
#
#
對於磁盤比較慢的並且帶寬比較大的環境下,無磁盤主從備份會工做得更好。

repl-diskless-sync no

# When diskless replication is enabled, it is possible to configure the delay
# the server waits in order to spawn the child that trnasfers the RDB via socket
# to the slaves.
#
# This is important since once the transfer starts, it is not possible to serve
# new slaves arriving, that will be queued for the next RDB transfer, so the server
# waits a delay in order to let more slaves 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.
#
#
當開啓了無磁盤同步備份, 它能夠配置這個延時備份的時間。
#
redis等待必定的時間後建立子進程經過socket和多個從redis進行同步備份。
#
#
這個很重要, 由於一旦傳輸開始了,它不可能中途將新的從redis加入到這個同步傳輸中
#
只可以等待新的一次RDB傳輸, 由於主redis等待必定的時間是爲了儘量多的等待從redis鏈接上來。
#
#
這個延時是使用秒爲單位, 默認值是5秒鐘.
#
若是要禁用這個延時的特性,將其設爲0便可,那麼這個同步會立刻開始.

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.
#
# slave
根據指定的時間間隔向master發送ping請求。
#
時間間隔能夠經過 repl_ping_slave_period 來設置。
#
默認10秒。

# repl-ping-slave-period 10

# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
# 2) Master timeout from the point of view of slaves (data, pings).
# 3) Slave 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-slave-period otherwise a timeout will be detected
# every time there is low traffic between the master and the slave.
#
#
如下選項設置同步的超時時間
#
# 1
slave在與master SYNC期間有大量數據傳輸,形成超時
# 2
)在slave角度,master超時,包括數據、ping
# 3
)在master角度,slave超時,當master發送REPLCONF ACK pings
#
#
確保這個值大於指定的repl-ping-slave-period,不然在主從間流量不高時每次都會檢測到超時
#
# repl-timeout 60

# Disable TCP_NODELAY on the slave socket after SYNC?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to slaves. But this can add a delay for
# the data to appear on the slave side, up to 40 milliseconds with
# Linux kernels using a default configuration.
#
# If you select "no" the delay for data to appear on the slave 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 slaves are many hops away, turning this to "yes" may
# be a good idea.

#
是否在slave套接字發送SYNC以後禁用 TCP_NODELAY
#
#
若是你選擇「yes」Redis將使用更少的TCP包和帶寬來向slaves發送數據。可是這將使數據傳輸到slave
#
上有延遲,Linux內核的默認配置會達到40毫秒
#
#
若是你選擇了 "no" 數據傳輸到salve的延遲將會減小但要使用更多的帶寬
#
#
默認咱們會爲低延遲作優化,但高流量狀況或主從之間的跳數過多時,把這個選項設置爲「yes」
#
是個不錯的選擇。

repl-disable-tcp-nodelay no

# Set the replication backlog size. The backlog is a buffer that accumulates
# slave data when slaves are disconnected for some time, so that when a slave
# wants to reconnect again, often a full resync is not needed, but a partial
# resync is enough, just passing the portion of data the slave missed while
# disconnected.
#
# The bigger the replication backlog, the longer the time the slave can be
# disconnected and later be able to perform a partial resynchronization.
#
# The backlog is only allocated once there is at least a slave connected.
#
#
設置數據備份的backlog大小。backlog是一個slave在一段時間內斷開鏈接時記錄salve數據的緩衝,
#
因此一個slave在從新鏈接時,沒必要要全量的同步,而是一個增量同步就足夠了,將在斷開鏈接的這段
#
時間內slave丟失的部分數據傳送給它。
#
#
同步的backlog越大,slave可以進行增量同步而且容許斷開鏈接的時間就越長。
#
# backlog
只分配一次而且至少須要一個slave鏈接
#
# repl-backlog-size 1mb

# After a master has no longer connected slaves 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 slave disconnected, for
# the backlog buffer to be freed.
#
# A value of 0 means to never release the backlog.
#
#
master在一段時間內再也不與任何slave鏈接,backlog將會釋放。如下選項配置了從最後一個
# slave
斷開開始計時多少秒後,backlog緩衝將會釋放。
#
# 0
表示永不釋放backlog
#
# repl-backlog-ttl 3600

# The slave priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a slave to promote into a
# master if the master is no longer working correctly.
#
# A slave with a low priority number is considered better for promotion, so
# for instance if there are three slaves 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 slave as not able to perform the
# role of master, so a slave with priority of 0 will never be selected by
# Redis Sentinel for promotion.
#
# By default the priority is 100.
#

# slave
的優先級是一個整數展現在RedisInfo輸出中。若是master再也不正常工做了,哨兵將用它來
#
選擇一個slave提高=升爲master
#
#
優先級數字小的salve會優先考慮提高爲master,因此例若有三個slave優先級分別爲1010025
#
哨兵將挑選優先級最小數字爲10slave
#
# 0
做爲一個特殊的優先級,標識這個slave不能做爲master,因此一個優先級爲0slave永遠不會被
#
哨兵挑選提高爲master
#
#
默認優先級爲100
#
slave-priority 100

# It is possible for a master to stop accepting writes if there are less than
# N slaves connected, having a lag less or equal than M seconds.
#
# The N slaves 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 slave, 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 slaves
# are available, to the specified number of seconds.
#
# For example to require at least 3 slaves with a lag <= 10 seconds use:
#
# min-slaves-to-write 3
# min-slaves-max-lag 10
#
# Setting one or the other to 0 disables the feature.
#
# By default min-slaves-to-write is set to 0 (feature disabled) and
# min-slaves-max-lag is set to 10.
#
# master
裏面若是slave少於N個延時小於等於M秒的已鏈接slave,就能夠中止接收寫操做。
#
# N
slave須要是「oneline」狀態
#
#
延時是以秒爲單位,而且必須小於等於指定值,是從最後一個從slave接收到的ping(一般每秒發送)
#
開始計數。
#
#
這個設置選項並不保證多個從redis都會接受到這個寫請求,
#
可是能夠減少這個數據丟失的機率,一旦沒有知足數量的從服務器或者沒達到這個延時秒數之下.
#
#
例如至少須要3個延時小於等於10秒的slave用下面的指令:
#
# min-slaves-to-write 3
# min-slaves-max-lag 10

#
#
二者之一設置爲0將禁用這個功能。
#
#
默認 min-slaves-to-write 值是0(該功能禁用)而且 min-slaves-max-lag 值是10


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

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# 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太快了,因此外面的人能夠嘗試每秒150k的密碼來試圖破解密碼。這意味着你須要
#
一個高強度的密碼,不然破解太容易了。
#
# requirepass foobared
#


# Command renaming.
#
# 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 slaves may cause problems.
#
#
命令重命名
#
#
在共享環境下,能夠爲危險命令改變名字。好比,你能夠爲 CONFIG 改個其餘不太容易猜到的名字,
#
這樣內部的工具仍然可使用,而普通的客戶端將不行。
#
#
例如:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
#
也能夠經過更名爲空字符串來徹底禁用一個命令
#
# rename-command CONFIG ""
#
#
請注意:改變命令名字被記錄到AOF文件或被傳送到從服務器可能產生問題。

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

# 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'.
#
#
設置最多同時鏈接的客戶端數量。默認這個限制是10000個客戶端,然而若是Redis服務器不能配置
#
處理文件的限制數來知足指定的值,那麼最大的客戶端鏈接數就被設置成當前文件限制數減32(因
#
Redis服務器保留了一些文件描述符做爲內部使用)
#
#
一旦達到這個限制,Redis會關閉全部新鏈接併發送錯誤'max number of clients reached'

# maxclients 10000

# Don't use more memory than 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 cache, or to set
# a hard memory limit for an instance (using the 'noeviction' policy).
#
# WARNING: If you have slaves attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the slaves 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 slaves 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 slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
#
不要用比設置的上限更多的內存。一旦內存使用達到上限,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>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# 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
#
# 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:
#
#
最大內存策略:若是達到內存限制了,Redis如何選擇刪除key。你能夠在下面五個行爲裏選:
#
# volatile-lru ->
根據LRU算法刪除帶有過時時間的key
# allkeys-lru ->
根據LRU算法刪除任何key
# volatile-random ->
根據過時設置來隨機刪除key, 具有過時時間的key
# allkeys->random ->
無差異隨機刪, 任何一個key
# volatile-ttl ->
根據最近過時時間來刪除(輔以TTL, 這是對於有過時時間的key
# noeviction ->
誰也不刪,直接在寫操做時返回錯誤。
#
#
注意:對全部策略來講,若是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 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
和最小TTL算法的實現都不是很精確,可是很接近(爲了省內存),因此你能夠用樣本量作檢測。
#
例如:默認Redis會檢查3key而後取最舊的那個,你能夠經過下面的配置指令來設置樣本的個數。
#
# maxmemory-samples 3

############################## 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 http://redis.io/topics/persistence for more information.
#
#
默認狀況下,Redis是異步的把數據導出到磁盤上。這種模式在不少應用裏已經足夠好,但Redis進程
#
出問題或斷電時可能形成一段時間的寫操做丟失(這取決於配置的save指令)
#
# AOF
是一種提供了更可靠的替代持久化模式,例如使用默認的數據寫入文件策略(參見後面的配置)
#
在遇到像服務器斷電或單寫狀況下Redis自身進程出問題但操做系統仍正常運行等突發事件時,Redis
#
能只丟失1秒的寫操做。
#
# AOF
RDB持久化能同時啓動而且不會有問題。
#
若是AOF開啓,那麼在啓動時Redis將加載AOF文件,它更能保證數據的可靠性。
#
#
請查看 http://redis.io/topics/persistence 來獲取更多信息.

appendonly no

# The name of the append only file (default: "appendonly.aof")
#
純累加文件名字(默認:"appendonly.aof"
#

appendfilename "appendonly.aof"

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# 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".

# fsync()
系統調用告訴操做系統把數據寫到磁盤上,而不是等更多的數據進入輸出緩衝區。
#
有些操做系統會真的把數據立刻刷到磁盤上;有些則會盡快去嘗試這麼作。
#
# Redis
支持三種不一樣的模式:
#
# no
:不要馬上刷,只有在操做系統須要刷的時候再刷。比較快。
# always
:每次寫操做都馬上寫入到aof文件。慢,可是最安全。
# everysec
:每秒寫一次。折中方案。
#
#
默認的 "everysec" 一般來講能在速度和數據安全性之間取得比較好的平衡。根據你的理解來
#
決定,若是你能放寬該配置爲"no" 來獲取更好的性能(但若是你能忍受一些數據丟失,能夠考慮使用
#
默認的快照持久化模式),或者相反,用「always」會比較慢但比everysec要更安全。
#
#
請查看下面的文章來獲取更多的細節
# http://antirez.com/post/redis-persistence-demystified.html
#
#
若是不能肯定,就用 "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 none". In practical terms, this means that it is
# possible to lose up to 30 seconds of log in the worst scenario (with the
# default Linux settings).
#
# 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的同步策略設置成 "always" 或者 "everysec",而且後臺的存儲進程(後臺存儲或寫入AOF
#
日誌)會產生不少磁盤I/O開銷。某些Linux的配置下會使Redis由於 fsync()系統調用而阻塞好久。
#
注意,目前對這個狀況尚未完美修正,甚至不一樣線程的 fsync() 會阻塞咱們同步的write(2)調用。
#
#
爲了緩解這個問題,能夠用下面這個選項。它能夠在 BGSAVE BGREWRITEAOF 處理時阻止主進程進行fsync()
#
#
這就意味着若是有子進程在進行保存操做,那麼Redis就處於"不可同步"的狀態。
#
這其實是說,在最差的狀況下可能會丟掉30秒鐘的日誌數據。(默認Linux設定)
#
#
若是你有延時問題把這個設置成"yes",不然就保持"no",這是保存持久數據的最安全的方式。
#

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.
#
#
自動重寫AOF文件
#
若是AOF日誌文件增大到指定百分比,Redis可以經過 BGREWRITEAOF 自動重寫AOF日誌文件。
#
#
工做原理:Redis記住上次重寫時AOF文件的大小(若是重啓後尚未寫操做,就直接用啓動時的AOF大小)
#
#
這個基準大小和當前大小作比較。若是當前大小超過指定比例,就會觸發重寫操做。你還須要指定被重寫
#
日誌的最小尺寸,這樣避免了達到指定百分比但尺寸仍然很小的狀況還要重寫。
#
#
指定百分比爲0會禁用AOF自動重寫特性。
#

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


# An AOF file may be found to be truncated at the end during the Redis
# startup process, when the AOF data gets loaded back into memory.
# This may happen when the system where Redis is running
# crashes, especially when an ext4 filesystem is mounted without the
# data=ordered option (however this can't happen when Redis itself
# crashes or aborts but the operating system still works correctly).
#
# Redis 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
文件可能在尾部是不完整的(這跟system關閉有問題,尤爲是mount ext4文件系統時
#
沒有加上data=ordered選項。只會發生在os死時,redis本身死不會不完整)。
#
redis重啓時load進內存的時候就有問題了。
#
發生的時候,能夠選擇redis啓動報錯,而且通知用戶和寫日誌,或者load儘可能多正常的數據。
#
若是aof-load-truncatedyes,會自動發佈一個log給客戶端而後load(默認)。
#
若是是no,用戶必須手動redis-check-aof修復AOF文件才能夠。
#
注意,若是在讀取的過程當中,發現這個aof是損壞的,服務器也是會退出的,
#
這個選項僅僅用於當服務器嘗試讀取更多的數據但又找不到相應的數據時。
#
aof-load-truncated yes

################################ LUA SCRIPTING ###############################

# Max execution time of a Lua script in milliseconds.
#
# If the maximum execution time is reached Redis will log that a script is
# still in execution after the maximum allowed time and will start to
# reply to queries with an error.
#
# When a long running script exceeds the maximum execution time only the
# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
# used to stop a script that did not yet called write commands. The second
# is the only way to shut down the server in the case a write command was
# already issued by the script but the user doesn't want to wait for the natural
# termination of the script.
#
# Set it to 0 or a negative value for unlimited execution without warnings.
#
# Lua
腳本的最大執行時間,毫秒爲單位
#
#
若是達到了最大的執行時間,Redis將要記錄在達到最大容許時間以後一個腳本仍然在執行,而且將
#
開始對查詢進行錯誤響應。
#
#
當一個長時間運行的腳本超過了最大執行時間,只有 SCRIPT KILL SHUTDOWN NOSAVE 兩個
#
命令可用。第一個能夠用於中止一個尚未調用寫命名的腳本。第二個是關閉服務器惟一方式,當
#
寫命令已經經過腳本開始執行,而且用戶不想等到腳本的天然終止。
#
#
設置成0或者負值表示不限制執行時間而且沒有任何警告
#
lua-time-limit 5000

################################## 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.
#
# Redis
慢查詢日誌能夠記錄超過指定時間的查詢。運行時間不包括各類I/O時間,例如:鏈接客戶端,
#
發送響應數據等,而只計算命令執行的實際時間(這只是線程阻塞而沒法同時爲其餘請求服務的命令執
#
行階段)
#
#
你能夠爲慢查詢日誌配置兩個參數:一個指明Redis的超時時間(單位爲微秒)來記錄超過這個時間的命令
#
另外一個是慢查詢日誌長度。當一個新的命令被寫進日誌的時候,最老的那個記錄從隊列中移除。
#
#
下面的時間單位是微秒,因此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 128

################################ 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 enalbed at runtime using the command
# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
#
# redis
延時監控系統在運行時會採樣一些操做,以便收集可能致使延時的數據根源。
#
#
經過 LATENCY命令能夠打印一些圖樣和獲取一些報告,方便監控
#
#
這個系統僅僅記錄那個執行時間大於或等於預約時間(毫秒)的操做,
#
這個預約時間是經過latency-monitor-threshold配置來指定的,
#
當設置爲0時,這個監控系統處於中止狀態
#
#
默認狀況下這個監控系統是處於中止狀態的,由於大部分狀況下都是不須要的,若是你
#
沒有延時問題,收集數據會有一個性能衝擊,這個影響會比較小,而且能夠測試出來
#
延時監控能夠很容易的在線開啓,經過命令 CONFIG SET latency-monitor-threshold
# <milliseconds>
開啓.
latency-monitor-threshold 0

############################# Event notification ##############################

# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at http://redis.io/topics/notifications
#
# For instance if keyspace events notification is enabled, and a client
# performs a DEL operation on key "foo" stored in the Database 0, two
# messages will be published via Pub/Sub:
#
# 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@<db>__ prefix.
# E Keyevent events, published with __keyevent@<db>__ 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)
# A Alias for g$lshzxe, so that the "AKE" string means all the events.
#
# 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.
#
# Redis
能通知 Pub/Sub 客戶端關於鍵空間發生的事件
#
這個功能文檔位於http://redis.io/topics/keyspace-events
#
#
例如:若是鍵空間事件通知被開啓,而且客戶端對 0 號數據庫的鍵 foo 執行 DEL 命令時,將經過
# Pub/Sub
發佈兩條消息:
# PUBLISH __keyspace@0__:foo del
# PUBLISH __keyevent@0__:del foo
#
#
能夠在下表中選擇Redis要通知的事件類型。事件類型由單個字符來標識:
#
# K
鍵空間通知,以__keyspace@<db>__爲前綴
# E
鍵事件通知,以__keysevent@<db>__爲前綴
# g DEL , EXPIRE , RENAME
等類型無關的通用命令的通知, ...
# $ String
命令
# l List
命令
# s Set
命令
# h Hash
命令
# z
有序集合命令
# x
過時事件(每次key過時時生成)
# e
驅逐事件(當key在內存滿了被清除時生成)
# A g$lshzxe
的別名,所以」AKE」意味着全部的事件
#
# notify-keyspace-events
帶一個由0到多個字符組成的字符串參數。空字符串意思是通知被禁用。
#
#
例子:啓用List和通用事件通知:
# notify-keyspace-events Elg
#
#
例子2:爲了獲取過時key的通知訂閱名字爲 __keyevent@__:expired 的頻道,用如下配置
# notify-keyspace-events Ex
#
#
默認所用的通知被禁用,由於用戶一般不須要該特性,而且該特性會有性能損耗。
#
注意若是你不指定至少KE之一,不會發送任何事件。
#
notify-keyspace-events ""

############################### 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只有少許的entry時,而且最大的entry所佔空間沒有超過指定的限制時,會用一種節省內存的
#
數據結構來編碼。能夠經過下面的指令來設定限制
hash-max-ziplist-entries 512
hash-max-ziplist-value 64


# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
# you are under the following limits:
#
hash似,數據元素較少的list,能夠用另外一種方式來編碼從而節省大量空間。
#
這種特殊的方式只有在符合下面限制時才能夠用:
list-max-ziplist-entries 512
list-max-ziplist-value 64


# 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
有一種特殊編碼的狀況:當set數據全是十進制64位有符號整型數字構成的字符串時。
#
下面這個配置項就是用來設置set使用這種編碼來節省內存的最大長度。
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:
#
hashlist類似,有序集合也能夠用一種特別的編碼方式來節省大量空間。
#
這種編碼只適合長度和元素都小於下面限制的有序集合:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64


# HyperLogLog sparse representation bytes limit. The limit includes the
# 16 bytes header. When an HyperLogLog using the sparse representation crosses
# this limit, it is converted into the dense representation.
#
# A value greater than 16000 is totally useless, since at that point the
# dense representation is more memory efficient.
#
# 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.
#
# HyperLogLog
稀疏結構表示字節的限制。該限制包括
# 16
個字節的頭。當HyperLogLog使用稀疏結構表示
#
這些限制,它會被轉換成密度表示。

#
值大於16000是徹底沒用的,由於在該點
#
密集的表示是更多的內存效率。

#
建議值是3000左右,以便具備的內存好處, 減小內存的消耗
#
不會減慢太多PFADD操做時間,
#
它是ON)使用稀疏編碼的話。該值能夠提升到
# 10000
左右若是CPU不是一個問題的話,但空間,數據集是
#
由許多HyperLogLogs與基數在0 - 15000範圍內。

hll-sparse-max-bytes 3000

# 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.
#
#
啓用哈希刷新,每100CPU毫秒會拿出1個毫秒來刷新Redis的主哈希表(頂級鍵值映射表)。
# redis
所用的哈希表實現(見dict.c)採用延遲哈希刷新機制:你對一個哈希表操做越多,哈希刷新
#
操做就越多;反之,若是服務器是空閒的,那麼哈希刷新就不會完成,哈希表就會佔用更多的一些
#
內存而已。
#
#
默認是每秒鐘進行10次哈希表刷新,用來刷新字典,而後儘快釋放內存。
#
#
建議:
#
若是你對延遲比較在乎,不可以接受Redis時不時的對請求有2毫秒的延遲的話,就用
# "activerehashing no"
,若是不太在乎延遲而但願儘快釋放內存就設置"activerehashing yes"
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
# slave -> slave 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 <class> <hard limit> <soft limit> <soft seconds>
#
# A client is immediately disconnected once the hard limit is reached, or if
# the soft limit is reached and remains reached for the specified number of
# seconds (continuously).
# So for instance if the hard limit is 32 megabytes and the soft limit is
# 16 megabytes / 10 seconds, the client will get disconnected immediately
# if the size of the output buffers reach 32 megabytes, but will also get
# disconnected if the client reaches 16 megabytes and continuously overcomes
# the limit for 10 seconds.
#
# 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 slave clients, since
# subscribers and slaves receive data in a push fashion.
#
# Both the hard or the soft limit can be disabled by setting them to zero.
#
#
客戶端的輸出緩衝區的限制,可用於強制斷開那些由於某種緣由從服務器讀取數據的速度不夠快的客戶端,
#
(一個常見的緣由是一個發佈/訂閱客戶端消費消息的速度沒法遇上生產它們的速度)
#
#
能夠對三種不一樣的客戶端設置不一樣的限制:
# normal ->
正常客戶端
# slave -> slave
MONITOR 客戶端
# pubsub ->
至少訂閱了一個pubsub channelpattern的客戶端
#
#
下面是每一個client-output-buffer-limit語法:
# client-output-buffer-limit <class><hard limit> <soft limit> <soft seconds>
#
#
一旦達到硬限制客戶端會當即被斷開,或者達到軟限制並持續達到指定的秒數(連續的)。
#
例如,若是硬限制爲32兆字節和軟限制爲16兆字節/10秒,客戶端將會當即斷開
#
若是輸出緩衝區的大小達到32兆字節,或客戶端達到16兆字節並連續超過了限制10秒,就將斷開鏈接。
#
#
默認normal客戶端不作限制,由於他們在不主動請求時不接收數據(以推的方式),只有異步客戶端
#
可能會出現請求數據的速度比它能夠讀取的速度快的場景。
#
# pubsub
slave客戶端會有一個默認值,由於訂閱者和slaves以推的方式來接收數據
#
#
把硬限制和軟限制都設置爲0來禁用該功能
#
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60


# 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.
#
# Redis
調用內部函數來執行許多後臺任務,如關閉客戶端超時的鏈接,清除未被請求過的過時Key等等。
#
#
不是全部的任務都以相同的頻率執行,但Redis依照指定的「hz」值來執行檢查任務。
#
#
默認狀況下,「hz」的被設定爲10。提升該值將在Redis空閒時使用更多的CPU時,但同時當有多個key
#
同時到期會使Redis的反應更靈敏,以及超時能夠更精確地處理。
#
#
範圍是1500之間,可是值超過100一般不是一個好主意。
#
大多數用戶應該使用10這個默認值,只有在很是低的延遲要求時有必要提升到100
#
hz 10

# When a child rewrites the AOF file, if the following option is enabled
# the file will be fsync-ed every 32 MB of data generated. This is useful
# in order to commit the file to the disk more incrementally and avoid
# big latency spikes.
#
#
當一個子進程重寫AOF文件時,若是啓用下面的選項,則文件每生成32M數據會被同步。
#
爲了增量式的寫入硬盤而且避免大的延遲高峯這個指令是很是有用的

#
aof-rewrite-incremental-fsync yes
redis

相關文章
相關標籤/搜索