c#连接Redis缓存数据库---(2)Redis存读取数据
本帖最后由 多米诺 于 2013-3-22 15:01 编辑这一节演示下载.NET中怎样使用Redis存储数据.在.net中比较常用的客户端类库是ServiceStack,看下通过servicestack怎样存储数据。
DLL下载:https://github.com/ServiceStack/ServiceStack.Redis 下载完成后,DLL中包括四个DLL文件,然后把这四个文件添加到自己的项目中。 Redis中包括四种数据类型,Strings, Lists,Sets, Sorted Sets 接下来我们一一看这四种类型的用法 1.连接redis服务器
[*]RedisClient client;
[*]private void button1_Click(object sender, EventArgs e)
[*]{
[*] //连接服务器
[*] client = new RedisClient("127.0.0.1",6379);
[*]}
2.Strings类型
Strings能存储字符串,数字等类型,浮点型等.NET中的基本类型
[*]private void button2_Click(object sender, EventArgs e)
[*] {
[*] //存储用户名和密码
[*] client.Set<string>("username","524300045@qq.com");
[*] client.Set<int>("pwd", 123456);
[*] string username = client.Get<string>("username");
[*] int pwd=client.Get<int>("pwd");
[*]
[*] client.Set<decimal>("price", 12.10M);
[*] decimal price = client.Get<decimal>("price");
[*] MessageBox.Show(price.ToString());
[*]
[*] MessageBox.Show("用户名:"+username+",密码:"+pwd.ToString());
[*] }
[*]
[*]源码:
感謝樓主分享 没有想到 这个里面还有redis数据库 开眼界了啊好好学习啊
不错 不错 不错{:soso__3922851084632044791_6:} 很不错 好帖就是要顶 真心顶 难得一见的好帖 很好哦 很不错
页:
[1]