C#使用memcached樣本

來源:互聯網
上載者:User

標籤:

1安裝libevent  ubuntu:apt-get install  名稱    suse:yast2 -i 名稱   centos: yum install 名稱

2安裝memcached  ubuntu:apt-get install  名稱    suse:yast2 -i 名稱   centos: yum install 名稱

3啟動服務(類似通訊端開啟監聽,查看是否開啟就好辦了,ps ef|grep memcache or netstat)

4用戶端必要配置(依賴性,connectstring等(此處體現在下面設計圖上)),根據配置按需串連,準備通訊.

以上完成:測試

1:建立winform app

2假設布局如下,兩個label,兩個textbox,一個button.

 

 

3:雙擊按鈕,添加如下代碼(注意第四步添加的dll引用以及名稱空間)

private void btnGetValue_Click(object sender, EventArgs e)

{

    string[] serverlist = { txtServer.Text };

    SockIOPool pool = SockIOPool.GetInstance();

    pool.SetServers(serverlist);

    pool.InitConnections = 3;

    pool.MinConnections = 3;

    pool.MaxConnections = 5;

    pool.SocketConnectTimeout = 1000;

    pool.SocketTimeout = 3000;

    pool.MaintenanceSleep = 30;

    pool.Failover = true;

    pool.Nagle = false;

    pool.Initialize();

    MemcachedClient mc = new MemcachedClient();

    mc.EnableCompression = false;

    string value = (string)mc.Get(txtKey.Text);

    MessageBox.Show(value);

}

4:運行,輸入memched所在的伺服器ip以及memcached對應連接埠號碼,(key:value也有類似set get的使用習慣)

 

我的總結:模仿,定製,適應新的需求.其實這和mysql for .net的流程幾乎就是一個模子.

有木有發現一個規律,mysql-server,redis-server,*-server,一一對應*-client(用戶端有手動輸入命令的終端,有加了個殼的gui,有編碼串連的app,本質,都一樣,socket通訊)

 

C#使用memcached樣本

聯繫我們

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