c# asp.Netmemcached client呼び出し例


詳細
1.Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll binディレクトリに配置
2.Memcached.ClientLibrary.dll
3.クラスではusing Memcachedを参照する.ClientLibrary;
4.コード

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Memcached.ClientLibrary;

namespace TestMemcachedApp
{
    class Program
    {
        [STAThread]
        public static void Main(String[] args)
        {
            string[] serverlist = { "192.168.1.11:11211","192.168.1.12:11211","192.168.1.13:11211" };//        

            //    
            SockIOPool pool = SockIOPool.GetInstance();
            pool.SetServers(serverlist);//        cache     ,server      IP:PORT( :127.0.0.1:11211)
            pool.InitConnections = 3;//     
            pool.MinConnections = 3;//     
            pool.MaxConnections = 5;//     
            pool.SocketConnectTimeout = 1000;//          
            pool.SocketTimeout = 3000;//         
            pool.MaintenanceSleep = 30;//             。     0,           ,30    30     

            //           。
            //          true socket    ,                       。
            //     false,              。    NULL,              。
            pool.Failover = true;

          pool.Nagle = false;//   false,           Nagle   
            pool.Initialize();

            //        
            MemcachedClient mc = new MemcachedClient();
            mc.EnableCompression = false;

            Console.WriteLine("------------    -----------");
            mc.Set("test", "my value");  //          ,      "my value"  ,key  "test"

            if (mc.KeyExists("test"))   //      key test   
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());  //      key test   
            }
            else
            {
                Console.WriteLine("test not Exists");
            }

            
            mc.Delete("test");  //     key test   

            if (mc.KeyExists("test"))
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());
            }
            else
            {
                Console.WriteLine("test not Exists");
            }
            Console.ReadLine();

            SockIOPool.GetInstance().Shutdown();  //   ,   sockets
        }
    }
}

黒い髪:http://heisetoufa.iteye.com/
  • MemcacheDLL.rar (161.9 KB)
  • ダウンロード回数:127