当前位置:首页 > 操作系统 > Windows

redis windows下的环境搭建

感觉这东西跟mongodb差不多,安装和布置挺简单,
下载地址:https://github.com/dmajkic/redis/downloads 下载下来的包里有两个,
一个是32位的,一个是64位的。根据自己的实情情况选择,我的是64bit,
把这个文件夹复制到其它地方,比如E:TRS edis目录下。
打开一个cmd窗口  使用cd命令切换目录到E:TRS edis 运行 redis-server.exe redis.conf
如果想方便的话,可以把redis的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个redis.conf可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:

技术分享

这时候别启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了
切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 出现下图:

技术分享

这时候,就已经完成配置了,现在说下它的的redis.conf配置文件。下面是相关项的说明,

            <span># Redis configuration file example

 

# Note on units: when memory size </span>
            <span>is</span> needed, it <span>is</span><span> possible to specifiy

# it </span><span>in</span><span> the usual form of 1k 5GB 4M and so forth:

#

# 1k </span>=> <span>1000</span><span> bytes

# 1kb </span>=> <span>1024</span><span> bytes

# 1m </span>=> <span>1000000</span><span> bytes

# 1mb </span>=> <span>1024</span>*<span>1024</span><span> bytes

# 1g </span>=> <span>1000000000</span><span> bytes

# 1gb </span>=> <span>1024</span>*<span>1024</span>*<span>1024</span><span> bytes

#

# units are </span><span>case</span><span> insensitive so 1GB 1Gb 1gB are all the same.

 

# By </span><span>default</span> Redis does not run <span>as</span> a daemon. Use <span>‘</span><span>yes</span><span>‘</span><span>if</span><span> you need it.

# Note that Redis will write a pid file </span><span>in</span> /var/run/<span>redis.pid when daemonized.

daemonize no  

Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程

 

# When running daemonized, Redis writes a pid file </span><span>in</span> /var/run/<span>redis.pid by

# </span><span>default</span><span>. You can specify a custom pid file location here.

pidfile </span>/var/run/<span>redis.pid

当Redis以守护进程方式运行时,Redis默认会把pid写入</span>/var/run/<span>redis.pid文件,可以通过pidfile指定

# Accept connections on the specified port, </span><span>default</span><span>is</span><span>6379</span><span>.

# If port </span><span>0</span><span>is</span><span> specified Redis will not listen on a TCP socket.

port </span><span>6379</span><span>

指定Redis监听端口,默认端口为6379

# If you want you can bind a single </span><span>interface</span>, <span>if</span> the bind option <span>is</span><span> not

# specified all the interfaces will listen </span><span>for</span><span> incoming connections.

#

# bind </span><span>127.0</span>.<span>0.1</span><span>

绑定的主机地址

# Specify the path </span><span>for</span> the unix socket that will be used to listen <span>for</span><span>

# incoming connections. There </span><span>is</span> no <span>default</span><span>, so Redis will not listen

# on a unix socket when not specified.

#

# unixsocket </span>/tmp/<span>redis.sock

# unixsocketperm </span><span>755</span><span>

 

# Close the connection after a client </span><span>is</span> idle <span>for</span> N seconds (<span>0</span><span> to disable)

timeout </span><span>0</span><span>

当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能

# Set server verbosity to </span><span>‘</span><span>debug</span><span>‘</span><span>

# it can be one of:

# debug (a lot of information, useful </span><span>for</span> development/<span>testing)

# verbose (many rarely useful info, but not a mess like the debug level)

# notice (moderately verbose, what you want </span><span>in</span><span> production probably)

# warning (only very important </span>/<span> critical messages are logged)

loglevel verbose

指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose

# Specify the log file name. Also </span><span>‘</span><span>stdout</span><span>‘</span><span> can be used to force

# Redis to log on the standard output. Note that </span><span>if</span><span> you use standard

# output </span><span>for</span> logging but daemonize, logs will be sent to /dev/<span>null</span><span>

logfile stdout

日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给</span>/dev/<span>null</span><span>

# To enable logging to the system logger, just </span><span>set</span><span>‘</span><span>syslog-enabled</span><span>‘</span><span> to yes,

# and optionally update the other syslog parameters to suit your needs.

# syslog</span>-<span>enabled no

 

# Specify the syslog identity.

# syslog</span>-<span>ident redis

 

