zoukankan      html  css  js  c++  java
  • c# 中使用memcached

    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;这是需要重启服务
    
  • 相关阅读:
    磁盘映射命令
    CentOS 配置XWIN/VNC
    生成一个随机数,让用户输入猜这个数字,有三次机会
    自己练习读取写入txt
    python学习笔记:文件操作和集合(转)
    接口测试基础
    nginx_tomcat负载均衡环境
    mysql索引
    shell脚本
    linux基础知识(四)
  • 原文地址:https://www.cnblogs.com/nele/p/5326403.html
Copyright © 2011-2022 走看看