Redis總結筆記(二):C#串連Redis簡單例子_Redis

來源:互聯網
上載者:User

註:C#在調用Redis是不要使用ServiceStack.Redis驅動的4.0版本,因為這個版本已經商業化了,會出現每小時6000條資料的限制

1、引用驅動

複製代碼 代碼如下:

    using ServiceStack.Redis;

2、資料庫連接
複製代碼 代碼如下:

    RedisClient client;
            //串連伺服器   6379是redis的預設連接埠
            client = new RedisClient("127.0.0.1", 6379);
    client.Password = "";//設定密碼 沒有可以注釋

          //10萬條資料測試,我發現使用set的效率明顯比使用store的效率高,而且在測試過程中我發現store會丟失7-80條左右的數而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");//擷取資料
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.