我希望设置两个Redis实例,因为我对要在Redis中存储的数据有不同的要求。虽然有时我不介意失去一些作为缓存数据使用的数据,但在某些情况下,例如当我使用将作业存储到Redis中以执行的Python RQ时,我想避免丢失一些数据。
以下是实现此目标的主要设置。
您认为呢?
我忘记了重要的东西吗?
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(Redis官方文档)
- https://raw.githubusercontent.com/antirez/redis/2.8/redis.conf(Redis配置文件示例)
- http://fr.slideshare.net/eugef/redis-persistence-in-practice-1(Redis持久化实践介绍)
- http://oldblog.antirez.com/post/redis-persistence-demystified.html(Redis持久化机制解析)
- 如何在Redis中执行持久化存储?
- https://www.packtpub.com/books/content/implementing-persistence-redis-intermediate(Redis持久化实现介绍)