码迷,mamicode.com
首页 > Windows程序 > 详细

C#使用memcached示例

时间:2015-03-18 15:36:57      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

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示例

标签:

原文地址:http://www.cnblogs.com/aobama/p/4346946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!