public T GetNodeForKey(string key) { if (!Ring.Any()) throw new InvalidOperationException("Can not find the available nodes, please call the AddNode method to add nodes."); var hash = HashAlgorithm.Hash(key); if (Ring.ContainsKey(hash)) return Ring[hash]; var node = Ring.Where(p => p.Key > hash).OrderBy(i => i.Key).Select(p => p.Value).FirstOrDefault(); if (node != null) return node; return Ring.FirstOrDefault().Value; }