public static void FistTest()
{
Console.WriteLine("Thrift2 Demo");
Console.WriteLine("This demo assumes you have a table called \"example\" with a column family called \"family1\"");
String host = "hserver";
int port = 9090;
int timeout = 10000;
var framed = false;
TTransport transport = new TSocket(host, port, timeout);
if (framed)
{
transport = new TFramedTransport(transport);
}
TProtocol protocol = new TBinaryProtocol(transport);
// This is our thrift client.
THBaseService.Iface client = new THBaseService.Client(protocol);
// open the transport
transport.Open();
var table = "t1".ToBytes();
TPut put = new TPut();
put.Row = ("row1".ToBytes());
for (var i = 0; i < 1000; i++)
{
TColumnValue columnValue = new TColumnValue();
columnValue.Family = ("f1".ToBytes());
columnValue.Qualifier = ("qualifier" + i).ToBytes();
columnValue.Value = ("value" + i).ToBytes();
List<TColumnValue> columnValues = new List<TColumnValue>();
columnValues.Add(columnValue);
put.ColumnValues = columnValues;
client.put(table, put);
}
TGet get = new TGet();
get.Row = ("row1".ToBytes());
TResult result = client.get(table, get);
Console.WriteLine("row = " + result.Row.ToStr());
foreach (TColumnValue resultColumnValue in result.ColumnValues)
{
Console.WriteLine("family = " + resultColumnValue.Family.ToStr());
Console.WriteLine("qualifier = " + resultColumnValue.Qualifier.ToStr());
Console.WriteLine("value = " + resultColumnValue.Value.ToStr());
Console.WriteLine("timestamp = " + resultColumnValue.Timestamp);
}
transport.Close();
}