国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Redis > 正文

Redis總結(jié)筆記(二):C#連接Redis簡單例子

2020-10-28 21:42:00
字體:
供稿:網(wǎng)友

注:C#在調(diào)用Redis是不要使用ServiceStack.Redis驅(qū)動的4.0版本,因為這個版本已經(jīng)商業(yè)化了,會出現(xiàn)每小時6000條數(shù)據(jù)的限制

1、引用驅(qū)動

復(fù)制代碼 代碼如下:

    using ServiceStack.Redis;

2、數(shù)據(jù)庫連接
復(fù)制代碼 代碼如下:

    RedisClient client;
            //連接服務(wù)器   6379是redis的默認(rèn)端口
            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.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ù)
 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临江市| 淳化县| 马龙县| 浮山县| 波密县| 西安市| 孟津县| 明水县| 额尔古纳市| 平昌县| 西安市| 宜兴市| 蒙山县| 武强县| 鱼台县| 乌兰县| 墨脱县| 花莲市| 广宗县| 巴彦淖尔市| 晋宁县| 永兴县| 调兵山市| 高平市| 兴山县| 临漳县| 德安县| 基隆市| 兴国县| 鹿邑县| 遵化市| 泰安市| 尤溪县| 始兴县| 莱西市| 炉霍县| 丰镇市| 凤阳县| 奇台县| 陆川县| 同心县|