C#连接内存数据库redis【1、Redis存读取数据】

 这一节演示下载.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());
        }
原文地址:https://www.cnblogs.com/tianciliangen/p/4949123.html