我想设置2个Redis实例,因为我对要存储在Redis中的数据有不同的要求。虽然我有时不介意丢失一些主要用作缓存数据的数据,但我希望避免在某些情况下丢失一些数据,例如,当我使用存储到Redis中的要执行的作业的Python RQ时。Redis的2个实例:作为缓存和作为持久数据存储
我在下面提到了实现这样一个目标的主要设置。
您认为如何?
我忘记了什么重要吗?
1)的Redis作为高速缓存
# Snapshotting to not rebuild the whole cache if it has to restart
# Be reasonable to not decrease the performances
save 900 1
save 300 10
save 60 10000
# Define a max memory and remove less recently used keys
maxmemory X # To define according needs
maxmemory-policy allkeys-lru
maxmemory-samples 5
# The rdb file name
dbfilename dump.rdb
# The working directory.
dir ./
# Make sure appendonly is disabled
appendonly no
2)的Redis作为持久数据存储
# Disable snapshotting since we will save each request, see appendonly
save ""
# No limit in memory
# How to disable it? By not defining it in the config file?
maxmemory
# Enable appendonly
appendonly yes
appendfilename redis-aof.aof
appendfsync always # Save on each request to not lose any data
no-appendfsync-on-rewrite no
# Rewrite the AOL file, choose a good min size based on the approximate size of the DB?
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 32mb
aof-rewrite-incremental-fsync yes
aof-load-truncated yes
来源:
- http://redis.io/topics/persistence
- https://raw.githubusercontent.com/antirez/redis/2.8/redis.conf
- http://fr.slideshare.net/eugef/redis-persistence-in-practice-1
- http://oldblog.antirez.com/post/redis-persistence-demystified.html
- How to perform Persistence Store in Redis?
- https://www.packtpub.com/books/content/implementing-persistence-redis-intermediate
为什么持久性选项过于激进?我不想丢失关于这个Redis实例的任何数据。那么这些设置是否合适?我不会存储很多内容,它不会成为我的主要数据存储区。 至于缓存,我会将保存更改为“1800 1”。这应该够了。作为缓存,我不介意丢失一些数据。谢谢 – Michael 2014-10-20 20:09:47
这些设置适合避免丢失任何数据,但实际上价格太高。每次写操作都会导致同步fsync,导致Redis总冻结几毫秒。在这几毫秒内,实例将完全无响应,而不仅仅是单个连接 - 对于所有连接。一般来说,这不是一个好主意。 – 2014-10-20 22:03:45