当前位置: 首页>>代码示例>>C#>>正文


C# RedisConnection.GetInfo方法代码示例

本文整理汇总了C#中BookSleeve.RedisConnection.GetInfo方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.GetInfo方法的具体用法?C# RedisConnection.GetInfo怎么用?C# RedisConnection.GetInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BookSleeve.RedisConnection的用法示例。


在下文中一共展示了RedisConnection.GetInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SelectAndCreateConnection

        private static RedisConnection SelectAndCreateConnection(string configuration, TextWriter log, out string selectedConfiguration, out string[] availableEndpoints, bool autoMaster, string newMaster = null)
        {
            int syncTimeout;
            bool allowAdmin;
            if(log == null) log = new StringWriter();
            var arr = GetConfigurationOptions(configuration, out syncTimeout, out allowAdmin);
            if (!string.IsNullOrWhiteSpace(newMaster)) allowAdmin = true; // need this to diddle the slave/master config

            log.WriteLine("{0} unique nodes specified", arr.Length);
            log.WriteLine("sync timeout: {0}ms, admin commands: {1}", syncTimeout,
                          allowAdmin ? "enabled" : "disabled");
            if (arr.Length == 0)
            {
                log.WriteLine("No nodes to consider");
                selectedConfiguration = null;
                availableEndpoints = new string[0];
                return null;
            }
            var connections = new List<RedisConnection>(arr.Length);
            RedisConnection preferred = null;

            try
            {
                var infos = new List<Task<string>>(arr.Length);
                var tiebreakers = new List<Task<string>>(arr.Length);
                foreach (var option in arr)
                {
                    if (string.IsNullOrWhiteSpace(option)) continue;

                    RedisConnection conn = null;
                    try
                    {

                        var parts = option.Split(':');
                        if (parts.Length == 0) continue;

                        string host = parts[0].Trim();
                        int port = 6379, tmp;
                        if (parts.Length > 1 && int.TryParse(parts[1].Trim(), out tmp)) port = tmp;
                        conn = new RedisConnection(host, port, syncTimeout: syncTimeout, allowAdmin: allowAdmin);

                        log.WriteLine("Opening connection to {0}:{1}...", host, port);
                        conn.Open();
                        var info = conn.GetInfo();
                        var tiebreak = conn.Strings.GetString(0, TieBreakerKey);
                        connections.Add(conn);
                        infos.Add(info);
                        tiebreakers.Add(tiebreak);
                    }
                    catch (Exception ex)
                    {
                        if (conn == null)
                        {
                            log.WriteLine("Error parsing option \"{0}\": {1}", option, ex.Message);
                        }
                        else
                        {
                            log.WriteLine("Error connecting: {0}", ex.Message);
                        }
                    }
                }
                List<RedisConnection> masters = new List<RedisConnection>(), slaves = new List<RedisConnection>();
                var breakerScores = new Dictionary<string, int>();
                foreach (var tiebreak in tiebreakers)
                {
                    try
                    {
                        if (tiebreak.Wait(syncTimeout))
                        {
                            string key = tiebreak.Result;
                            if (string.IsNullOrWhiteSpace(key)) continue;
                            int score;
                            if (breakerScores.TryGetValue(key, out score)) breakerScores[key] = score + 1;
                            else breakerScores.Add(key, 1);
                        }
                    }
                    catch { /* if a node is down, that's fine too */ }
                }
                // check for tie-breakers (i.e. when we store which is the master)
                switch (breakerScores.Count)
                {
                    case 0:
                        log.WriteLine("No tie-breakers found");
                        break;
                    case 1:
                        log.WriteLine("Tie-breaker is unanimous: {0}", breakerScores.Keys.Single());
                        break;
                    default:
                        log.WriteLine("Ambiguous tie-breakers:");
                        foreach (var kvp in breakerScores.OrderByDescending(x => x.Value))
                        {
                            log.WriteLine("\t{0}: {1}", kvp.Key, kvp.Value);
                        }
                        break;
                }

                for (int i = 0; i < connections.Count; i++)
                {
                    log.WriteLine("Reading configuration from {0}:{1}...", connections[i].Host, connections[i].Port);
                    try
//.........这里部分代码省略.........
开发者ID:IgorCandido,项目名称:NodeTests,代码行数:101,代码来源:ConnectionUtils.cs

示例2: SelectAndCreateConnection

        private static RedisConnection SelectAndCreateConnection(string configuration, TextWriter log,
                                                                 out string selectedConfiguration,
                                                                 out string[] availableEndpoints, bool autoMaster,
                                                                 string newMaster = null, string tieBreakerKey = null)
        {
            if (tieBreakerKey == null) tieBreakerKey = "__Booksleeve_TieBreak"; // default tie-breaker key
            int syncTimeout;
            bool allowAdmin;
            string serviceName;
            string clientName;
            if (log == null) log = new StringWriter();
            string[] arr = GetConfigurationOptions(configuration, out syncTimeout, out allowAdmin, out serviceName,
                                                   out clientName);
            if (!string.IsNullOrWhiteSpace(newMaster)) allowAdmin = true; // need this to diddle the slave/master config

            log.WriteLine("{0} unique nodes specified", arr.Length);
            log.WriteLine("sync timeout: {0}ms, admin commands: {1}", syncTimeout,
                          allowAdmin ? "enabled" : "disabled");
            if (!string.IsNullOrEmpty(serviceName)) log.WriteLine("service: {0}", serviceName);
            if (!string.IsNullOrEmpty(clientName)) log.WriteLine("client: {0}", clientName);
            if (arr.Length == 0)
            {
                log.WriteLine("No nodes to consider");
                selectedConfiguration = null;
                availableEndpoints = new string[0];
                return null;
            }
            var connections = new List<RedisConnection>(arr.Length);
            RedisConnection preferred = null;

            try
            {
                var infos = new List<Task<string>>(arr.Length);
                var tiebreakers = new List<Task<string>>(arr.Length);
                foreach (string option in arr)
                {
                    if (string.IsNullOrWhiteSpace(option)) continue;

                    RedisConnection conn = null;
                    try
                    {
                        string[] parts = option.Split(':');
                        if (parts.Length == 0) continue;

                        string host = parts[0].Trim();
                        int port = 6379, tmp;
                        if (parts.Length > 1 && int.TryParse(parts[1].Trim(), out tmp)) port = tmp;
                        conn = new RedisConnection(host, port, syncTimeout: syncTimeout, allowAdmin: allowAdmin);
                        conn.Name = clientName;
                        log.WriteLine("Opening connection to {0}:{1}...", host, port);
                        conn.Open();
                        Task<string> info = conn.GetInfo();
                        Task<string> tiebreak = conn.Strings.GetString(0, tieBreakerKey);
                        connections.Add(conn);
                        infos.Add(info);
                        tiebreakers.Add(tiebreak);
                    }
                    catch (Exception ex)
                    {
                        if (conn == null)
                        {
                            log.WriteLine("Error parsing option \"{0}\": {1}", option, ex.Message);
                        }
                        else
                        {
                            log.WriteLine("Error connecting: {0}", ex.Message);
                        }
                    }
                }
                List<RedisConnection> masters = new List<RedisConnection>(), slaves = new List<RedisConnection>();
                var breakerScores = new Dictionary<string, int>();
                foreach (var tiebreak in tiebreakers)
                {
                    try
                    {
                        if (tiebreak.Wait(syncTimeout))
                        {
                            string key = tiebreak.Result;
                            if (string.IsNullOrWhiteSpace(key)) continue;
                            int score;
                            if (breakerScores.TryGetValue(key, out score)) breakerScores[key] = score + 1;
                            else breakerScores.Add(key, 1);
                        }
                    }
                    catch
                    {
                        /* if a node is down, that's fine too */
                    }
                }

                // see if any of our nodes are sentinels that know about the named service
                List<Tuple<RedisConnection, Task<Tuple<string, int>>>> sentinelNodes = null;
                foreach (RedisConnection conn in connections)
                {
                    // the "wait" we did during tie-breaker detection means we should now know what each server is
                    if (conn.ServerType == ServerType.Sentinel)
                    {
                        if (string.IsNullOrEmpty(serviceName))
                        {
                            log.WriteLine("Sentinel discovered, but no serviceName was specified; ignoring {0}:{1}",
//.........这里部分代码省略.........
开发者ID:jorik041,项目名称:booksleeve-unofficial,代码行数:101,代码来源:ConnectionUtils.cs


注:本文中的BookSleeve.RedisConnection.GetInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。