redis安装配置使用过程的遇到的各种问题

本文详细介绍了Redis在Windows环境下的正确启动方法及配置文件的使用,并深入探讨了持久化策略的具体设置,包括如何配置持久化文件名及保存策略。

###1.下载安装后,如何正确的启动redis 直接双击是不好的,因为没有指定配置文件,采用默认的配置,因此最好的做法是启动的同时指定配置文件。这就不奇怪,我在Windows中修改了n遍config文件却一直不生效。更恶心的是,安装结束后由两个配置文件,还不知道哪个是,原来是启动的时候选择的。

C:\Program Files\Redis>redis-server.exe redis.windows.conf

###2.正确的配置持久化的文件名 默认是有个持久化策略的,至于具体啥问题也不去研究。我就是用来做存储的,不出问题就行。真是糟糕的学习方式,土地主一般。 在配置持久化文件的时候有两个配置项:

# The filename where to dump the DB
dbfilename db\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.
dir D:\data\redis\

dbfilename真的只是文件名,不要自作多情的以为是相对路径。所以上面的做法不对。应该是:

dbfilename dump.rdb

持久化的策略,默认是这样的:


################################ 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 900 1
save 300 10
save 60 10000

就是说,在900s内,一个key发生改变,则持久化到磁盘。相应的就是300s内10次改变,60s内10000次改变。所以,如果redis关掉了还是会丢东西的。比如刚刚持久化到磁盘,你写入了10个以上10000个一下的key,然后还不到300s,redi挂了,这些数据就么了。

顺便记录下持久化的日志格式:

[5948] 06 Nov 13:54:05.270 # Server started, Redis version 3.0.501
[5948] 06 Nov 13:54:05.277 * The server is now ready to accept connections on port 6379
[5948] 06 Nov 13:59:06.064 * 10 changes in 300 seconds. Saving...
[5948] 06 Nov 14:02:53.483 * Background saving started by pid 8460
[5948] 06 Nov 14:02:53.584 # fork operation complete
[5948] 06 Nov 14:02:53.585 * Background saving terminated with success

其实早就应该看备份命令

save
bgsave

###参考

转载于:https://my.oschina.net/ilikesss/blog/791107

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值