代码之家  ›  专栏  ›  技术社区  ›  Greg

ConnectionMultiplexer.GetEndPoints()中的“configuredOnly”用于什么?

  •  6
  • Greg  · 技术社区  · 10 年前

    我正在使用神奇的StackExchange。实现ObjectCache的Redis库。要在ObjectCache中实现的接口方法之一是 long GetCount(...) 其返回数据库中的键的数量。看起来这可以通过 IServer.DatabaseSize(...) StackExchange.Redis中的方法。

    我计划从 ConnectionMultiplexer.GetEndPoints() ,为每个端点获取一个IServer,然后查询每个服务器上我感兴趣的每个数据库的数据库大小(暂时忽略大小差异)。

    现在 连接多路复用器.GetEndPoints() 具有名为“configuredOnly”的可选参数。不提供它的后果是什么?是真是假?

    连接多路复用器.GetEndPoints() implementation ,我看到,如果configuredOnly为true,它将从多路复用器配置中返回端点,否则将从名为“serverSnapshot”的数组中返回端点。

    据我所知,“serverSnapshot”已填充 here ,当服务器连接或至少尝试连接到时,它似乎已填充。

    GetEndPoints(true) 是否返回ConnectionMultiplexer上配置的所有端点?做 GetEndPoints() GetEndPoints(false) 返回实际连接/有效的端点?GetEndPoints方法关于configuredOnly参数的文档是稀疏的,我随后使用返回的EndPoints需要一种行为,而不是另一种行为。

    1 回复  |  直到 10 年前
        1
  •  3
  •   bmalec    9 年前

    当configuredOnly设置为true时,GetEndPoints()只返回在ConnectionMultiplexer.Connect()调用中显式指定的Redis服务器的端点。或者,如果configuredOnly为false,则为集群中的每个Redis服务器返回端点,无论它们是否在初始ConnectionMultiplexer中指定。Connect()调用。

    如果在ConnectionMultiplexer中使用DNS名称,则会有些奇怪。Connect()调用,GetEndPoints(false)将返回DNS名称和解析的IP地址的行。例如,对于六节点Redis集群,代码如下:

    ConnectionMultiplexer redis = ConnectionMultiplexer("localhost:6379,localhost:6380");
    foreach (var endpoint in redis.GetEndPoints(false))
    {
      Console.WriteLine(endpoint.ToString());
    }
    

    将输出

    $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
    

    如果我打过电话 redis.GetEndPoints(true) 只有 Unspecified/localhost:6379 Unspecified/localhost:6380 将返回。