西西軟件園多重安全檢測下載網站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)其它知識 → C#緩存Redis for Windows配置文件詳解

C#緩存Redis for Windows配置文件詳解

相關軟件相關文章發(fā)表評論 來源:aehyok時間:2013/12/19 9:02:50字體大。A-A+

作者:aehyok點擊:137次評論:0次標簽: Redis

directx9.0c 64位運行庫V9.29.1974官方最終版
  • 類型:游戲其他大。17.3M語言:中文 評分:3.8
  • 標簽:
立即下載

本文將主要來探討redis強大的配置文件。

  我現(xiàn)在使用的redis版本為2.6。首先奉上配置文件的源文件。

# Redis configuration file example

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

# 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.
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.
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.
port 6666# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for incoming connections.
#
# 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.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 755# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0# Set server verbosity to 'debug'# it can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice

# Specify the log file name. Also 'stdout' 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/nulllogfile 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.
# syslog-enabled no

# Specify the syslog identity.
# syslog-ident redis

# Specify the syslog facility.  Must be USER or between LOCAL0-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'-1databases 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 at all commenting all the "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 900 1save 300 10save 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 an hard way) that data is not persisting
# on disk properly, otherwise chances are that no one will notice and some
# distater 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 usually even if there are problems with disk,
# permissions, and so forth.
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?# 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.
rdbcompression yes

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

# 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.
# 
# Also the Append Only File will be created inside this directory.
# 
# Note that you must specify a directory here, not a file name.
dir ./################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the 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.
#
# 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.
#
# 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 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-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 extend you can improve
# security of read only slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
slave-read-only yes

# 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.
#
# 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-timeout 60# 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 wtih 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-priority 100################################## 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.
#
# 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
# 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 possible to completely kill a command renaming it into
# an empty string:
#
# rename-command CONFIG ""################################### 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 ot 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'.
#
# 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
# accordingly to the eviction policy selected (see maxmemmory-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# an 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').
#
# maxmemory <bytes># 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
# allkeys-lru -> remove any key accordingly 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 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.
#
# 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.appendonly no

# The name of the append only file (default: "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.
#
# 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" that's usually the right compromise between# speed and data safety. It's up to you to understand if you can relax this to# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),# or on the contrary, use "always" that's very slow but a bit safer than# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html#
# If unsure, use "everysec".

# appendfsync always
appendfsync everysec
# appendfsync no

# When the AOF fsync policy is set to always or everysec, and a background
# saving process (a background save or AOF log background rewriting) is# performing a lot of I/O against the disk, in some Linux configurations
# Redis may block too long on the fsync() call. Note that there is no fix for# this currently, as even performing fsync in a different thread will block
# our synchronous write(2) call.
#
# In order to mitigate this problem it's possible to use the following option# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
#
# This means that while another child is saving the durability of Redis is# the same as "appendfsync none", that in practical 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.
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 percentage of zero in order to disable the automatic AOF
# rewrite feature.

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

################################ 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 exceed 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 commands was
# already issue by the script but the user don'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-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.
slowlog-log-slower-than 10000# There is no limit to this length. Just be aware that it will consume memory.
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128############################### ADVANCED CONFIG ###############################

# Hashes are encoded using a memory efficient data structure when they have a
# small number of entries, and the biggest entry does not exceed a given
# threshold. These thresholds can be configured using the following directives.
hash-max-ziplist-entries 512hash-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:
list-max-ziplist-entries 512list-max-ziplist-value 64# Sets have a special encoding in just one case: when a set is composed
# of just strings that happens to be integers in radix 10 in the range
# of 64 bit signed integers.
# The following configuration setting sets the limit in the size of the
# set in order to use this special memory saving encoding.set-max-intset-entries 512# Similarly to hashes and lists, sorted sets are also specially encoded in# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
zset-max-ziplist-entries 128zset-max-ziplist-value 64# 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 an 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
# active rehashing 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 form time to time
# to queries with 2 milliseconds delay.
#
# use "activerehashing yes" if you don't have such hard requirements but# want to free memory asap when possible.
activerehashing yes

