Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ipport"></param>
        /// <param name="logcallback"></param>
        /// <param name="ReadBuffSize"></param>
        /// <param name="Interval"> ms,0 means never update</param>
        /// <remarks>通常说来,info返回的字节数都差不多,因此这里输入一个足够大的buffer可以一次性加载完整的数据</remarks>
        public InfoClient(string ipport, Action <string> logcallback = null, int ReadBuffSize = 4096, int Interval = 1000)
        {
            #region prepare data
            RCommand cmd = new RCommand("info");
            INFOBUFF  = System.Text.ASCIIEncoding.ASCII.GetBytes(cmd.ToProtocolString());
            READBUFF  = new byte[ReadBuffSize];
            _interval = Interval;
            cb        = new CommandBuilder();
            #endregion
            if (logcallback != null)
            {
                _mlog = logcallback;
            }
            ipport = ipport.Trim();
            string ip   = ipport;
            int    port = 6379;
            var    arr  = ipport.Split(new char[] { ':' });

            if (arr.Length > 1)
            {
                ip   = arr[0];
                port = int.Parse(arr[1]);
            }
            try
            {
                socket = new TcpClient(ip, port);
            }
            catch (SocketException se)
            {
                Log(se.ToString());
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }

            if (loopthread == null)
            {
                _running   = true;
                loopthread = new Thread(monitorloop);
                loopthread.Start();
            }
            else
            {
                Log("Err:" + Err.ThreadStartFailed);
            }

            stream = socket.GetStream();
        }
Beispiel #2
0
        public override string ToProtocolString()
        {
            RCommand cmd = new RCommand(_args);

            return(cmd.ToProtocolString());
        }