caching - 2 个 Redis 实例 : as a cache and as a persistent datastore

标签 caching redis

我想设置 2 个 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

来源:

最佳答案

我认为您的持久性选项过于激进 - 但这主要取决于数据的性质和数量。

对于缓存,使用 RDB 是个好主意,但请记住,根据数据量,将内存中的内容转储到磁盘上是有代价的。在我的系统上,Redis 可以以 400 MB/s 的速度写入内存数据,但请注意,数据可能会(或可能不会)被压缩,可能(或可能不会)使用密集数据结构,因此您的里程会有所不同。使用您的设置,支持大量写入的缓存将每分钟生成一次转储。您必须检查您拥有的卷,转储持续时间远低于该分钟(大约 6-10 秒就可以了)。实际上,我建议只保留保存 900 1 并删除其他保存行。即使每 15 分钟一次转储也被认为过于频繁,尤其是当您的 SSD 硬件会逐渐磨损时。

对于持久存储,您还需要定义 dir 参数(因为它还控制 AOF 文件的位置)。 appendfsync always 选项对于大多数用途来说是矫枉过正且速度太慢,除非您的吞吐量非常低。您应该将其设置为每秒。如果即使在系统崩溃的情况下你也不能丢失一点数据,那么使用 Redis 作为存储后端并不是一个好主意。最后,您可能必须将 auto-aof-rewrite-percentage 和 auto-aof-rewrite-min-size 调整为 Redis 实例必须维持的写入吞吐量水平。

关于caching - 2 个 Redis 实例 : as a cache and as a persistent datastore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452804/

相关文章:

ruby-on-rails - rails fresh_when/stale?用法

javascript - 如何制作pjax :popstate work like a simple PJAX call

java - 如何停止 LOCAL Ignite 缓存的 "Ignoring query projection"警告

ruby-on-rails - Rails、ActionController::Live、Puma:ThreadError

data-structures - Redis - 一个一个地插入字符串并一次全部删除的数据结构

android - 加密 Android 上的 WebView 缓存

c# - 在 asp.net 中缓存(输出)?

redis - 如何正确计算 hash-max-ziplist-value?

linux - redis-cli 使用模式执行 ttl 命令

asp.net - 这是 StackExchange Redis 流水线的良好实现吗?