# Specify the syslog facility.  Must be USER or between LOCAL0</span>-<span>LOCAL7.

# syslog</span>-<span>facility local0

 

# Set the number of databases. The </span><span>default</span> database <span>is</span> DB <span>0</span><span>, you can select

# a different one on a per</span>-connection basis <span>using</span> SELECT <dbid> <span>where</span><span>

# dbid </span><span>is</span> a number between <span>0</span> and <span>‘</span><span>databases</span><span>‘</span>-<span>1</span><span>

databases </span><span>16</span><span>

设置数据库的数量,默认数据库为0,可以使用SELECT </span><dbid><span>命令在连接上指定数据库id

################################ SNAPSHOTTING  #################################

#

# Save the DB on disk:

#

#   save </span><seconds> <changes><span>

#

#   Will save the DB </span><span>if</span><span> 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 </span><span>900</span> sec (<span>15</span> min) <span>if</span> at least <span>1</span><span> key changed

#   after </span><span>300</span> sec (<span>5</span> min) <span>if</span> at least <span>10</span><span> keys changed

#   after </span><span>60</span> sec <span>if</span> at least <span>10000</span><span> keys changed

#

#   Note: you can disable saving at all commenting all the </span><span>"</span><span>save</span><span>"</span><span> lines.

 

save </span><span>900</span><span>1</span><span>

save </span><span>300</span><span>10</span><span>

save </span><span>60</span><span>10000</span><span>

分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。

指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合

# Compress </span><span>string</span> objects <span>using</span> LZF when dump .rdb databases?<span>

# For </span><span>default</span> that<span>‘</span><span>s set to </span><span>‘</span>yes<span>‘</span><span> as it</span><span>‘</span><span>s almost always a win.

# If you want to save some CPU </span><span>in</span> the saving child <span>set</span> it to <span>‘</span><span>no</span><span>‘</span><span> but

# the dataset will likely be bigger </span><span>if</span><span> you have compressible values or keys.

rdbcompression yes

指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大

# The filename </span><span>where</span><span> to dump the DB

dbfilename dump.rdb

指定本地数据库文件名,默认值为dump.rdb

# The working directory.

#

# The DB will be written inside </span><span>this</span><span> directory, with the filename specified

# above </span><span>using</span> the <span>‘</span><span>dbfilename</span><span>‘</span><span> configuration directive.

# 

# Also the Append Only File will be created inside </span><span>this</span><span> directory.

# 

# Note that you must specify a directory here, not a file name.

dir .</span>/<span>

指定本地数据库存放目录

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

 

# Master</span>-<span>Slave replication. Use slaveof to make a Redis instance a copy of

# another Redis server. Note that the configuration </span><span>is</span><span> local to the slave

# so </span><span>for</span> example it <span>is</span><span> possible to configure the slave to save the DB with a

# different interval, or to listen to another port, and so on.

#

# slaveof </span><masterip> <masterport><span>

slaveof </span><masterip> <masterport><span> 设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步

# If the master </span><span>is</span> password <span>protected</span> (<span>using</span> the <span>"</span><span>requirepass</span><span>"</span><span> configuration

# directive below) it </span><span>is</span><span> possible to tell the slave to authenticate before

# starting the replication synchronization process, otherwise the master will

# refuse the slave request.

#

# masterauth </span><master-password><span>

masterauth </span><master-password><span> 当master服务设置了密码保护时,slav服务连接master的密码

# When a slave lost the connection with the master, or when the replication

# </span><span>is</span> still <span>in</span> progress, the slave can act <span>in</span><span> two different ways:

#

# </span><span>1</span>) <span>if</span> slave-serve-stale-data <span>is</span><span>set</span> to <span>‘</span><span>yes</span><span>‘</span> (the <span>default</span><span>) the slave will

#    still reply to client requests, possibly with </span><span>out</span><span> of data data, or the

#    data </span><span>set</span> may just be empty <span>if</span><span>this</span><span>is</span><span> the first synchronization.

#

# </span><span>2</span>) <span>if</span> slave-serve-stale data <span>is</span><span>set</span> to <span>‘</span><span>no</span><span>‘</span><span> the slave will reply with

#    an error </span><span>"</span><span>SYNC with master in progress</span><span>"</span><span> to all the kind of commands

#    but to INFO and SLAVEOF.

#

slave</span>-serve-stale-<span>data yes

 