# The client output buffer limits can be used to force disconnection of clients
# that are not reading data from the server fast enough for some reason (a
# common reason is that a Pub/Sub client can't consume messages as fast as the# publisher can produce them).
#
# The limit can be set differently for the three different classes of clients:
#
# normal -> normal clients
# slave  -> slave clients and MONITOR clients
# pubsub -> clients subcribed 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 just setting it to zero.
client-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis server but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
#
# include /path/to/local.conf
# include /path/to/other.conf

配置文件解析包括以下幾個部分

  一、基本配置

  二、快照

  三、同步

  四、安全

  五、限制

  六、純累加模式

  七、LUA腳本

  八、慢查詢日志

  九、高級配置

  十、其他

一、基本配置

1、  

# 注意單位問題:當需要設置內存大小的時候,可以使用類似1k、5GB、4M這樣的常見格式:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# 單位是大小寫不敏感的,所以1GB 1Gb 1gB的寫法都是完全一樣的。

2、

# Redis默認是不作為守護進程來運行的。你可以把這個設置為"yes"讓它作為守護進程來運行。
# 注意,當作為守護進程的時候,Redis會把進程ID寫到 /var/run/redis.pid
daemonize no

3、

# 當以守護進程方式運行的時候,Redis會把進程ID默認寫到 /var/run/redis.pid。你可以在這里修改路徑。
pidfile /var/run/redis.pid

4、

# 接受連接的特定端口,默認是6379。
# 如果端口設置為0,Redis就不會監(jiān)聽TCP套接字。
port 6379

5、



# 如果你想的話,你可以綁定單一接口;如果這里沒單獨設置,那么所有接口的連接都會被監(jiān)聽。
#
# bind 127.0.0.1

6、

# 指定用來監(jiān)聽連接的unxi套接字的路徑。這個沒有默認值,所以如果你不指定的話,Redis就不會通過unix套接字來監(jiān)聽。
#
# unixsocket /tmp/redis.sock
# unixsocketperm 755

7、

#一個客戶端空閑多少秒后關閉連接。(0代表禁用,永不關閉)
timeout 0

8、

# 設置服務器調試等級。
# 可能值:
# debug (很多信息,對開發(fā)/測試有用)
# verbose (很多精簡的有用信息,但是不像debug等級那么多)
# notice (適量的信息,基本上是你生產環(huán)境中需要的程度)
# warning (只有很重要/嚴重的信息會記錄下來)
loglevel verbose

9、

# 指明日志文件名。也可以使用"stdout"來強制讓Redis把日志信息寫到標準輸出上。
# 注意:如果Redis以守護進程方式運行,而你設置日志顯示到標準輸出的話,那么日志會發(fā)送到 /dev/nulllogfile stdout

10、

# 然后根據需要設置其他一些syslog參數(shù)就可以了。
# syslog-enabled no
 
# 指明syslog身份
# syslog-ident redis

# 指明syslog的設備。必須是一個用戶或者是 LOCAL0 ~ LOCAL7 之一。
# syslog-facility local0

11、

# 設置數(shù)據庫個數(shù)。默認數(shù)據庫是 DB 0,你可以通過SELECT <dbid> WHERE dbid(0~'databases' - 1)來為每個連接使用不同的數(shù)據庫。
databases 16

二、快照

12、

################################ 快照 #################################
 
#
# 把數(shù)據庫存到磁盤上:
#
#   save <seconds> <changes>#  
#   會在指定秒數(shù)和數(shù)據變化次數(shù)之后把數(shù)據庫寫到磁盤上。
#
#   下面的例子將會進行把數(shù)據寫入磁盤的操作:
#   900秒(15分鐘)之后,且至少1次變更
#   300秒(5分鐘)之后,且至少10次變更
#   60秒之后,且至少10000次變更
#
#   注意:你要想不寫磁盤的話就把所有 "save" 設置注釋掉就行了。
 
save 900 1save 300 10save 60 10000

13、

#后臺存儲錯誤停止寫。 
stop-writes-on-bgsave-error yes

14、

# 當導出到 .rdb 數(shù)據庫時是否用LZF壓縮字符串對象。
# 默認設置為 "yes",所以幾乎總是生效的。
# 如果你想節(jié)省CPU的話你可以把這個設置為 "no",但是如果你有可壓縮的key的話,那數(shù)據文件就會更大了。
rdbcompression yes

