2015-04-03 111 views
1

我想将redis纯粹用作缓存。为确保如此,我必须在redis.conf中禁用哪些选项。我读了默认情况下redis持久数据(AOF和rdb文件,也许更多)。即使设置为过期的键也是如此。 是否坚持被设置为过期的数据是矛盾的?将redis配置为缓存

回答

0

Redis将其所有数据存储在RAM中,但不时将其转储到持久存储(HDD/SDD)。这个过程被称为快照。

你可以在your redis.conf file配置快照的频率(见SNAPSHOTTING部分):

# 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 

所以,如果你想完全禁用快照,您应该删除或redis.conf文件发表评论所有save指令。

+0

确定最近,我偶然发现此 [链接] http://oldblog.antirez.com/post/redis-persistence-demystified.html 它说,“执行主当RDB快照还用于通过Redis的 - >从属同步。“ 因此,如果我禁用快照会阻止我的主从同步?! 也任何想法如何禁用AOF持久性,我试图设置“appendonly”为否,但我不知道如果这是足够的。 除了快照和追加只有相关参数(在redis.conf中)还有其他我需要照顾的事情/参数吗? – user2713255 2015-04-03 11:51:45

+0

Redis使用快照执行**初始**同步。禁用RDB快照只会禁用自动快照,不会影响像'SYNC'(复制)或'BGSAVE'(手动快照)的命令。 – 2015-04-03 12:19:51

+0

至于AOF,它应该足以将'appendonly'设置为'no',尽管它在redis默认配置中没有启用。 – 2015-04-03 12:21:14