Redis可用性和CAP定理

Redis availability and CAP theorem

在CAP定理中,Redis被指定为缺乏可用性(具有分区容忍性和一致性)的数据库。

但是Redis在很多地方都被认为是高可用键值存储。

什么是对的?如果您能提供深入的答案,我将不胜感激。

首先我要说没有 'CA' 类别。在没有网络分区的情况下,大多数系统都是 CA。

CAP 定理适用于分布式数据存储,并在网络分区 (P) 发生时生效。它表示当 (P) 发生时,分布式数据存储必须在一致性 (C) 或可用性 (A) 之间做出选择。

即当 P 发生时,它将是 PA 或 PC。

RDBMS 曾经是 PC,但随着时间的推移,他们也开始支持 PA。

具体来说 Redis,高可用性不仅仅是分区容错。 Redis 具有 Master Slave 架构,如果 Master 出现故障,则 Redis Sentinels 会提升一个 Slave 成为新的 Master,从而使整个解决方案具有高可用性。由于多种原因(例如内存不足),主机可能会失败(或变得不可用),这不一定是由于网络分区造成的。

然后是网络分区(P)的情况,如果(P)发生那么Redis在少数分区中变得不可用。这就是为什么从 CAP 的角度来看,Redis 是 CP,因为它在少数分区中变得不可用。请注意,它仍将在多数分区中可用。

您可以阅读有关 Redis High Availability here 的更多信息。有关分区的详细信息,请参阅标题为 "Consistency under partitions" 的段落。

Redis 也被称为最终一致性,因为当 (P) 发生时,少数分区仍然可用几秒钟,并且在此期间对少数分区所做的任何写入最终都会被丢弃。

根据《Redis精要》一书第170页:

Since Redis Sentinel and Redis Cluster are distributed systems, it is fair to analyze them using the CAP theorem. Network partitions are unavoidable in a distributed system, so it should ensure either consistency or availability; that is, it should be either CP or AP.

Theoretically, Redis Sentinel and Redis Cluster are neither consistent nor available under network partitions. However, there are some configurations that can minimize the consistency and availability problems. They cannot provide availability because there is a quorum that needs to agree on a master election, and depending on the quorum's decision, part of the system may become unavailable.

They cannot provide consistency under network partitions, for example, when two or more partitions accept writes at the same time. When the network heals and the partitions are joined, some of those writes will be lost (conflicts are not automatically solved, nor are they exposed for clients).

希望对you.The在线图书有所帮助:(https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781784392451/9/ch09lvl1sec52/the-cap-theorem)