15、

#存儲和加載rdb文件時校驗。 
rdbchecksum yes

16、

# 數(shù)據庫的文件名
dbfilename dump.rdb

17、

# 工作目錄
#
# 數(shù)據庫會寫到這個目錄下,文件名就是上面的 "dbfilename" 的值。
#
# 累加文件也放這里。
#
# 注意你這里指定的必須是目錄,不是文件名。
dir ./

三、同步

18、

#
# 主從同步。通過 slaveof 配置來實現(xiàn)Redis實例的備份。
# 注意,這里是本地從遠端復制數(shù)據。也就是說,本地可以有不同的數(shù)據庫文件、綁定不同的IP、監(jiān)聽不同的端口。
#
# slaveof <masterip> <masterport>
 # 如果master設置了密碼(通過下面的 "requirepass" 選項來配置),那么slave在開始同步之前必須進行身份驗證,否則它的同步請求會被拒絕。
#
# masterauth <master-password>
 # 當一個slave失去和master的連接,或者同步正在進行中,slave的行為有兩種可能:
#
# 1) 如果 slave-serve-stale-data 設置為 "yes" (默認值),slave會繼續(xù)響應客戶端請求,可能是正常數(shù)據,也可能是還沒獲得值的空數(shù)據。
# 2) 如果 slave-serve-stale-data 設置為 "no",slave會回復"正在從master同步(SYNC with master in progress)"來處理各種請求,除了 INFO 和 SLAVEOF 命令。
#
slave-serve-stale-data yes

19、

#如果為yes,slave實例只讀,如果為no,slave實例可讀可寫。 
slave-read-only yes  
# slave根據指定的時間間隔向服務器發(fā)送ping請求。
# 時間間隔可以通過 repl_ping_slave_period 來設置。
# 默認10秒。
#
# repl-ping-slave-period 10
 # 下面的選項設置了大塊數(shù)據I/O、向master請求數(shù)據和ping響應的過期時間。
# 默認值60秒。
#
# 一個很重要的事情是:確保這個值比 repl-ping-slave-period 大,否則master和slave之間的傳輸過期時間比預想的要短。
#
# repl-timeout 60

20、



#如果master不能再正常工作,那么會在多個slave中,選擇優(yōu)先值最小的一個slave提升為master,優(yōu)先值為0表示不能提升為master。 
 slave-priority 100

四、安全 

21、

# 要求客戶端在處理任何命令時都要驗證身份和密碼。
# 這在你信不過來訪者時很有用。
#
# 為了向后兼容的話,這段應該注釋掉。而且大多數(shù)人不需要身份驗證(例如:它們運行在自己的服務器上。)
#

# 警告:因為Redis太快了,所以居心不良的人可以每秒嘗試150k的密碼來試圖破解密碼。
# 這意味著你需要一個高強度的密碼,否則破解太容易了。
#
# requirepass foobared
 
# 命令重命名
#
# 在共享環(huán)境下,可以為危險命令改變名字。比如,你可以為 CONFIG 改個其他不太容易猜到的名字,這樣你自己仍然可以使用,而別人卻沒法做壞事了。
#
# 例如:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# 甚至也可以通過給命令賦值一個空字符串來完全禁用這條命令:
#
# rename-command CONFIG ""

五、限制 

22、

#
# 設置最多同時連接客戶端數(shù)量。
# 默認沒有限制,這個關系到Redis進程能夠打開的文件描述符數(shù)量。
# 特殊值"0"表示沒有限制。
# 一旦達到這個限制,Redis會關閉所有新連接并發(fā)送錯誤"達到最大用戶數(shù)上限(max number of clients reached)"#
# maxclients 10000

23、

