当前位置:首页 / 编程技术 / 数据库 / Redis总结笔记(二):C#连接Redis简单例子
Redis总结笔记(二):C#连接Redis简单例子
发布时间:2022/07/10来源:编程网

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

分享到:
免责声明:本文仅代表文章作者的个人观点,与本站无关,请读者仅作参考,并自行核实相关内容。文章内容来源于网络,版权归原作者所有,如有侵权请与我们联系,我们将及时删除。
资讯推荐
热门最新
精品工具
全部评论(0)
剩余输入数量90/90
暂无任何评论,欢迎留下你的想法
你可能感兴趣的资讯
换一批