zoukankan      html  css  js  c++  java
  • mencache的使用二

     在这里说的是在C#中的使用,在C#中使用是需要引入驱动的,

    可以在网上找,这里推荐一个链接http://sourceforge.net/projects/memcacheddotnet/

    将Memcached.ClientLibrary;引入。另外的 commands.dll log4net.dll,ICSharpCode.SharpZipLib.dll

    等,应该是被以来的,下面的代码显示,使用到的类只在Memcacahed.ClientLibrary程序集中。其中log4net是

    memcache记录日志所用。

    简单的代码如下:

    using Memcached.ClientLibrary;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace memcache
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string[] server = { "10.21.160.31:11211"};
                SockIOPool pool = SockIOPool.GetInstance();//在Memcached.ClientLibrary程序集里。
                pool.SetServers(server);
                pool.InitConnections = 3;
                pool.MinConnections = 3;
                pool.MaxBusy = 5;
                pool.SocketConnectTimeout = 1000;
                pool.SocketTimeout = 3000;
                pool.MaintenanceSleep = 30;
                pool.Failover = true;
                pool.Nagle = false;
                pool.Initialize();
                //获得客户端实例
                MemcachedClient client = new MemcachedClient();//在Memcached.ClientLibrary程序集里
                client.EnableCompression = false;
                client.Add("keyd1", "value12dfsdf", DateTime.Now.AddHours(1), 0);
                Console.WriteLine(client.Get("keyd1").ToString());
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    云虚拟化
    yum puppet 并整合控制台
    Centos6.4 openNebula
    ubuntu Server LAmp环境
    openSuSE12.1 zypper LAMP
    yum puppet
    NYOJ 257 郁闷的C小加(一)
    JAVA_SE基础——17.方法的重载
    poj 1390 Blocks (经典区间dp 方块消除)
    HBase数据同步到ElasticSearch的方案
  • 原文地址:https://www.cnblogs.com/xiaoai123/p/6473137.html
Copyright © 2011-2022 走看看