# 不要用比設置的上限更多的內存。一旦內存使用達到上限,Redis會根據選定的回收策略(參見:maxmemmory-policy)刪除key。
#
# 如果因為刪除策略問題Redis無法刪除key,或者策略設置為 "noeviction",Redis會回復需要更多內存的錯誤信息給命令。
# 例如,SET,LPUSH等等。但是會繼續(xù)合理響應只讀命令,比如:GET。
#
# 在使用Redis作為LRU緩存,或者為實例設置了硬性內存限制的時候(使用 "noeviction" 策略)的時候,這個選項還是滿有用的。
#
# 警告:當一堆slave連上達到內存上限的實例的時候,響應slave需要的輸出緩存所需內存不計算在使用內存當中。
# 這樣當請求一個刪除掉的key的時候就不會觸發(fā)網絡問題/重新同步的事件,然后slave就會收到一堆刪除指令,直到數(shù)據庫空了為止。
#
# 簡而言之,如果你有slave連上一個master的話,那建議你把master內存限制設小點兒,確保有足夠的系統(tǒng)內存用作輸出緩存。
# (如果策略設置為"noeviction"的話就不無所謂了)
#
# maxmemory <bytes>

24、

# 內存策略:如果達到內存限制了,Redis如何刪除key。你可以在下面五個策略里面選:181#182# volatile-lru -> 根據LRU算法生成的過期時間來刪除。183# allkeys-lru -> 根據LRU算法刪除任何key。184# volatile-random -> 根據過期設置來隨機刪除key。185# allkeys->random -> 無差別隨機刪。186# volatile-ttl -> 根據最近過期時間來刪除(輔以TTL)187# noeviction -> 誰也不刪,直接在寫操作時返回錯誤。188#
# 注意:對所有策略來說,如果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和最小TTL算法的實現(xiàn)都不是很精確,但是很接近(為了省內存),所以你可以用樣例做測試。
# 例如:默認Redis會檢查三個key然后取最舊的那個,你可以通過下面的配置項來設置樣本的個數(shù)。
#
# maxmemory-samples 3

六、純累加模式

25、

# 默認情況下,Redis是異步的把數(shù)據導出到磁盤上。這種情況下,當Redis掛掉的時候,最新的數(shù)據就丟了。
# 如果不希望丟掉任何一條數(shù)據的話就該用純累加模式:一旦開啟這個模式,Redis會把每次寫入的數(shù)據在接收后都寫入 appendonly.aof 文件。
# 每次啟動時Redis都會把這個文件的數(shù)據讀入內存里。
#
# 注意,異步導出的數(shù)據庫文件和純累加文件可以并存(你得把上面所有"save"設置都注釋掉,關掉導出機制)。
# 如果純累加模式開啟了,那么Redis會在啟動時載入日志文件而忽略導出的 dump.rdb 文件。
#
# 重要:查看 BGREWRITEAOF 來了解當累加日志文件太大了之后,怎么在后臺重新處理這個日志文件。
 
appendonly no

26、

# 純累加文件名字(默認:"appendonly.aof")
# appendfilename appendonly.aof
 
# fsync() 請求操作系統(tǒng)馬上把數(shù)據寫到磁盤上,不要再等了。
# 有些操作系統(tǒng)會真的把數(shù)據馬上刷到磁盤上;有些則要磨蹭一下,但是會盡快去做。
#
# Redis支持三種不同的模式:
#
# no:不要立刻刷,只有在操作系統(tǒng)需要刷的時候再刷。比較快。
# always:每次寫操作都立刻寫入到aof文件。慢,但是最安全。
# everysec:每秒寫一次。折衷方案。
#
# 默認的 "everysec" 通常來說能在速度和數(shù)據安全性之間取得比較好的平衡。
# 如果你真的理解了這個意味著什么,那么設置"no"可以獲得更好的性能表現(xiàn)(如果丟數(shù)據的話,則只能拿到一個不是很新的快照);
# 或者相反的,你選擇 "always" 來犧牲速度確保數(shù)據安全、完整。
#
# 如果拿不準,就用 "everysec"
 # appendfsync always
appendfsync everysec
# appendfsync no

27、

# 如果AOF的同步策略設置成 "always" 或者 "everysec",那么后臺的存儲進程(后臺存儲或寫入AOF日志)會產生很多磁盤I/O開銷。
# 某些Linux的配置下會使Redis因為 fsync() 而阻塞很久。
# 注意,目前對這個情況還沒有完美修正,甚至不同線程的 fsync() 會阻塞我們的 write(2) 請求。
#
# 為了緩解這個問題,可以用下面這個選項。它可以在 BGSAVE 或 BGREWRITEAOF 處理時阻止 fsync()。
#
# 這就意味著如果有子進程在進行保存操作,那么Redis就處于"不可同步"的狀態(tài)。
# 這實際上是說,在最差的情況下可能會丟掉30秒鐘的日志數(shù)據。(默認Linux設定)
#
# 如果你有延遲的問題那就把這個設為 "yes",否則就保持 "no",這是保存持久數(shù)據的最安全的方式。
no-appendfsync-on-rewrite no

