为了账号安全,请及时绑定邮箱和手机立即绑定

c#怎么连接Redis,Get和Set数据?

c#怎么连接Redis,Get和Set数据?

C#
侃侃无极 2019-03-22 15:14:11
c#怎么连接Redis,Get和Set数据?
查看完整描述

2 回答

?
开心每一天1111

TA贡献1836条经验 获得超12个赞

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



查看完整回答
反对 回复 2019-03-27
  • 2 回答
  • 0 关注
  • 1042 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信