c# 中使用memcached

作者:@nele
本文为作者原创,转载请注明出处:https://www.cnblogs.com/nele/p/5326403.html


目录

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;这是需要重启服务

转载于:https://www.cnblogs.com/ExMan/p/9795379.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值