28、

# 自動重寫AOF文件
#
# 如果AOF日志文件大到指定百分比,Redis能夠通過 BGREWRITEAOF 自動重寫AOF日志文件。
#
# 工作原理:Redis記住上次重寫時AOF日志的大。ɑ蛘咧貑⒑鬀]有寫操作的話,那就直接用此時的AOF文件),
#           基準尺寸和當前尺寸做比較。如果當前尺寸超過指定比例,就會觸發(fā)重寫操作。
#
# 你還需要指定被重寫日志的最小尺寸,這樣避免了達到約定百分比但尺寸仍然很小的情況還要重寫。
#
# 指定百分比為0會禁用AOF自動重寫特性。
 
auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb

七、LUA腳本

29、

#一個Lua腳本最長的執(zhí)行時間為5000毫秒(5秒),如果為0或負數(shù)表示無限執(zhí)行時間。 
 lua-time-limit 5000

30、

# Redis慢查詢日志可以記錄超過指定時間的查詢。運行時間不包括各種I/O時間。
# 例如:連接客戶端,發(fā)送響應數(shù)據等。只計算命令運行的實際時間(這是唯一一種命令運行線程阻塞而無法同時為其他請求服務的場景)
#
# 你可以為慢查詢日志配置兩個參數(shù):一個是超標時間,單位為微妙,記錄超過個時間的命令。
# 另一個是慢查詢日志長度。當一個新的命令被寫進日志的時候,最老的那個記錄會被刪掉。
#
# 下面的時間單位是微秒,所以1000000就是1秒。注意,負數(shù)時間會禁用慢查詢日志,而0則會強制記錄所有命令。
slowlog-log-slower-than 10000
 # 這個長度沒有限制。只要有足夠的內存就行。你可以通過 SLOWLOG RESET 來釋放內存。(譯者注:日志居然是在內存里的Orz)
slowlog-max-len 128

八、慢查詢日志

31、

# Redis慢查詢日志可以記錄超過指定時間的查詢。運行時間不包括各種I/O時間。 
# 例如:連接客戶端,發(fā)送響應數(shù)據等。只計算命令運行的實際時間(這是唯一一種命令運行線程阻塞而無法同時為其他請求服務的場景) 
# 
 # 你可以為慢查詢日志配置兩個參數(shù):一個是超標時間,單位為微妙,記錄超過個時間的命令。 
# 另一個是慢查詢日志長度。當一個新的命令被寫進日志的時候,最老的那個記錄會被刪掉。 
# 
 # 下面的時間單位是微秒,所以1000000就是1秒。注意,負數(shù)時間會禁用慢查詢日志,而0則會強制記錄所有命令。 
slowlog-log-slower-than 10000 
   
 # 這個長度沒有限制。只要有足夠的內存就行。你可以通過 SLOWLOG RESET 來釋放內存。(譯者注:日志居然是在內存里的Orz) 
slowlog-max-len 128

九、高級配置

32、

# 當有大量數(shù)據時,適合用哈希編碼(需要更多的內存),元素數(shù)量上限不能超過給定限制。
# 你可以通過下面的選項來設定這些限制:
hash-max-zipmap-entries 512hash-max-zipmap-value 64
 # 與哈希相類似,數(shù)據元素較少的情況下,可以用另一種方式來編碼從而節(jié)省大量空間。
# 這種方式只有在符合下面限制的時候才可以用:
list-max-ziplist-entries 512list-max-ziplist-value 64
 # 還有這樣一種特殊編碼的情況:數(shù)據全是64位無符號整型數(shù)字構成的字符串。
# 下面這個配置項就是用來限制這種情況下使用這種編碼的最大上限的。set-max-intset-entries 512
 # 與第一、第二種情況相似,有序序列也可以用一種特別的編碼方式來處理,可節(jié)省大量空間。
