欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Redis总结笔记(二):C#连接Redis简单例子

程序员文章站 2022-04-01 08:39:51
注:c#在调用redis是不要使用servicestack.redis驱动的4.0版本,因为这个版本已经商业化了,会出现每小时6000条数据的限制 1、引用驱动 复制代...

注: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");//获取数据