我想設置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