Ejemplo n.º 1
0
        public static MemcachedServerStats GetServerStats(IPEndPoint ip, TimeSpan connectionTimeout, TimeSpan receiveTimeout)
        {
            MemcachedSocket      socket = new MemcachedSocket(ip, connectionTimeout, receiveTimeout);
            MemcachedServerStats stats  = socket.GetStats();

            return(stats);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取Memcached的运行状态
        /// </summary>
        /// <returns></returns>
        public MemcachedServerStats GetStats()
        {
            MemcachedServerStats stats = new MemcachedServerStats(endpoint);

            try
            {
                socket.Connect(endpoint);
                networkStream  = new NetworkStream(socket);
                bufferedStream = new BufferedStream(networkStream);
                byte[] buffer = Encoding.ASCII.GetBytes(CommandString);

                SocketError socketError;
                socket.Send(buffer, 0, buffer.Length, SocketFlags.None, out socketError);
                if (socketError != SocketError.Success)
                {
                    stats.IsReachable = false;
                }
                else
                {
                    stats.IsReachable = true;
                    //string result = ReadLine();
                    //Dictionary<string, string> serverData = new Dictionary<string, string>(StringComparer.Ordinal);
                    //while (!string.IsNullOrEmpty(result))
                    //{
                    //    // 返回的数据信息以"END"作为结束标记
                    //    if (String.Compare(result, "END", StringComparison.Ordinal) == 0)
                    //        break;

                    //    //期望的响应格式是:"STAT 名称 值"(注意"STAT 名称 值"之间有空格)
                    //    if (result.Length < 6 || String.Compare(result, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0)
                    //    {
                    //        continue;
                    //    }

                    //    //获取以空格作为分隔符的键值对
                    //    string[] parts = result.Remove(0, 5).Split(' ');
                    //    if (parts.Length != 2)
                    //    {
                    //        continue;
                    //    }
                    //    serverData[parts[0]] = parts[1];
                    //    result = ReadLine();
                    //}
                    //stats.InitializeData(serverData);
                }
            }
            catch (Exception ex)
            {
                stats.IsReachable = false;
                // throw ex;
            }
            finally
            {
            }
            return(stats);
        }