# Slaves send PINGs to server </span><span>in</span> a predefined interval. It<span>‘</span><span>s possible to change</span><span>
# </span><span>this</span> interval with the repl_ping_slave_period option. The <span>default</span> value <span>is</span><span>10</span><span>

# seconds.

#

# repl</span>-ping-slave-period <span>10</span><span>

 

# The following option sets a timeout </span><span>for</span> both Bulk transfer I/<span>O timeout and

# master data or ping response timeout. The </span><span>default</span> value <span>is</span><span>60</span><span> seconds.

#

# It </span><span>is</span> important to make sure that <span>this</span> value <span>is</span><span> greater than the value

# specified </span><span>for</span> repl-ping-slave-<span>period otherwise a timeout will be detected

# every time there </span><span>is</span><span> low traffic between the master and the slave.

#

# repl</span>-timeout <span>60</span><span>

 

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

 

# Require clients to issue AUTH </span><PASSWORD><span> before processing any other

# commands.  This might be useful </span><span>in</span> environments <span>in</span> which you <span>do</span><span> not trust

# others with access to the host running redis</span>-<span>server.

#

# This should stay commented </span><span>out</span><span>for</span><span> backward compatibility and because most

# people </span><span>do</span><span> not need auth (e.g. they run their own servers).

# 

# Warning: since Redis </span><span>is</span> pretty fast an outside user can <span>try</span><span> 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 </span><span>break</span><span>.

#

# requirepass foobared

 requirepass foobared 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH </span><password><span>命令提供密码,默认关闭

# Command renaming.

#

# It </span><span>is</span> possilbe to change the name of dangerous commands <span>in</span><span> a shared

# environment. For instance the CONFIG command may be renamed into something

# of hard to guess so that it will be still available </span><span>for</span><span>internal</span>-<span>use

# tools but not available </span><span>for</span><span> general clients.

#

# Example:

#

# rename</span>-<span>command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52

#

# It </span><span>is</span><span> also possilbe to completely kill a command renaming it into

# an empty </span><span>string</span><span>:

#

# rename</span>-command CONFIG <span>""</span><span>

 

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

 

# Set the max number of connected clients at the same time. By </span><span>default</span><span> there

# </span><span>is</span> no limit, and it<span>‘</span><span>s up to the number of file descriptors the Redis process</span><span>
# </span><span>is</span> able to open. The special value <span>‘</span><span>0</span><span>‘</span><span> means no limits.

# Once the limit </span><span>is</span> reached Redis will close all the <span>new</span><span> connections sending

# an error </span><span>‘</span><span>max number of clients reached</span><span>‘</span><span>.

#

# maxclients </span><span>128</span><span>

maxclients </span><span>128</span> 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients <span>0</span><span>,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息

# Don</span><span>‘</span><span>t use more memory than the specified amount of bytes.</span><span>
# When the memory limit </span><span>is</span> reached Redis will <span>try</span><span> to remove keys with an

# EXPIRE </span><span>set</span>. It will <span>try</span><span> to start freeing keys that are going to expire

# </span><span>in</span><span> little time and preserve keys with a longer time to live.

# Redis will also </span><span>try</span> to remove objects from free lists <span>if</span><span> possible.

#

# If all </span><span>this</span><span> fails, Redis will start to reply with errors to commands

# that will use more memory, like SET, LPUSH, and so on, and will </span><span>continue</span><span>

# to reply to most read</span>-<span>only commands like GET.

#

# WARNING: maxmemory can be a good idea mainly </span><span>if</span> you want to use Redis <span>as</span><span> a

# </span><span>‘</span><span>state</span><span>‘</span> server or cache, not <span>as</span> a real DB. When Redis <span>is</span> used <span>as</span><span> a real

# database the memory usage will grow over the weeks, it will be obvious </span><span>if</span><span>

# it </span><span>is</span> going to use too much memory <span>in</span> the <span>long</span> run, and you<span>‘</span><span>ll have the time</span><span>
# to upgrade. With maxmemory after the limit </span><span>is</span> reached you<span>‘</span><span>ll start to get</span><span>
# errors </span><span>for</span> write operations, and <span>this</span><span> may even lead to DB inconsistency.

#

# maxmemory </span><bytes><span>

 maxmemory </span><bytes><span>指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory

# </span><span>is</span> reached?<span> You can select among five behavior:

# 