# 這種編碼只適合長度和元素都符合下面限制的有序序列:
zset-max-ziplist-entries 128zset-max-ziplist-value 64

33、

# 哈希刷新,每100個CPU毫秒會拿出1個毫秒來刷新Redis的主哈希表(頂級鍵值映射表)。
# redis所用的哈希表實現(xiàn)(見dict.c)采用延遲哈希刷新機制:你對一個哈希表操作越多,哈希刷新操作就越頻繁;
# 反之,如果服務器非常不活躍那么也就是用點內存保存哈希表而已。
#
# 默認是每秒鐘進行10次哈希表刷新,用來刷新字典,然后盡快釋放內存。
#
# 建議:
# 如果你對延遲比較在意的話就用 "activerehashing no",每個請求延遲2毫秒不太好嘛。
# 如果你不太在意延遲而希望盡快釋放內存的話就設置 "activerehashing yes"。
activerehashing yes


34、

# 哈希刷新,每100個CPU毫秒會拿出1個毫秒來刷新Redis的主哈希表(頂級鍵值映射表)。 
# redis所用的哈希表實現(xiàn)(見dict.c)采用延遲哈希刷新機制:你對一個哈希表操作越多,哈希刷新操作就越頻繁; 
# 反之,如果服務器非常不活躍那么也就是用點內存保存哈希表而已。 
# 
 # 默認是每秒鐘進行10次哈希表刷新,用來刷新字典,然后盡快釋放內存。 
# 
 # 建議: 
# 如果你對延遲比較在意的話就用 "activerehashing no",每個請求延遲2毫秒不太好嘛。 

# 如果你不太在意延遲而希望盡快釋放內存的話就設置 "activerehashing yes"。 

 #重新哈希the main Redis hash table(the one mapping top-level keys to values),這樣會節(jié)省更多的空間。 
activerehashing yes 
   #對客戶端輸出緩沖進行限制可以強迫那些就不從服務器讀取數(shù)據的客戶端斷開連接。對于normal client,第一個0表示取消hard limit,第二個0和第三個0表示取消soft limit,normal client默認取消限制,因為如果沒有尋問,他們是不會接收數(shù)據的。 

 client-output-buffer-limit normal 0 0 0 

 #對于slave client和MONITER client,如果client-output-buffer一旦超過256mb,又或者超過64mb持續(xù)60秒,那么服務器就會立即斷開客戶端連接。 
client-output-buffer-limit slave 256mb 64mb 60  #對于pubsub client,如果client-output-buffer一旦超過32mb,又或者超過8mb持續(xù)60秒,那么服務器就會立即斷開客戶端連接。 
client-output-buffer-limit pubsub 32mb 8mb 60

35、

# 包含一個或多個其他配置文件。 
# 這在你有標準配置模板但是每個redis服務器又需要個性設置的時候很有用。 
# 包含文件特性允許你引人其他配置文件,所以好好利用吧。 
# 
 # include /path/to/local.conf 
# include /path/to/other.conf


總結

從上看到下,如果你對redis研究不是很深入,就像我一樣,會感覺到redis的配置功能的確是很強大的,貌似也是很復雜的,不過沒關系,如果你在實踐的項目中有用到的話,你會發(fā)現(xiàn)其實也沒那么復雜。下一篇希望簡單的在C#使用redis。

    運行庫合集
    (58)運行庫合集
    用精簡版系統(tǒng)或者綠色版軟件時,使用軟件經常遇見的情況是由于應用程序配置不正確,應用程序未能啟動,提示缺少文件等。大部分電腦新手都以為軟件問題,其實不是的,部分軟件或者游戲需要依賴運行庫才可以運行的。西西為大家精挑細選了常用的運行庫,運行綠色軟件和游戲不再提示找不到了其中運行庫分為大類,常用運行庫游戲運行庫和其他運行庫,最大滿足不同類型的用戶。...更多>>

    相關評論

    閱讀本文后您有什么感想? 已有人給出評價!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評論

    最新評論

    發(fā)表評論 查看所有評論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字數(shù): 0/500 (您的評論需要經過審核才能顯示)