Exception interception with Redis Cluster - StackExchange.Redis

Configured Redis Cluster Server on Ubuntu 14.0 LTS Server (AZURE VM) using the official redis tutorial with no loopback IP as @Marcgravell pointed out, but getting MOVED exception for some keys when using Stackexchange.Redis client. Hi @Marcgravell, Can you shed some light on this. Thank.

+3


source to share


1 answer


Finally, I got my program. Thanks to @ hrishi18pathak. I downloaded the code from https://github.com/hrishi18pathak/StackExchange.Redis/tree/SEClusteringBugFix with changes from July 17, 2015. Major changes in the ConnectionMultiplexer and ConfigurartionOptions class.


ConnectionMultiplexer.cs (modified UpdateClusterRange () method, added IsNodeCompatibleWithConfiguration () method):

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 (Added HasAllDnsEndPoints () method)

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

      

However, I need to check for any implications with this fix.

-1


source







All Articles