# </span><span>volatile</span>-lru -> remove the key with an expire <span>set</span><span>using</span><span> an LRU algorithm

# allkeys</span>-lru -><span> remove any key accordingly to the LRU algorithm

# </span><span>volatile</span>-random -> remove a random key with an expire <span>set</span><span>

# allkeys</span>->random -><span> remove a random key, any key

# </span><span>volatile</span>-ttl -><span> remove the key with the nearest expire time (minor TTL)

# noeviction </span>-> don<span>‘</span><span>t expire at all, just return an error on write operations</span><span>
# 

# Note: with all the kind of policies, Redis will </span><span>return</span><span> an error on write

#       operations, when there are not suitable keys </span><span>for</span><span> eviction.

#

#       At the date of writing </span><span>this</span> commands are: <span>set</span><span> 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 </span><span>default</span><span>is</span><span>:

#

# maxmemory</span>-policy <span>volatile</span>-<span>lru

 

# LRU and minimal TTL algorithms are not precise algorithms but approximated

# algorithms (</span><span>in</span> order to save memory), so you can select <span>as</span><span> well the sample

# size to check. For instance </span><span>for</span><span>default</span><span> Redis will check three keys and

# pick the one that was used less recently, you can change the sample size

# </span><span>using</span><span> the following configuration directive.

#

# maxmemory</span>-samples <span>3</span><span>

 

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

 

# By </span><span>default</span><span> Redis asynchronously dumps the dataset on disk. If you can live

# with the idea that the latest records will be lost </span><span>if</span><span> something like a crash

# happens </span><span>this</span><span>is</span><span> the preferred way to run Redis. If instead you care a lot

# about your data and don</span><span>‘</span><span>t want to that a single record can get lost you should</span><span>
# enable the append only mode: when </span><span>this</span> mode <span>is</span><span> enabled Redis will append

# every write operation received </span><span>in</span><span> the file appendonly.aof. This file will

# be read on startup </span><span>in</span> order to rebuild the full dataset <span>in</span><span> memory.

#

# Note that you can have both the async dumps and the append only file </span><span>if</span><span> you

# like (you have to comment the </span><span>"</span><span>save</span><span>"</span><span> statements above to disable the dumps).

# Still </span><span>if</span> append only mode <span>is</span><span> enabled Redis will load the data from the

# log file at startup ignoring the dump.rdb file.

#

# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append

# log file </span><span>in</span><span> background when it gets too big.

 

appendonly no

appendonly no指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no

# The name of the append only file (</span><span>default</span>: <span>"</span><span>appendonly.aof</span><span>"</span><span>)

# appendfilename appendonly.aof

 appendfilename appendonly.aof指定更新日志文件名,默认为appendonly.aof

# The fsync() call tells the Operating System to actually write data on disk

# instead to wait </span><span>for</span> more data <span>in</span><span> the output buffer. Some OS will really flush 

# data on disk, some other OS will just </span><span>try</span> to <span>do</span><span> it ASAP.

#

# Redis supports three different modes:

#

# no: don</span><span>‘</span><span>t fsync, just let the OS flush the data when it wants. Faster.</span><span>
# always: fsync after every write to the append only log . Slow, Safest.

# everysec: fsync only </span><span>if</span><span> one second passed since the last fsync. Compromise.

#

# The </span><span>default</span><span>is</span><span>"</span><span>everysec</span><span>"</span> that<span>‘</span><span>s usually the right compromise between</span><span>
# speed and data safety. It</span><span>‘</span><span>s up to you to understand if you can relax this to</span><span>
# </span><span>"</span><span>no</span><span>"</span><span> that will will let the operating system flush the output buffer when

# it wants, </span><span>for</span> better performances (but <span>if</span><span> you can live with the idea of

# some data loss consider the </span><span>default</span> persistence mode that<span>‘</span><span>s snapshotting),</span><span>
# or on the contrary, use </span><span>"</span><span>always</span><span>"</span> that<span>‘</span><span>s very slow but a bit safer than</span><span>
# everysec.

#

# If unsure, use </span><span>"</span><span>everysec</span><span>"</span><span>.

 

# appendfsync always

appendfsync everysec

# appendfsync no

指定更新日志条件,共有3个可选值:

no:表示等操作系统进行数据缓存同步到磁盘(快)

always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)

everysec:表示每秒同步一次(折衷,默认值)

