分享

c#连接Redis

 yuriboy 2013-05-16

演示下载.NET中怎样使用Redis存储数据.在.net中比较常用的客户端类库是ServiceStack,看下通过servicestack怎样存储数据。

   DLL下载:https://github.com/ServiceStack/ServiceStack.Redis

   下载完成后,DLL中包括四个DLL文件,然后把这四个文件添加到自己的项目中。

     

    Redis中包括四种数据类型,Strings, Lists,  Sets, Sorted Sets

    接下来我们一一看这四种类型的用法

   1.连接redis服务器

[csharp] view plaincopy
  1. RedisClient client;  
  2. private void button1_Click(object sender, EventArgs e)  
  3. {  
  4.     //连接服务器  
  5.      client = new RedisClient("127.0.0.1",6379);  
  6. }  

    2.Strings类型
         Strings能存储字符串,数字等类型,浮点型等.NET中的基本类型

[csharp] view plaincopy
  1. private void button2_Click(object sender, EventArgs e)  
  2.      {  
  3.          //存储用户名和密码  
  4.          client.Set<string>("username","524300045@qq.com");  
  5.          client.Set<int>("pwd", 123456);  
  6.          string username = client.Get<string>("username");  
  7.          int pwd=client.Get<int>("pwd");  
  8.   
  9.          client.Set<decimal>("price", 12.10M);  
  10.          decimal price = client.Get<decimal>("price");  
  11.          MessageBox.Show(price.ToString());  
  12.   
  13.          MessageBox.Show("用户名:"+username+",密码:"+pwd.ToString());  
  14.      }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多