Memcached安裝,操作,用C#操作

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   sp   

 

本文來自:http://li19910722.blog.163.com/blog/static/136856822201406103313163/

1;安裝
下載Memcache:http://code.jellycan.com/Memcache/
將服務程式拷貝到一個磁碟上的目錄,同時將CMD命令視窗也複製到該檔案夾下面
安裝服務:cmd→Memcached.exe -d install 開啟服務監控視窗可以查看服務是否啟動。
或者改為:.\Memcached.exe -d install
啟動服務:cmd→Memcached.exe -d start(restart重啟,stop關mem閉服務)檢查服務是否啟動:串連到Memcache控制台:telnet 127.0.0.1 11211  輸入命令:stats檢查當前服務狀態。卸載服務:Memcached.exe -d uninstall遇到問題:1;win8下安裝服務。無法啟動此程式,因為電腦中丟失 MSVCR71.dll。嘗試重新安裝該程式以解決此問題。下載dll地址:http://www.dll-files.com/dllindex/dll-files.shtml?msvcr712;關於無法用Telnet:是這樣的,Win7預設沒有安裝telnet功能,所以你直接用telnet命令是用不了的;
你可以去“控制台”--》“程式和功能”(在左下角)---》“開啟或關閉Windows功能”,勾上“telnet用戶端”,確定就可以正常使用telnet命令了

2;

添加一條資料:add key 0 30 10           --表示失效時間為30s,長度為10 或set  key 0 30 10           --添加一條資料 得到一條資料get key
 3; 如何使用C#操作Memcached:
    1. 添加引用
    2. 寫代碼
      MemcachedHelp類:
    3.  public class MemcachedHelper   {       /// <summary>       /// 定義一個靜態MemcachedClient用戶端,它隨類一起載入,所有對象共用       /// </summary>       private static MemcachedClient mc;       /// <summary>       /// 靜態建構函式,初始化Memcached用戶端       /// </summary>       static MemcachedHelper()       {           string[] serverList = { "127.0.0.1:11211" };           SockIOPool pool = SockIOPool.GetInstance("test");           pool.SetServers(serverList);           pool.Initialize();           mc = new MemcachedClient();           mc.PoolName = "test";           mc.EnableCompression = false;       }       /// <summary>       /// 向Memcached緩衝中添加一條資料       /// </summary>       /// <param name="key">鍵</param>       /// <param name="value">值</param>       /// <param name="expiry">到期時間</param>       /// <returns>返回是否添加成功</returns>       public static bool SetValue(string key, object value, DateTime expiry)       {           return mc.Set(key, value, expiry);       }       /// <summary>       /// 通過key 來得到一個對象       /// </summary>       /// <param name="key">鍵</param>       /// <returns>對象</returns>       public static object GetValue(string key)       {           return mc.Get(key);       }   }
      4;測試:
       /// <summary>        ///  向Memcached中添加一條資料        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void btnAddMemCached_Click(object sender, EventArgs e)        {            if (MemcachedHelper.SetValue("name", "licong", DateTime.Now.AddMinutes(1)))            {                MessageBox.Show("資料添加成功");            }            object obj = MemcachedHelper.GetValue("name");            MessageBox.Show(obj.ToString());        }

Memcached安裝,操作,用C#操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.