注:C#在調(diào)用Redis是不要使用ServiceStack.Redis驅(qū)動的4.0版本,因為這個版本已經(jīng)商業(yè)化了,會出現(xiàn)每小時6000條數(shù)據(jù)的限制
RedisClient client;
//連接服務(wù)器 6379是redis的默認端口
client = new RedisClient("127.0.0.1", 6379);
client.Password = "";//設(shè)置密碼 沒有可以注釋
//10萬條數(shù)據(jù)測試,我發(fā)現(xiàn)使用set的效率明顯比使用store的效率高,而且在測試過程中我發(fā)現(xiàn)store會丟失7-80條左右的數(shù)而set卻一條都沒有丟
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i 100000; i++)
{
client.SetGPS>(Guid.NewGuid().ToString(), new GPS
{
direction = 287,
gps_time = "1417622213418",
lati = 29.310586,
longi = 120.125143,
pla_no = "浙A12345",
pla_type = 1,
speed = 23.5,
state = 0,
carstate = 0,
upload_time = "1417622088418"
});
client.StoreGPS>(
new GPS
{
direction = 287,
gps_time = "1417622213418",
lati = 29.310586,
longi = 120.125143,
pla_no = "浙A12345",
pla_type = 1,
speed = 23.5,
state = 0,
carstate = 0,
upload_time = "1417622088418"
});
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
decimal price = client.Getdecimal>("price");//獲取數(shù)據(jù)