Redis總結(jié)筆記(二):C#連接Redis簡(jiǎn)單例子
注:C#在調(diào)用Redis是不要使用ServiceStack.Redis驅(qū)動(dòng)的4.0版本,因?yàn)檫@個(gè)版本已經(jīng)商業(yè)化了,會(huì)出現(xiàn)每小時(shí)6000條數(shù)據(jù)的限制
1、引用驅(qū)動(dòng)
using ServiceStack.Redis;
2、數(shù)據(jù)庫(kù)連接
RedisClient client;
//連接服務(wù)器 6379是redis的默認(rèn)端口
client = new RedisClient("127.0.0.1", 6379);
client.Password = "";//設(shè)置密碼 沒(méi)有可以注釋
//10萬(wàn)條數(shù)據(jù)測(cè)試,我發(fā)現(xiàn)使用set的效率明顯比使用store的效率高,而且在測(cè)試過(guò)程中我發(fā)現(xiàn)store會(huì)丟失7-80條左右的數(shù)而set卻一條都沒(méi)有丟
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 100000; i++)
{
client.Set<GPS>(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.Store<GPS>(
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.Get<decimal>("price");//獲取數(shù)據(jù)
- RedisDesktopManager無(wú)法遠(yuǎn)程連接Redis的完美解決方法
- Python與Redis的連接教程
- springboot2整合redis使用lettuce連接池的方法(解決lettuce連接池?zé)o效問(wèn)題)
- redis客戶(hù)端連接錯(cuò)誤 NOAUTH Authentication required
- Redis連接超時(shí)異常的處理方法
- 詳解springboot配置多個(gè)redis連接
- 詳解Redis開(kāi)啟遠(yuǎn)程登錄連接
- Springboot2.X集成redis集群(Lettuce)連接的方法
- redis連接報(bào)錯(cuò)error:NOAUTH Authentication required
- redis連接被拒絕的解決方案
- redis-copy使用6379端口無(wú)法連接到Redis服務(wù)器的問(wèn)題
相關(guān)文章
redis慢查詢(xún)?nèi)罩镜脑L問(wèn)和管理方式
這篇文章主要介紹了redis慢查詢(xún)?nèi)罩镜脑L問(wèn)和管理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12