Esempio n. 1
0
 public IList<string> Info()
 {
     IList<string> result = new List<string>();
     using (ClientItem c = Pop())
     {
         using (Command cmd = new Command())
         {
             cmd.Add(CONST_VALURES.REDIS_COMMAND_INFO);
             using (Result r = TcpClient.Send(cmd, c.Client))
             {
                 foreach (ArraySegment<byte> item in r.ResultDataBlock)
                 {
                     result.Add(item.GetString());
                 }
             }
         }
     }
     return result;
 }
Esempio n. 2
0
        private void OnDetect(object state)
        {
           
            try
            {
                TcpClient client = CreateClient();
                using (Command cmd = new Command())
                {
                    cmd.Add(CONST_VALURES.REDIS_COMMAND_PING);
                    using (Result result =TcpClient.Send(cmd,client))
                    {

                    }
                }
                Push(client);
                Available = true;
            }
            catch (Exception e_)
            {
                LastError = e_;
                Available = false;
            }
            Detecting = false;
        }
Esempio n. 3
0
        internal static Result Send(Command cmd, TcpClient client)
        {
            byte[] sdata = BufferPool.Single.Pop();
            try
            {
                int count = cmd.toData(sdata);
                if (!client.Send(sdata, 0, count))
                {
                    throw new Exception(string.Format("{0} client disconnect!", client.mHost));
                }
            }
            catch (Exception e_)
            {
                client.mLastError = e_;
              
                throw new Exception(string.Format("send to {0} error!", client.mHost), e_);
            }
            finally
            {
                BufferPool.Single.Push(sdata);
            }
            Result result = new Result();

            try
            {
                while (true)
                {
                    TcpReceiveArgs res = client.Receive();
                    if (result.Import(res.Data, res.Offset, res.Count))
                    {
                        break;
                    }
                }
                if (result.mImportOffset > 0)
                {
                    client.Receive(result.mImportOffset);
                    
                }
            }
            catch (Exception e_)
            {
                result.Dispose();
                client.mLastError = e_;
                throw new Exception(string.Format("receive {0} error!", client.mHost), e_);
            }
            return result;
        }