.net 應用Memcached 緩衝 demo(非轉載,檔案下載地址有效)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   ar   檔案   資料   2014   

一、準備:

  Memcaced服務端: http://files.cnblogs.com/sjns/memcached_en32or64.rar

  Memcaced 用戶端類庫:http://files.cnblogs.com/sjns/Memcached.ClientLibrary.rar

  檢測資料儲存在哪個服務:securecrt(註:此軟體沒有用過,這裡只記錄以後有時間在驗證)

二、安裝Memcaced服務端

  將memcached.exe複製到任意目錄下。用cmd命令安裝。(註:再win7下運行“命令提示字元”要用管理身份運行)

  安裝:memcached.exe -d install

  啟動:memcached.exe -d start

  卸載:memcached.exe -d uninstall

三、建立程式,我在這裡用的是控制台應用程式。

  把Memcaced 用戶端類庫添加到引用中來。

    

      SockIOPool是Memcached用戶端提供的一個通訊端串連池,通俗講,就是與Memcached伺服器端交換資料的對象。

      註: SockIOPool在應用程式啟動時初始化一次就可以了,我們可以把這個工作放在 GLOBAL.ASAX.CS的Application_Start方法裡。

  好了,接下來就是My Code了很的一個Demo

 

  

static void Main(string[] args)        {            char[] separator = { ‘,‘ };            string[] serverlist = new string[] { "127.0.0.1:11211" };            try            {                SockIOPool pool = SockIOPool.GetInstance();                pool.SetServers(serverlist);                pool.InitConnections = 3;                pool.MinConnections = 3;                pool.MaxConnections = 50;                pool.SocketConnectTimeout = 1000;                pool.SocketTimeout = 3000;                pool.MaintenanceSleep = 30;                pool.Failover = true;                pool.Nagle = false;                pool.Initialize();                MemcachedClient mc = new MemcachedClient();                mc.Set("123", "123123123");                Console.WriteLine("輸入要查詢的KEY");                string key = Console.ReadLine();                Console.WriteLine(mc.Get(key));                Console.WriteLine("輸入要修改的KEY");                String ukey = Console.ReadLine();                Console.WriteLine("輸入要修改的Value");                String uval = Console.ReadLine();                Console.WriteLine(mc.Set(ukey, uval));                Console.WriteLine("key:" + ukey + "的值已修改。如下:");                Console.WriteLine("value:" + uval);            }            catch (Exception err)            {                //這裡就可以用Log4Net記錄Error啦!            }        }

下面是運行效果:

 

                                   

 

.net 應用Memcached 緩衝 demo(非轉載,檔案有效)

聯繫我們

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