网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 Redis总结笔记(二):C#连接Redis简单例子
内容
    注: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");//获取数据
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/23 7:04:35