using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentCassandra;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var session = new CassandraSession("Tester", "localhost");
CreateData(session);
SelectData(session);
Console.WriteLine("Done");
Console.ReadLine();
}
private static void SelectData(CassandraSession session)
{
using (var db = new CassandraContext(session))
{
var users = db.GetColumnFamily("Users2");
var count = users.AsObjectQueryable<User>().Count();
Console.WriteLine("Counted: " + count.ToString());
}
}
private static void CreateData(CassandraSession session)
{
var startTime = DateTime.UtcNow;
for (int index = 0; index < 11 * 1000; index++)
{
using (var db = new CassandraContext(session))
{
var users = db.GetColumnFamily("Users2");
dynamic user = users.CreateRecord(index);
user.Name = "UserX" + index.ToString();
user.Password = "PasswordX" + index.ToString();
db.Attach(user);
db.SaveChanges();
if (index % 1000 == 0)
{
var taken = DateTime.UtcNow - startTime;
Console.WriteLine(string.Format("{0} thousand in {1} seconds", (index / 1000) + 1, taken.TotalSeconds));
}
}
}
}
}
class User
{
public string Name { get; set; }
public string Text { get; set; }
}
}
这个应用程序的输出是
1 thousand in 0.2760158 seconds
2 thousand in 0.8180468 seconds
3 thousand in 1.3700784 seconds
4 thousand in 1.8971085 seconds
5 thousand in 2.4091378 seconds
6 thousand in 3.0791761 seconds
7 thousand in 3.6002059 seconds
8 thousand in 4.126236 seconds
9 thousand in 4.8292762 seconds
10 thousand in 5.3513061 seconds
11 thousand in 5.8543349 seconds
Counted: 9018
Done