CRL.CacheServer.TcpPoolClient.SendQuery C# (CSharp) Method

SendQuery() public method

public SendQuery ( string query ) : string
query string
return string
        public override string SendQuery(string query)
        {
            var data = encode.GetBytes(query);
            if (Connections.Count > 300)
            {
                throw new Exception("TcpClientPool连接已超过500");
            }
            Connection connection;
            lock (lockObj)
            {
                connection = Connections.Find(b => b.Used == false);
                if (connection == null)
                {
                    connectionIndex += 1;
                    connection = new Connection() { Socket = new CoreHelper.SocketUtil.TcpClient(server, port, 3, true), Index = connectionIndex };
                    Connections.Add(connection);
                }
                connection.Used = true;
            }
            var result = connection.Socket.SendAndReceive(data);
            lock (lockObj)
            {
                connection.Used = false;
                connection.LastUseTime = DateTime.Now;
            }
            if (result == null)
            {
                //connection.Socket.Dispose();
                //Connections.Remove(connection);
                throw new Exception("连接到缓存服务器时发生错误:" + connection.Socket.LastException.Message);
            }
            var response = encode.GetString(result);
            return response;
        }