Gre*_*reg 5 stackexchange.redis
我正在使用神奇的StackExchange.Redis库来实现ObjectCache.在ObjectCache中实现的接口方法之一是long GetCount(...)返回数据库中的键数.看起来这可以通过IServer.DatabaseSize(...)StackExchange.Redis中的方法来满足.
我计划从中获取服务器端点ConnectionMultiplexer.GetEndPoints(),为每个端点获取一个IServer,然后在每个服务器上查询我感兴趣的每个数据库的数据库大小(暂时忽略大小差异).
现在,ConnectionMultiplexer.GetEndPoints()有一个名为"configuredOnly"的可选参数.没有提供它的结果是什么,而不是真实的,而不是虚假的?
在ConnectionMultiplexer.GetEndPoints() 实现中,我看到如果configuredOnly为true,它将从多路复用器配置返回EndPoints,或者从名为"serverSnapshot"的数组返回EndPoints.
据我所知,这里填充了 "serverSnapshot" ,这似乎是在连接服务器时填充的,或者至少是尝试连接的.
是否GetEndPoints(true)返回在ConnectionMultiplexer上配置的所有EndPoints?是否GetEndPoints()和GetEndPoints(false)返回实际连接/有效终点?GetEndPoints方法相对于configuredOnly参数的文档是稀疏的,我后续使用返回的EndPoints需要一个行为而不是另一个行为.
小智 3
当configuredOnly设置为true时,GetEndPoints()仅返回在调用ConnectionMultiplexer.Connect()时显式指定的Redis服务器的端点。或者,当configuredOnly为false时,将为集群中的每个Redis服务器返回端点,无论它们是否在初始ConnectionMultiplexer.Connect()调用中指定。
有点奇怪的是,如果您在 ConnectionMultiplexer.Connect() 调用中使用 DNS 名称,GetEndPoints(false) 将返回 DNS 名称和解析的 IP 地址的行。例如,对于六节点 Redis 集群,代码如下:
ConnectionMultiplexer redis = ConnectionMultiplexer("localhost:6379,localhost:6380");
foreach (var endpoint in redis.GetEndPoints(false))
{
Console.WriteLine(endpoint.ToString());
}
Run Code Online (Sandbox Code Playgroud)
将输出
$127.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
Run Code Online (Sandbox Code Playgroud)
如果我打电话redis.GetEndPoints(true),只会Unspecified/localhost:6379被Unspecified/localhost:6380回复。
| 归档时间: |
|
| 查看次数: |
437 次 |
| 最近记录: |