[C#] 纯文本查看 复制代码
// 摘要:
// Represents read preference modes.
public enum ReadPreferenceMode
{
// 默认参数,只从主节点上进行读取操作;
Primary = 0,
// 大部分从主节点上读取数据,只有主节点不可用时从secondary节点读取数据。
PrimaryPreferred = 1,
// 只从secondary节点上进行读取操作,存在的问题是secondary节点的数据会比primary节点数据“旧”。
Secondary = 2,
// 优先从secondary节点进行读取操作,secondary节点不可用时从主节点读取数据;
SecondaryPreferred = 3,
// 不管是主节点、secondary节点,从网络延迟最低的节点上读取数据。
Nearest = 4,
}
[C#] 纯文本查看 复制代码
switch (strReadPreference)
{
case "Nearest":
set.ReadPreference = new ReadPreference(ReadPreferenceMode.Nearest); //优先读取secondary 不存在时读取primary
break;
case "Primary":
set.ReadPreference = new ReadPreference(ReadPreferenceMode.Primary);
break;
case "PrimaryPreferred":
set.ReadPreference = new ReadPreference(ReadPreferenceMode.PrimaryPreferred);
break;
case "Secondary":
set.ReadPreference = new ReadPreference(ReadPreferenceMode.Secondary);
break;
case "SecondaryPreferred":
set.ReadPreference = new ReadPreference(ReadPreferenceMode.SecondaryPreferred);
break;
default:
set.ReadPreference = new ReadPreference(ReadPreferenceMode.Nearest); //优先读取secondary 不存在时读取primary
break;
}