"configuredOnly" 在 ConnectionMultiplexer.GetEndPoints() 中有什么用?
What is "configuredOnly" used for in ConnectionMultiplexer.GetEndPoints()?
我正在使用很棒的 StackExchange.Redis 库来实现 ObjectCache。在 ObjectCache 中实现的接口方法之一是 long GetCount(...)
,它 return 是数据库中键的数量。 StackExchange.Redis.
中的IServer.DatabaseSize(...)
方法好像可以满足
我计划从 ConnectionMultiplexer.GetEndPoints()
获取服务器端点,为每个端点获取一个 IServer,然后查询每个服务器上我感兴趣的每个数据库的数据库大小(暂时忽略大小差异) .
现在,ConnectionMultiplexer.GetEndPoints()
有一个名为 "configuredOnly" 的可选参数。不提供与真与假的后果是什么?
在 ConnectionMultiplexer.GetEndPoints()
implementation 中,我看到如果 configuredOnly 为真,它 returns 来自多路复用器配置的端点,否则 returns 来自多路复用器配置的端点名为 "serverSnapshot".
的数组
据我所知,"serverSnapshot" 已填充 here,这似乎是在服务器连接时填充的,或者至少是尝试连接到的。
是否 GetEndPoints(true)
return 所有在 ConnectionMultiplexer 上配置的端点? GetEndPoints()
和 GetEndPoints(false)
return 端点实际上是 connected/valid 吗?关于 configuredOnly 参数的 GetEndPoints 方法的文档很少,我随后使用 returned EndPoints 需要一种行为而不需要另一种行为。
当 configuredOnly 设置为 true 时,GetEndPoints() 仅 returns 端点用于在对 ConnectionMultiplexer.Connect() 的调用中明确指定的 Redis 服务器。或者,当 configuredOnly 为 false 时,将为集群中的每个 Redis 服务器 returned 端点,无论它们是否在初始 ConnectionMultiplexer.Connect() 调用中指定。
有点奇怪,如果您在 ConnectionMultiplexer.Connect() 调用中使用 DNS 名称,GetEndPoints(false) 将为 DNS 名称和已解析的 IP 地址生成 return 行。例如,对于六节点 Redis 集群,以下代码:
ConnectionMultiplexer redis = ConnectionMultiplexer("localhost:6379,localhost:6380");
foreach (var endpoint in redis.GetEndPoints(false))
{
Console.WriteLine(endpoint.ToString());
}
会输出
7.0.0.1:6379
Unspecified/localhost:6379
Unspecified/localhost:6380
127.0.0.1:6380
127.0.0.1:6381
127.0.0.1:6382
127.0.0.1:6383
127.0.0.1:6384
如果我调用了 redis.GetEndPoints(true)
,只有 Unspecified/localhost:6379
和 Unspecified/localhost:6380
会被 return 编辑。
我正在使用很棒的 StackExchange.Redis 库来实现 ObjectCache。在 ObjectCache 中实现的接口方法之一是 long GetCount(...)
,它 return 是数据库中键的数量。 StackExchange.Redis.
IServer.DatabaseSize(...)
方法好像可以满足
我计划从 ConnectionMultiplexer.GetEndPoints()
获取服务器端点,为每个端点获取一个 IServer,然后查询每个服务器上我感兴趣的每个数据库的数据库大小(暂时忽略大小差异) .
现在,ConnectionMultiplexer.GetEndPoints()
有一个名为 "configuredOnly" 的可选参数。不提供与真与假的后果是什么?
在 ConnectionMultiplexer.GetEndPoints()
implementation 中,我看到如果 configuredOnly 为真,它 returns 来自多路复用器配置的端点,否则 returns 来自多路复用器配置的端点名为 "serverSnapshot".
据我所知,"serverSnapshot" 已填充 here,这似乎是在服务器连接时填充的,或者至少是尝试连接到的。
是否 GetEndPoints(true)
return 所有在 ConnectionMultiplexer 上配置的端点? GetEndPoints()
和 GetEndPoints(false)
return 端点实际上是 connected/valid 吗?关于 configuredOnly 参数的 GetEndPoints 方法的文档很少,我随后使用 returned EndPoints 需要一种行为而不需要另一种行为。
当 configuredOnly 设置为 true 时,GetEndPoints() 仅 returns 端点用于在对 ConnectionMultiplexer.Connect() 的调用中明确指定的 Redis 服务器。或者,当 configuredOnly 为 false 时,将为集群中的每个 Redis 服务器 returned 端点,无论它们是否在初始 ConnectionMultiplexer.Connect() 调用中指定。
有点奇怪,如果您在 ConnectionMultiplexer.Connect() 调用中使用 DNS 名称,GetEndPoints(false) 将为 DNS 名称和已解析的 IP 地址生成 return 行。例如,对于六节点 Redis 集群,以下代码:
ConnectionMultiplexer redis = ConnectionMultiplexer("localhost:6379,localhost:6380");
foreach (var endpoint in redis.GetEndPoints(false))
{
Console.WriteLine(endpoint.ToString());
}
会输出
7.0.0.1:6379
Unspecified/localhost:6379
Unspecified/localhost:6380
127.0.0.1:6380
127.0.0.1:6381
127.0.0.1:6382
127.0.0.1:6383
127.0.0.1:6384
如果我调用了 redis.GetEndPoints(true)
,只有 Unspecified/localhost:6379
和 Unspecified/localhost:6380
会被 return 编辑。