redis windows下的环境搭建
先说下安装吧!感觉这东西跟mongodb差不多,安装和布置挺简单,
下载地址:https://github.com/dmajkic/redis/downloads 下载下来的包里有两个,
一个是32位的,一个是64位的。根据自己的实情情况选择,我的是32bit,
把这个文件夹复制到其它地方,比如D:\redis 目录下。
打开一个cmd窗口 使用cd命令切换目录到d:\redis 运行 redis-server.exe redis.conf
如果想方便的话,可以把redis的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个redis.conf可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:
![](http://up.2cto.com/2012/0402/20120402111041385.png)
![](http://up.2cto.com/2012/0402/20120402111041385.png)
这时候别启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了
切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 出现下图:
![](http://up.2cto.com/2012/0402/20120402111041181.png)
![](http://up.2cto.com/2012/0402/20120402111041181.png)
这时候,就已经完成配置了,现在说下它的的redis.conf配置文件。下面是相关项的说明,
001
# Redis configuration file example
002
003
# Note on units: when memory size is needed, it is possible to specifiy
004
# it in the usual form of 1k 5GB 4M and so forth:
005
#
006
# 1k => 1000 bytes
007
# 1kb => 1024 bytes
008
# 1m => 1000000 bytes
009
# 1mb => 1024*1024 bytes
010
# 1g => 1000000000 bytes
011
# 1gb => 1024*1024*1024 bytes
012
#
013
# units are case insensitive so 1GB 1Gb 1gB are all the same.
014
015
# By default Redis does not run as a daemon. Use 'yes' if you need it.
016
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
017
daemonize no
018
Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
019
020
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
021
# default. You can specify a custom pid file location here.
022
pidfile /var/run/redis.pid
023
当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定
024
# Accept connections on the specified port, default is 6379.
025
# If port 0 is specified Redis will not listen on a TCP socket.
026
port 6379
027
指定Redis监听端口,默认端口为6379
028
# If you want you can bind a single interface, if the bind option is not
029
# specified all the interfaces will listen for incoming connections.
030
#
031
# bind 127.0.0.1
032
绑定的主机地址
033
# Specify the path for the unix socket that will be used to listen for
034
# incoming connections. There is no default, so Redis will not listen
035
# on a unix socket when not specified. www.2cto.com
036
#
037
# unixsocket /tmp/redis.sock
038
# unixsocketperm 755
039
040
# Close the connection after a client is idle for N seconds (0 to disable)
041
timeout 0
042
当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
043
# Set server verbosity to 'debug'
044
# it can be one of:
045
# debug (a lot of information, useful for development/testing)
046
# verbose (many rarely useful info, but not a mess like the debug level)
047
# notice (moderately verbose, what you want in production probably)
048
# warning (only very important / critical messages are logged)
049
loglevel verbose
050
指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
051
# Specify the log file name. Also 'stdout' can be used to force
052
# Redis to log on the standard output. Note that if you use standard
053
# output for logging but daemonize, logs will be sent to /dev/null
054
logfile stdout
055
日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给/dev/null
056
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
057
# and optionally update the other syslog parameters to suit your needs.
058
# syslog-enabled no
059
060
# Specify the syslog identity.
061
# syslog-ident redis
062
063
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
064
# syslog-facility local0
065
066
# Set the number of databases. The default database is DB 0, you can select
067
# a different one on a per-connection basis using SELECT <dbid> where
068
# dbid is a number between 0 and 'databases'-1
069
databases 16 www.2cto.com
070
设置数据库的数量,默认数据库为0,可以使用SELECT <dbid>命令在连接上指定数据库id
071
################################ SNAPSHOTTING #################################
072
#
073
# Save the DB on disk:
074
#
075
# save <seconds> <changes>
076
#
077
# Will save the DB if both the given number of seconds and the given
078
# number of write operations against the DB occurred.
079
#
080
# In the example below the behaviour will be to save:
081
# after 900 sec (15 min) if at least 1 key changed
082
# after 300 sec (5 min) if at least 10 keys changed
083
# after 60 sec if at least 10000 keys changed
084
#
085
# Note: you can disable saving at all commenting all the "save" lines.
086
087
save 900 1
088
save 300 10
089
save 60 10000
090
分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。
091
指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
092
# Compress string objects using LZF when dump .rdb databases?
093
# For default that's set to 'yes' as it's almost always a win.
094
# If you want to save some CPU in the saving child set it to 'no' but
095
# the dataset will likely be bigger if you have compressible values or keys.
096
rdbcompression yes
097
指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大
098
# The filename where to dump the DB
099
dbfilename dump.rdb
100
指定本地数据库文件名,默认值为dump.rdb
101
# The working directory.
102
#
103
# The DB will be written inside this directory, with the filename specified
104
# above using the 'dbfilename' configuration directive.
105
#
106
# Also the Append Only File will be created inside this directory.
107
#
108
# Note that you must specify a directory here, not a file name.
109
dir ./
110
指定本地数据库存放目录
111
################################# REPLICATION #################################
112
113
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
114
# another Redis server. Note that the configuration is local to the slave
115
# so for example it is possible to configure the slave to save the DB with a
116
# different interval, or to listen to another port, and so on. www.2cto.com
117
#
118