Redis簡單本機測試

來源:互聯網
上載者:User

下載Redis的windows 版本,裡麵包含32bit和64bit2個檔案夾,和其他檔案,根據系統選擇拷貝32bit或者64bit的目錄裡面的檔案到D:\redis檔案夾裡面,然後通過cmd命令進入到該檔案,執行Redis-Server.exe Redis.conf啟動服務端。

如果出現如下內容,及服務端啟動成功:(注意服務端的Cmd視窗不能關閉,一旦關閉服務就停止了)

d:\redis>redis-server.exe redis.conf
[9340] 09 Dec 22:13:37 * Server started, Redis version 2.4.2
[9340] 09 Dec 22:13:37 * DB loaded from disk: 0 seconds
[9340] 09 Dec 22:13:37 * The server is now ready to accept connections on port 6
379

在開啟一個Cmd命令視窗啟動用戶端,出現以下就成功了。

d:\redis>redis-cli.exe -h 127.0.0.1 -p 6379
redis 127.0.0.1:6379> set pwd 123456
OK
redis 127.0.0.1:6379> get pwd
"123456"
redis 127.0.0.1:6379>

到處安裝成功。

然後在下載用戶端,把4個dll引用到項目中。

ServiceStack.Text.dll/ServiceStack.Redis.dll/ServiceStack.Interfaces/ServiceStack.Common.dll

在項目中添加命名空間引用using ServiceStack.Redis;

就可以再項目中使用了redis了。

使用一 

RedisClient Redis = new RedisClient("127.0.0.1", 6379);//串連伺服器
     
            UserInfo user = new UserInfo { UserName = "why", Age = 111, Id = 222 };
            Redis.Set<UserInfo>("test", user);//設定緩衝
             UserInfo getU = Redis.Get<UserInfo>("test");//取緩衝。

使用二

  public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts)
        {
            //支援讀寫分離,均衡負載
            return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
            {
                MaxWritePoolSize = 5,//“寫”連結池連結數
                MaxReadPoolSize = 5,//“寫”連結池連結數
                AutoStart = true,
            });
        }

   //通過讀寫分離式:

      PooledRedisClientManager prcm = CreateManager(new string[] { "127.0.0.1:6379" }, new string[] { "127.0.0.1:6379" });

           using (IRedisClient Redis2 = prcm.GetClient())
           {
               Redis2.Set("userinfolist", userinfoList);
               List<UserInfo> userList = Redis2.Get<List<UserInfo>>("userinfolist");

               Response.Write(userList[1].UserName +
         userList[0].UserName);
           }

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.