# When the AOF fsync policy </span><span>is</span><span>set</span><span> to always or everysec, and a background

# saving process (a background save or AOF log background rewriting) </span><span>is</span><span>

# performing a lot of I</span>/O against the disk, <span>in</span><span> some Linux configurations

# Redis may block too </span><span>long</span> on the fsync() call. Note that there <span>is</span> no fix <span>for</span><span>

# </span><span>this</span> currently, <span>as</span> even performing fsync <span>in</span><span> a different thread will block

# our synchronous write(</span><span>2</span><span>) call.

#

# In order to mitigate </span><span>this</span> problem it<span>‘</span><span>s possible to use the following option</span><span>
# that will prevent fsync() from being called </span><span>in</span> the main process <span>while</span><span> a

# BGSAVE or BGREWRITEAOF </span><span>is</span><span>in</span><span> progress.

#

# This means that </span><span>while</span> another child <span>is</span> saving the durability of Redis <span>is</span><span>

# the same </span><span>as</span><span>"</span><span>appendfsync none</span><span>"</span>, that <span>in</span> pratical terms means that it <span>is</span><span>

# possible to lost up to </span><span>30</span> seconds of log <span>in</span><span> the worst scenario (with the

# </span><span>default</span><span> Linux settings).

# 

# If you have latency problems turn </span><span>this</span> to <span>"</span><span>yes</span><span>"</span>. Otherwise leave it <span>as</span><span>

# </span><span>"</span><span>no</span><span>"</span> that <span>is</span><span> the safest pick from the point of view of durability.

no</span>-appendfsync-on-<span>rewrite no

 

# Automatic rewrite of the append only file.

# Redis </span><span>is</span><span> able to automatically rewrite the log file implicitly calling

# BGREWRITEAOF when the AOF log size will growth by the specified percentage.

# 

# This </span><span>is</span><span> how it works: Redis remembers the size of the AOF file after the

# latest rewrite (or </span><span>if</span><span> no rewrite happened since the restart, the size of

# the AOF at startup </span><span>is</span><span> used).

#

# This </span><span>base</span> size <span>is</span> compared to the current size. If the current size <span>is</span><span>

# bigger than the specified percentage, the rewrite </span><span>is</span><span> triggered. Also

# you need to specify a minimal size </span><span>for</span> the AOF file to be rewritten, <span>this</span><span>

# </span><span>is</span> useful to avoid rewriting the AOF file even <span>if</span><span> the percentage increase

# </span><span>is</span> reached but it <span>is</span><span> still pretty small.

#

# Specify a precentage of zero </span><span>in</span><span> order to disable the automatic AOF

# rewrite feature.

 

auto</span>-aof-rewrite-percentage <span>100</span><span>

auto</span>-aof-rewrite-min-<span>size 64mb

 

################################## SLOW LOG ###################################

 

# The Redis Slow Log </span><span>is</span><span> a system to log queries that exceeded a specified

# execution time. The execution time does not include the I</span>/<span>O operations

# like talking with the client, sending the reply and so forth,

# but just the time needed to actually execute the command (</span><span>this</span><span>is</span><span> the only

# stage of command execution </span><span>where</span> the thread <span>is</span><span> blocked and can not serve

# other requests </span><span>in</span><span> the meantime).

# 

# You can configure the slow log with two parameters: one tells Redis

# what </span><span>is</span> the execution time, <span>in</span> microseconds, to exceed <span>in</span> order <span>for</span><span> the

# command to </span><span>get</span> logged, and the other parameter <span>is</span><span> the length of the

# slow log. When a </span><span>new</span> command <span>is</span> logged the oldest one <span>is</span><span> removed from the

# queue of logged commands.

 

# The following time </span><span>is</span> expressed <span>in</span> microseconds, so <span>1000000</span><span>is</span><span> equivalent

# to one second. Note that a negative number disables the slow log, </span><span>while</span><span>

# a value of zero forces the logging of every command.

slowlog</span>-log-slower-than <span>10000</span><span>

 

# There </span><span>is</span> no limit to <span>this</span><span> length. Just be aware that it will consume memory.

# You can reclaim memory used by the slow log with SLOWLOG RESET.

slowlog</span>-max-len <span>1024</span><span>

 

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

 

### WARNING</span>! Virtual Memory <span>is</span> deprecated <span>in</span> Redis <span>2.4</span><span>

