这个问题听起来很像:this one ,但我相信不是。虽然这个问题非常具体,但我认为它不足以解决我的疑问。
我正在尝试为我拥有的应用程序部署设置 Redis 集群。我使用 Redis 存储各种信息,例如 session 信息、计划作业元信息等 到目前为止,我一直在使用单节点实例。但是,我正在考虑迁移到用于 HA 的 Redis 集群。我知道 Redis 是单线程的,只提供尽力而为的一致性,而不是强一致性提供者。因此,就我在单个节点上而言,我在一致性方面没有任何问题(除了容错方面)。但是,当我转移到集群设置时,这仍然不是真的(至少根据我的理解)。
我的问题如下:
最佳答案
我可能无法深入回答所有问题。在详细了解您的问题之前;
可用性和一致性之间的关系不仅与 Redis 有关,而且是分布式系统的核心原则之一。可以用CAP Theorem解释.是的,你会妥协 consistency
高availability
因为you can't sacrifice partition tolerance
在分布式系统中。一些分布式数据库技术提供配置以与仲裁可用性的权衡可用性具有“强”一致性(例如 Cassandra
)。
如果你想要 HA,那么 Redis 集群可能不是你想要的。当您需要将数据分片(分配负载)到多个节点时,Redis Cluster 是一个很好的解决方案。当您达到实例的内存限制时,这是“必须的”。您可能需要的是 Redis Sentinel .
Redis Sentinel
provideshigh availability
for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures.
quorum
根据业务需要。它不会是 Elixir ,总是需要权衡取舍。 The quorum is only used to detect the failure. In order to actually perform a failover, one of the Sentinels need to be elected leader for the failover and be authorized to proceed. This only happens with the vote of the majority of the Sentinel processes.
If a master is not working as expected, Sentinel can start a failover process where a replica is promoted to master, the other additional replicas are reconfigured to use the new master, and the applications using the Redis server are informed about the new address to use when connecting.
关于caching - 将 session 信息存储在 Redis 集群中是否安全高效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62998033/