类:Mongo::ClusterTime Private
- 继承:
-
BSON::Document
- 对象
- BSON::Document
- Mongo::ClusterTime
- 包括:
- Comparable
- 定义于:
- lib/ Mongo/cluster_time.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
ClusterTime 封装了集群时间存储和操作。
对集群时间执行的主节点 (primary node in the replica set)操作是将其提前:给定另一个集群时间,选择两个时间中较新的一个。
此类提供了用于确定哪个集群时间较新的比较方法,并在集群时间文档中缺少实际时间时以 lint 模式提供诊断。
在命名空间下定义
模块: 消费者
类方法摘要折叠
-
。 [] (doc) ⇒ 对象
private
将BSON::Document 转换为 ClusterTime。
实例方法摘要折叠
-
# <=> (other) ⇒ 对象
private
通过比较时间戳来比较两个 ClusterTime 实例。
-
# == (other) ⇒ 对象
private
通过比较时间戳来比较两个 ClusterTime 实例。
-
# advance (other) ⇒ 对象
private
将接收器中的集群时间提前到
other中的集群时间。 -
#initialize(elements = nil) ⇒ ClusterTime
构造函数
private
ClusterTime 的新实例。
构造函数详情
#initialize (elements = nil) ⇒ ClusterTime
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 ClusterTime 的新实例。
31 32 33 34 35 36 37 |
# File 'lib/ Mongo/cluster_time.rb', line 31 def 初始化(元素 = nil) 超 return 除非 Lint.已启用? && !self[' clusterTime '] 提高 ArgumentError, ' Creating a 集群 time without clusterTime 字段 ' end |
类方法详细信息
。 [] (doc) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
将BSON::Document 转换为 ClusterTime。
doc 可以为 nil,在这种情况下返回 nil。
81 82 83 84 85 86 87 |
# File 'lib/ Mongo/cluster_time.rb', line 81 def [ ](doc) if doc.nil? || doc.is_a?(ClusterTime) doc else ClusterTime.new(doc) end end |
实例方法详细信息
# <=> (other) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
通过比较时间戳来比较两个 ClusterTime 实例。
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ Mongo/cluster_time.rb', line 56 def <=>(其他) if self[' clusterTime '] && 其他[' clusterTime '] self[' clusterTime '] <=> 其他[' clusterTime '] elsif !self[' clusterTime '] 提高 ArgumentError, "当接收器缺少 clusterTime key 时,无法比较集群时间: #{ inspect } " else 其他[' clusterTime '] 提高 ArgumentError, " Cannot比较集群时间,当 other 缺少 clusterTime key: #{ other.inspect} " end end |
# == (other) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
通过比较时间戳来比较两个 ClusterTime 实例。
68 69 70 71 72 73 74 75 |
# File 'lib/ Mongo/cluster_time.rb', line 68 def ==(其他) if self[' clusterTime '] && 其他[' clusterTime '] && self[' clusterTime '] == 其他[' clusterTime '] true else false end end |
# advance (other) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
将接收器中的集群时间提前到other中的集群时间。
other 可以为零或晚于接收器中的集群时间;在这些情况下,接收者会按原样返回。 如果接收器提前,则返回一个新的 ClusterTime 对象。
返回值为 nil 或 ClusterTime实例。
46 47 48 49 50 51 52 53 |
# File 'lib/ Mongo/cluster_time.rb', line 46 def advance(其他) if self[' clusterTime '] && 其他[' clusterTime '] && 其他[' clusterTime '] > self[' clusterTime '] ClusterTime[其他] else self end end |