### The use of Virtual Memory </span><span>is</span><span> strongly discouraged.

 

### WARNING</span>! Virtual Memory <span>is</span> deprecated <span>in</span> Redis <span>2.4</span><span>

### The use of Virtual Memory </span><span>is</span><span> strongly discouraged.

 

# Virtual Memory allows Redis to work with datasets bigger than the actual

# amount of RAM needed to hold the whole dataset </span><span>in</span><span> memory.

# In order to </span><span>do</span> so very used keys are taken <span>in</span> memory <span>while</span><span> the other keys

# are swapped into a swap file, similarly to what operating systems </span><span>do</span><span>

# with memory pages.

#

# To enable VM just </span><span>set</span><span>‘</span><span>vm-enabled</span><span>‘</span> to yes, and <span>set</span><span> the following three

# VM parameters accordingly to your needs.

 

vm</span>-<span>enabled no

指定是否启用虚拟内存机制,默认值为no,简单的介绍一下,VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中(在后面的文章我会仔细分析Redis的VM机制)

# vm</span>-<span>enabled yes

 

# This </span><span>is</span><span> the path of the Redis swap file. As you can guess, swap files

# can</span><span>‘</span><span>t be shared by different Redis instances, so make sure to use a swap</span><span>
# file </span><span>for</span> every redis process you are running. Redis will complain <span>if</span><span> the

# swap file </span><span>is</span> already <span>in</span><span> use.

#

# The best kind of storage </span><span>for</span> the Redis swap file (that<span>‘</span><span>s accessed at random) </span><span>
# </span><span>is</span><span> a Solid State Disk (SSD).

#

# </span>*** WARNING *** <span>if</span> you are <span>using</span> a shared hosting the <span>default</span><span> of putting

# the swap file under </span>/tmp <span>is</span><span> not secure. Create a dir with access granted

# only to Redis user and configure Redis to create the swap file there.

vm</span>-swap-file /tmp/<span>redis.swap

虚拟内存文件路径,默认值为</span>/tmp/<span>redis.swap,不可多个Redis实例共享

# vm</span>-max-<span>memory configures the VM to use at max the specified amount of

# RAM. Everything that deos not fit will be swapped on disk </span>*<span>if</span>*<span> possible, that

# </span><span>is</span>, <span>if</span> there <span>is</span> still enough contiguous space <span>in</span><span> the swap file.

#

# With vm</span>-max-memory <span>0</span><span> the system will swap everything it can. Not a good

# </span><span>default</span>, just specify the max amount of RAM you can <span>in</span> bytes, but it<span>‘</span><span>s</span><span>
# better to leave some margin. For instance specify an amount of RAM

# that</span><span>‘</span><span>s more or less between 60 and 80% of your free RAM.</span><span>
vm</span>-max-memory <span>0</span><span>

将所有大于vm</span>-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据 就是keys),也就是说,当vm-max-<span>memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0

# Redis swap files </span><span>is</span> split into pages. An <span>object</span> can be saved <span>using</span><span> multiple

# contiguous pages, but pages can</span><span>‘</span><span>t be shared between different objects.</span><span>
# So </span><span>if</span> your page <span>is</span> too big, small objects swapped <span>out</span><span> on disk will waste

# a lot of space. If you page </span><span>is</span> too small, there <span>is</span> less space <span>in</span><span> the swap

# file (assuming you configured the same number of total swap file pages).

#

# If you use a lot of small objects, use a page size of </span><span>64</span> or <span>32</span><span> bytes.

# If you use a lot of big objects, use a bigger page size.

# If unsure, use the </span><span>default</span><span> :)

vm</span>-page-size <span>32</span><span>

Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm</span>-page-<span>size是要根据存储的 数据大小来设定的,作者建议如果存储很多小对象,page大小最好设置为32或者64bytes;如果存储很大大对象,则可以使用更大的page,如果不 确定,就使用默认值

# Number of total memory pages </span><span>in</span><span> the swap file.

# Given that the page table (a bitmap of free</span>/used pages) <span>is</span> taken <span>in</span><span> memory,

# every </span><span>8</span> pages on disk will consume <span>1</span><span>byte</span><span> of RAM.

#

# The total swap size </span><span>is</span> vm-page-size * vm-<span>pages

#

# With the </span><span>default</span> of <span>32</span>-bytes memory pages and <span>134217728</span><span> pages Redis will

