예제 #1
0
        private static List <RedisConnectionInfo> LoadRedisConnections()
        {
            var result = new List <RedisConnectionInfo>();
            var defaultServerInstances = Current.Settings.Redis.Defaults.Instances;
            var allServerInstances     = Current.Settings.Redis.AllServers.Instances ?? Enumerable.Empty <RedisSettings.Instance>();

            foreach (var s in Current.Settings.Redis.Servers)
            {
                var server = new RedisHost(s);

                var count = result.Count;
                // Add instances that belong to any servers
                foreach (var asi in allServerInstances)
                {
                    result.Add(new RedisConnectionInfo(server, asi));
                }

                // Add instances defined on this server
                foreach (var si in s.Instances)
                {
                    result.Add(new RedisConnectionInfo(server, si));
                }

                // If we have no instances added at this point, defaults it is!
                if (defaultServerInstances != null && count == result.Count)
                {
                    foreach (var dsi in defaultServerInstances)
                    {
                        result.Add(new RedisConnectionInfo(server, dsi));
                    }
                }
            }
            return(result);
        }
예제 #2
0
 public bool CanSlaveTo(RedisHost host, out string reason)
 {
     foreach (var i in Instances)
     {
         foreach (var di in i.GetAllSlavesInChain())
         {
             if (di?.ConnectionInfo?.Server == host)
             {
                 reason = $"Current chain contains {di.HostAndPort}";
                 return(false);
             }
         }
     }
     reason = "";
     return(true);
 }
예제 #3
0
 internal RedisConnectionInfo(RedisHost server, RedisSettings.Instance settings)
 {
     Server   = server;
     Settings = settings;
 }
예제 #4
0
 public bool InSameRegionAs(RedisHost host) => string.Equals(Region, host.Region, StringComparison.OrdinalIgnoreCase);