gpt4 book ai didi

azure - Redis 集群的 MOVED 异常 - StackExchange.Redis

转载 作者:IT王子 更新时间:2023-10-29 06:02:56 29 4
gpt4 key购买 nike

使用 Redis 官方教程和非环回 IP 地址在 Ubuntu 服务器 14.0 LTS (AZURE VM) 中配置 Redis 集群服务器,如 @Marcgravell article 中所述。 ,但在使用 Stackexchange.Redis 客户端时,某些键出现 MOVED 异常。嗨@Marcgravell,你能解释一下吗?谢谢。

最佳答案

我的程序终于可以运行了。感谢@hrishi18pathak。我已经从https://github.com/hrishi18pathak/StackExchange.Redis/tree/SEClusteringBugFix下载了代码2015 年 7 月 17 日起发生变化的分支。主要更改在 ConnectionMultiplexer 和 ConfigurartionOptions 类中。

<小时/>

ConnectionMultiplexer.cs(修改UpdateClusterRange()方法,添加IsNodeCompatibleWithConfiguration()方法):

internal void UpdateClusterRange(ClusterConfiguration configuration)
{
if (configuration == null) return;
foreach (var node in configuration.Nodes)
{
// do not update cluster range if the node configuration is incompatible with the multiplexer

// endpoints configuration. If a user has specified endpoints in the multiplexer configuration using

// Dns endpoints, Stackexchange.redis returns the ConnectionMultiplexer object successfully
// after connecting to all the nodes in the connection string (using their host names).
// Also, before returning the multiplexer object it updates the mapping of nodes to their clusterslots

// and this mapping is of the format “DNS hostname:port” : “clusterSlotNumber”.

// However at the same time, the client also issues “CLUSTER NODES” command to each of the nodes in the above list

// (to determine master and slave configuration) and re-updates the cluster mapping with the output of the clusternodes command

// which now is going to contain IP addresses (redis-server itself does not understand host names).

// So the cluster mapping is now updated to the format: “IP Address” : “clusterSlotNumber”

// If the StackExchange.Redis has not been able to connect to all the nodes using their IP addresses by the time the first command (GET,SET)
// is issued to the cluster, it results in failure to connect to that particular node resulting in the “MOVED ERROR”

// (since it tries to hit a random node in the list subsequently)

if (node.IsSlave || node.Slots.Count == 0 || !IsNodeCompatibleWithConfiguration(node)) continue;
foreach (var slot in node.Slots)
{
var server = GetServerEndPoint(node.EndPoint);
if (server != null) serverSelectionStrategy.UpdateClusterRange(slot.From, slot.To, server);
}
}
}

/// <summary>
/// Checks if the specified node has the same format as that of
/// the endpoints specified in the multiplexer configuration i.e.
/// if all nodes are dns endpoints then the specified node has to be a dns endpoint
/// to be compatible.
/// </summary>
/// <param name="node"></param>
/// <returns>True if node is compatible with multiplexer configuration</returns>
private bool IsNodeCompatibleWithConfiguration(ClusterNode node)
{
return (this.configuration.HasAllDnsEndPoints() && (node.EndPoint is DnsEndPoint)) ||
(!this.configuration.HasDnsEndPoints() && !(node.EndPoint is DnsEndPoint));
}
<小时/>

ConfigurationOptions.cs(添加方法 HasAllDnsEndPoints())

internal bool HasAllDnsEndPoints()
{
return !endpoints.Any(ep => !(ep is DnsEndPoint));
}

我仍然需要验证此修复是否有任何影响。

关于azure - Redis 集群的 MOVED 异常 - StackExchange.Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30223105/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com