# use a </span><span>4</span> GB swap file, that will use <span>16</span> MB of RAM <span>for</span><span> the page table.

#

# It</span><span>‘</span><span>s better to use the smallest acceptable value for your application,</span><span>
# but the </span><span>default</span><span>is</span> large <span>in</span> order to work <span>in</span><span> most conditions.

vm</span>-pages <span>134217728</span><span>

设置swap文件中的page数量,由于页表(一种表示页面空闲或使用的bitmap)是在放在内存中的,,在磁盘上每8个pages将消耗1byte的内存。

# Max number of VM I</span>/<span>O threads running at the same time.

# This threads are used to read</span>/write data from/<span>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 </span><span>if</span> they can<span>‘</span><span>t help with</span><span>
# I</span>/O itself <span>as</span><span> the physical device may not be able to couple with many

# reads</span>/<span>writes operations at the same time.

#

# The special value of </span><span>0</span> turn off threaded I/<span>O and enables the blocking

# Virtual Memory implementation.

vm</span>-max-threads <span>4</span><span>

设置访问swap文件的线程数,最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟。默认值为4

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

 

# Hashes are encoded </span><span>in</span><span> a special way (much more memory efficient) when they

# have at max a given numer of elements, and the biggest element does not

# exceed a given threshold. You can configure </span><span>this</span><span> limits with the following

# configuration directives.

hash</span>-max-zipmap-entries <span>512</span><span>

hash</span>-max-zipmap-value <span>64</span><span>

指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法

# Similarly to hashes, small lists are also encoded </span><span>in</span> a special way <span>in</span><span> order

# to save a lot of space. The special representation </span><span>is</span><span> only used when

# you are under the following limits:

list</span>-max-ziplist-entries <span>512</span><span>

list</span>-max-ziplist-value <span>64</span><span>

 

# Sets have a special encoding </span><span>in</span> just one <span>case</span>: when a <span>set</span><span>is</span><span> composed

# of just strings that happens to be integers </span><span>in</span> radix <span>10</span><span>in</span><span> the range

# of </span><span>64</span><span> bit signed integers.

# The following configuration setting sets the limit </span><span>in</span><span> the size of the

# </span><span>set</span><span>in</span> order to use <span>this</span><span> special memory saving encoding.

</span><span>set</span>-max-intset-entries <span>512</span><span>

 

# Similarly to hashes and lists, sorted sets are also specially encoded </span><span>in</span><span>

# order to save a lot of space. This encoding </span><span>is</span><span> only used when the length and

# elements of a sorted </span><span>set</span><span> are below the following limits:

zset</span>-max-ziplist-entries <span>128</span><span>

zset</span>-max-ziplist-value <span>64</span><span>

 

# Active rehashing uses </span><span>1</span> millisecond every <span>100</span> milliseconds of CPU time <span>in</span><span>

# order to help rehashing the main Redis hash table (the one mapping top</span>-<span>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 </span><span>is</span> rhashing, the more rehashing <span>"</span><span>steps</span><span>"</span> are performed, so <span>if</span><span> the

# server </span><span>is</span> idle the rehashing <span>is</span> never complete and some more memory <span>is</span><span> used

# by the hash table.

# 

# The </span><span>default</span><span>is</span> to use <span>this</span> millisecond <span>10</span> times every second <span>in</span><span> order to

# active rehashing the main dictionaries, freeing memory when possible.

#

# If unsure:

# use </span><span>"</span><span>activerehashing no</span><span>"</span><span>if</span> you have hard latency requirements and it <span>is</span><span>

# not a good thing </span><span>in</span><span> your environment that Redis can reply form time to time

# to queries with </span><span>2</span><span> milliseconds delay.

#

# use </span><span>"</span><span>activerehashing yes</span><span>"</span><span>if</span> you don<span>‘</span><span>t have such hard requirements but</span><span>
# want to free memory asap when possible.

activerehashing yes

 

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

 

# Include one or more other config files here.  This </span><span>is</span> useful <span>if</span><span> you

# have a standard template that goes to all redis server but also need

# to customize a few per</span>-<span>server settings.  Include files can include

# other files, so use </span><span>this</span><span> wisely.

#

# include </span>/path/to/<span>local.conf

# include </span>/path/to/other.conf

 

原文:http://www.cnblogs.com/yixi978/p/5752671.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