Exemple #1
0
      public static async Task <T> GetDataOverTCPAsync <T>(string dbName, string key)
      {
          if (!TcpConnectionPool.Initialized)
          {
              TcpConnectionPool.InitializeConnectionPool(_tcpHostAddress, _port, _minPoolSize, _maxPoolSize, _socketRecycleAgeAsMinute);
          }

          var CustomSocket = TcpConnectionPool.GetSocket();

          try
          {
              byte[] sendData = Encoding.ASCII.GetBytes($"get {dbName} {key}");
              string response;
              using (NetworkStream stream = CustomSocket.GetStream())
              {
                  await stream.WriteAsync(sendData, 0, sendData.Length);

                  using (MemoryStream buffer = new MemoryStream())
                  {
                      int b;
                      while ((b = stream.ReadByte()) != -1)
                      {
                          buffer.WriteByte((byte)b);
                      }
                      response = Encoding.UTF8.GetString(buffer.GetBuffer());
                  }
              }
              return(JsonConvert.DeserializeObject <T>(response));
          }
          finally
          {
              TcpConnectionPool.PutSocket(CustomSocket);
          }
      }
Exemple #2
0
      public RocksDBClient(string tcpHostAdress = "127.0.0.1", int port = 38670, int minPoolSize = 20, int maxPoolSize = 5000, int socketRecycleAgeAsMinute = 15)
      {
          if (client.BaseAddress == null)
          {
              client.BaseAddress = new Uri("http://" + tcpHostAdress + ":3800/");
              client.DefaultRequestHeaders.Accept.Clear();
          }

          TcpConnectionPool.InitializeConnectionPool(tcpHostAdress, port, minPoolSize, maxPoolSize, socketRecycleAgeAsMinute);
      }