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

c# 中使用memcached

时间:2016-03-27 19:24:28      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

1.首先下载memcached 服务端 

2.使用Enyim.Caching .Net 客户端

3.配置web.config

  

  
   <sectionGroup name="QuickBootstrap1">
      <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
    </sectionGroup>

<QuickBootstrap1> <memcached> <servers> <add address="127.0.0.1" port="11211" /> </servers> <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00" /> </memcached> </QuickBootstrap1>

 

4.开始使用

代码如下

 //MemcachedClient mc = new MemcachedClient("QuickBootstrap1/memcached");
            MemcachedClient mc = new MemcachedClient("QuickBootstrap1/memcached");


            // store a string in the cache
            //bool res = mc.Store(StoreMode.Set, "MyKey", "Hello World");

            User user = new Entities.User
            {
                CreateTime = DateTime.Now,
                IsEnable = false,
                UserName = "1q2",
                Nick = "12312",
                UserPwd = "123"
            };
            string str = Newtonsoft.Json.JsonConvert.SerializeObject(user);
            bool result = mc.Store(StoreMode.Set, "user66", user);

            // retrieve the item from the cache
           // string mykey = mc.Get("MyKey").ToString();

            // store some other items
            //mc.Store(StoreMode.Set, "D1", 1234L);
            //mc.Store(StoreMode.Set, "D2", DateTime.Now);
            //mc.Store(StoreMode.Set, "D3", true);
            //mc.Store(StoreMode.Set, "D4", new Product());

            //mc.Store(StoreMode.Set, "D5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

          

 

5.注意:

mc.Store(StoreMode.Set, "user66", user); 会返回false;这是需要重启服务

c# 中使用memcached

标签:

原文地址:http://www.cnblogs.com/nele/p/5326403.html

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