Exemple #1
0
        static Dictionary <IPEndPoint, List <int> > Slabs()
        {
            ServerStats stats = client.Stats("items");

            Type      t             = stats.GetType();
            FieldInfo field_Results = t.GetField("results", BindingFlags.Instance | BindingFlags.NonPublic);

            Dictionary <IPEndPoint, Dictionary <string, string> > results = field_Results.GetValue(stats) as Dictionary <IPEndPoint, Dictionary <string, string> >;

            Dictionary <IPEndPoint, Dictionary <string, string> > .Enumerator re = results.GetEnumerator();
            Dictionary <IPEndPoint, List <int> > servers = new Dictionary <IPEndPoint, List <int> >();

            while (re.MoveNext())
            {
                List <int> members = new List <int>();
                re.Current.Value.Keys.ToList().ForEach(key =>
                {
                    Match match = Regex.Match(key, @"items:(?<slab>\d+):number");
                    int slab    = 0;
                    if (match.Success == true && int.TryParse(match.Groups["slab"].Value, out slab))
                    {
                        members.Add(slab);
                    }
                });

                servers.Add(re.Current.Key, members);
            }

            return(servers);
        }
        /// <summary>
        /// 使用配置文件默认配置的情况
        /// </summary>
        private MemcachedService()
        {
            memClient  = new MemcachedClient();
            serverInfo = memClient.Stats();

            //服务器节点失效事件
            memClient.NodeFailed += memClient_NodeFailed;
        }
        /// <summary>
        /// 使用自定义节点的情况
        /// </summary>
        /// <param name="sectionName"></param>
        private MemcachedService(string sectionName)
        {
            memClient  = new MemcachedClient(sectionName);
            serverInfo = memClient.Stats();

            //服务器节点失效事件,需要一个参数为IMemcachedNode并且无返回值的处理器
            memClient.NodeFailed += memClient_NodeFailed;
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tagName">customer_,device_ 等</param>
        /// <returns>Hashtable 数据对象,根据tagName</returns>
        public Hashtable GetStats(string tagName)
        {
            ArrayList arrList = new ArrayList();

            for (int i = 0; i < serverlist.Length; i++)
            {
                arrList.Add(serverlist[i]);
            }
            Hashtable tmpDataHashTable = new Hashtable();
            Hashtable resultHashtable  = new Hashtable();
            Hashtable allHashtable     = mc.Stats(arrList, "items");

            foreach (string key in allHashtable.Keys)
            {
                Hashtable dataHashTable = (Hashtable)allHashtable[key];
                foreach (string tmpKey in dataHashTable.Keys)
                {
                    string[] splitKey = tmpKey.Split(':');
                    string   tmpValue = (string)dataHashTable[tmpKey];
                    if (splitKey[2] == "number")
                    {
                        tmpDataHashTable.Add(splitKey[1], tmpValue);
                    }
                }
            }
            foreach (string allKey in tmpDataHashTable.Keys)
            {
                //key memCache结果集标记key,tmpDataHashTable[key]条数
                Hashtable hashtable = mc.Stats(arrList, "cachedump " + allKey + " " + tmpDataHashTable[allKey]);
                foreach (string tmpKey in hashtable.Keys)
                {
                    Hashtable result = (Hashtable)hashtable[tmpKey];
                    foreach (string resultKey in result.Keys)
                    {
                        if (resultKey.IndexOf(tagName) != -1)
                        {
                            resultHashtable.Add(resultKey, result[resultKey]);
                        }
                    }
                }
            }
            return(resultHashtable);
        }
Exemple #5
0
        public string CacheStatus()
        {
            var result = new Dictionary <string, Dictionary <string, string> >();

            foreach (Enyim.Caching.Memcached.StatItem statItem in Enum.GetValues(typeof(Enyim.Caching.Memcached.StatItem)))
            {
                var stats = memcachedClient.Stats().GetRaw(statItem.ToString());

                foreach (var stat in stats)
                {
                    var serverKey = stat.Key.Address + ":" + stat.Key.Port;
                    if (!result.ContainsKey(serverKey))
                    {
                        result[serverKey] = new Dictionary <string, string>();
                    }

                    result[serverKey][statItem.ToString()] = memcachedClient.Stats().GetRaw(stat.Key, statItem);
                }
            }

            return(result.ToJSON());
        }
Exemple #6
0
        public static string[] Allkeys()
        {
            Hashtable ht = mc.Stats();
            int       i  = 0;

            string[] allkey = new string[] { };
            foreach (DictionaryEntry de in ht)
            {
                Hashtable info = (Hashtable)de.Value;
                foreach (DictionaryEntry de2 in info)
                {
                    allkey[i] = de2.Key.ToString();
                }
                i++;
            }
            return(allkey);
        }
Exemple #7
0
        public CacheBus(string ipaddress)
        {
            try
            {
                m_config = new MemcachedClientConfiguration();
                m_config.Servers.Add(new IPEndPoint(IPAddress.Parse(ipaddress), 11211));
                m_config.Protocol   = MemcachedProtocol.Text;
                m_config.Transcoder = new DCBTranscoder();
                _ipAddress          = ipaddress;

                m_client         = new MemcachedClient(m_config);
                m_localHashtable = new Hashtable();
                m_stats          = m_client.Stats();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #8
0
 public void RemoveAll(string cacheKeyPrefix)
 {
     var s = mc.Stats();
 }
Exemple #9
0
        public void InvalidConfigurationTest()
        {
            MemcachedClient mc = new MemcachedClient("test/invalidConfig");

            mc.Stats();
        }
Exemple #10
0
 /// <summary>
 /// 服务器状态
 /// </summary>
 /// <returns></returns>
 public static Dictionary <string, Dictionary <string, string> > Stats()
 {
     return(cache.Stats());
 }
Exemple #11
0
        static void Main(string[] args)
        {
            //using (var client = new MemcachedClient())
            //{
            //    client.Store(StoreMode.Set, "currentTime", DateTime.UtcNow.ToString());
            //    string value = client.Get<string>("currentTime");
            //    Console.WriteLine(client.Stats());
            //    Console.WriteLine(value);
            //    Console.ReadKey();
            //}

            // create a MemcachedClient
            // in your application you can cache the client in a static variable or just recreate it every time
            // MemcachedClient mc = new MemcachedClient();

            // you can create another client using a different section from your app/web.config
            // this client instance can have different pool settings, key transformer, etc.
            // MemcachedClient mc2 = new MemcachedClient("memcached");

            // or just initialize the client from code

            MemcachedClientConfiguration config = new MemcachedClientConfiguration();
            config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
            config.Protocol = MemcachedProtocol.Binary;

            var mc = new MemcachedClient();

            for (var i = 0; i < 100; i++)
                mc.Store(StoreMode.Set, "Hello", "World");

            var myHello = mc.Get("Hello");
            Console.WriteLine(myHello);

            // simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
            List<string> keys = new List<string>();

            for (int i = 1; i < 100; i++)
            {
                string k = "aaaa" + i + "--" + (i * 2);
                keys.Add(k);

                mc.Store(StoreMode.Set, k, i);
            }

            IDictionary<string, ulong> cas;
            IDictionary<string, object> retvals = mc.Get(keys);

            List<string> keys2 = new List<string>(keys);
            keys2.RemoveRange(0, 50);

            IDictionary<string, object> retvals2 = mc.Get(keys2);
            retvals2 = mc.Get(keys2);

            ServerStats ms = mc.Stats();

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

            // retrieve the item from the cache
            Console.WriteLine("MyKey: {0}", mc.Get("MyKey"));

            Console.WriteLine("Increment num1 by 10 {0}", mc.Increment("num1", 1, 10));
            Console.WriteLine("Increment num1 by 10 {0}", mc.Increment("num1", 1, 10));
            Console.WriteLine("Increment num1 by 14 {0}", mc.Decrement("num1", 1, 14));

            //// 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 });

            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());

            Console.WriteLine("D1: {0}", mc.Get("D1"));
            Console.WriteLine("D2: {0}", mc.Get("D2"));
            Console.WriteLine("D3: {0}", mc.Get("D3"));
            Console.WriteLine("D4: {0}", mc.Get("D4"));
            Console.WriteLine("D5: {0}", System.Text.Encoding.UTF8.GetString(mc.Get<byte[]>("D5")));

            Console.WriteLine("Removing D1-D4");
            // delete them from the cache
            mc.Remove("D1");
            mc.Remove("D2");
            mc.Remove("D3");
            mc.Remove("D4");

            //ServerStats stats = mc.Stats();
            Console.WriteLine("Active Connections: {0}",ms.GetValue(ServerStats.All, StatItem.ConnectionCount));
            Console.WriteLine("GET operations {0}", ms.GetValue(ServerStats.All, StatItem.GetCount));

            //// add an item which is valid for 10 mins
            mc.Store(StoreMode.Set, "D4", new Product(), new TimeSpan(0, 10, 0));
            Console.WriteLine(mc.Stats().GetValue(new IPEndPoint(IPAddress.Loopback, 11211), StatItem.BytesRead));
            Console.ReadLine();
        }
Exemple #12
0
 public Hashtable Stats()
 {
     return(m_memcachedClientIns.Stats());
 }
Exemple #13
0
		static void Main(string[] args)
		{
			// create a MemcachedClient
			// in your application you can cache the client in a static variable or just recreate it every time
			MemcachedClient mc = new MemcachedClient();
			mc.Get("");

			// you can create another client using a different section from your app/web.config
			// this client instance can have different pool settings, key transformer, etc.
			// MemcachedClient mc2 = new MemcachedClient("memcached");

			// or just initialize the client from code
			//
			// MemcachedClientConfiguration config = new MemcachedClientConfiguration();
			// config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 20002));
			//
			// MemcachedClient mc = new MemcachedClient(config);


			// simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
			//List<string> keys = new List<string>();

			//for (int i = 1; i < 100; i++)
			//{
			//    string k = "aaaa" + i + "--" + (i * 2);
			//    keys.Add(k);

			//    mc.Store(StoreMode.Set, k, i);
			//}

			//IDictionary<string, ulong> cas;
			//IDictionary<string, object> retvals = mc.Get(keys, out cas);

			//List<string> keys2 = new List<string>(keys);
			//keys2.RemoveRange(0, 50);

			//IDictionary<string, object> retvals2 = mc.Get(keys2, out cas);
			//retvals2 = mc.Get(keys2, out cas);

			//ServerStats ms = mc.Stats();

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

			// retrieve the item from the cache
			Console.WriteLine(mc.Get("MyKey"));

			// 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 });


			//mc2.Store(StoreMode.Set, "D1", 1234L);
			//mc2.Store(StoreMode.Set, "D2", DateTime.Now);
			//mc2.Store(StoreMode.Set, "D3", true);
			//mc2.Store(StoreMode.Set, "D4", new Product());
			
			Console.WriteLine("D1: {0}", mc.Get("D1"));
			Console.WriteLine("D2: {0}", mc.Get("D2"));
			Console.WriteLine("D3: {0}", mc.Get("D3"));
			Console.WriteLine("D4: {0}", mc.Get("D4"));

			byte[] tmp = mc.Get<byte[]>("D5");

			// delete them from the cache
			mc.Remove("D1");
			mc.Remove("D2");
			mc.Remove("D3");
			mc.Remove("D4");

			ServerStats stats = mc.Stats();
			Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.ConnectionCount));
			Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.GetCount));

			// add an item which is valid for 10 mins
			mc.Store(StoreMode.Set, "D4", new Product(), new TimeSpan(0, 10, 0));

			Console.ReadLine();
		}
Exemple #14
0
        public static bool Initialize()
        {
            try
            {
                string[] serverlist = { "127.0.0.1" };

                //初始化池
                SockIOPool pool = SockIOPool.GetInstance();
                pool.SetServers(serverlist);

                pool.InitConnections = 3;
                pool.MinConnections  = 3;
                pool.MaxConnections  = 250;

                pool.SocketConnectTimeout = 1000;
                pool.SocketTimeout        = 3000;

                pool.MaintenanceSleep = 30;
                pool.Failover         = true;

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


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

                Loger.Debug(" memcached client Initialized ");
                System.Collections.Hashtable hsStats = new System.Collections.Hashtable(mc.Stats());
                foreach (DictionaryEntry s in hsStats)
                {
                    Loger.Debug(s.Key.ToString());
                    foreach (DictionaryEntry t in (Hashtable)s.Value)
                    {
                        Loger.Debug(t.Key.ToString() + " : " + t.Value.ToString());
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Loger.Debug("MemcachedClient Initialize error : " + ex.ToString());
                return(false);
            }
        }
        public ArrayList GetStats(ArrayList serverArrayList, Stats statsCommand, string param)
        {
            ArrayList statsArray = new ArrayList();

            param = string.IsNullOrEmpty(param) ? "" : param.Trim().ToLower();

            string commandstr = "stats";

            //转换stats命令参数
            switch (statsCommand)
            {
            case Stats.Reset: { commandstr = "stats reset"; break; }

            case Stats.Malloc: { commandstr = "stats malloc"; break; }

            case Stats.Maps: { commandstr = "stats maps"; break; }

            case Stats.Sizes: { commandstr = "stats sizes"; break; }

            case Stats.Slabs: { commandstr = "stats slabs"; break; }

            case Stats.Items: { commandstr = "stats items"; break; }

            case Stats.CachedDump: {
                string[] statsparams = param.Split(" ");
                if (statsparams.Length == 2)
                {
                    if (statsparams.IsNumberArray())
                    {
                        commandstr = "stats cachedump  " + param;
                    }
                }

                break;
            }

            case Stats.Detail: {
                if (string.Equals(param, "on") || string.Equals(param, "off") || string.Equals(param, "dump"))
                {
                    commandstr = "stats detail " + param.Trim();
                }

                break;
            }

            default: { commandstr = "stats"; break; }
            }
            //加载返回值
            Hashtable stats = mc.Stats(serverArrayList, commandstr);

            foreach (string key in stats.Keys)
            {
                statsArray.Add(key);
                Hashtable values = (Hashtable)stats[key];
                foreach (string key2 in values.Keys)
                {
                    statsArray.Add(key2 + ":" + values[key2]);
                }
            }
            return(statsArray);
        }
        private static string GoMemcached(string cs)
        {
            var parts = cs.Split(':');
            var host  = cs;
            int port  = 11211;

            if (parts.Length == 2)
            {
                host = parts[0];
                Int32.TryParse(parts[1], out port);
            }

            Func <IPAddress, int> order = ip => ip.ToString().IndexOf(".") >= 0 ? 1 : 2;
            IPAddress             address;

            if (!IPAddress.TryParse(host, out address))
            {
                IPAddress[] resolved = Dns.GetHostAddresses(host);
                var         ordered  = resolved.OrderBy(x => order(x)).ToArray();
                address = ordered.FirstOrDefault();
            }

            if (address == null)
            {
                throw new ArgumentException($"Unable to resolve IP Address of {cs}");
            }


            MemcachedClientOptions opts = new MemcachedClientOptions();

            opts.Protocol = MemcachedProtocol.Binary;
            var ipEndPoint        = new DnsEndPoint(host, port);
            var nullLoggerFactory = Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance;
            MemcachedClientConfiguration config = new MemcachedClientConfiguration(nullLoggerFactory, opts);

            config.Servers.Add(ipEndPoint);
            config.Protocol = MemcachedProtocol.Binary;

            // config.Authentication.Type = typeof(PlainTextAuthenticator);
            // config.Authentication.Parameters["userName"] = "******";
            // config.Authentication.Parameters["password"] = "******";

            var mc = new MemcachedClient(nullLoggerFactory, config);

            mc.Get($"PING_({Guid.NewGuid().ToString("N")})");
            // return "OK. TryGet took " + (sw.ElapsedTicks / Convert.ToDecimal(Stopwatch.Frequency)).ToString("f2") + " msec";

            Stopwatch   sw = Stopwatch.StartNew();
            ServerStats stats;

            try
            {
                stats = mc.Stats();
            }
            catch (NullReferenceException)
            {
                // yes, memcached client is buggy
                throw new Exception("No memcached connection is available to service this operation");
            }
            var rawVersion     = stats.GetRaw("version");
            var rawPointerSize = stats.GetRaw("pointer_size");
            var version        = rawVersion.FirstOrDefault().Value ?? "N/A";
            var pointerSize    = rawPointerSize.FirstOrDefault().Value;

            if (!string.IsNullOrEmpty(pointerSize))
            {
                version += $" [{pointerSize} bits]";
            }

            return(version);
        }
Exemple #17
0
		public void InvalidConfigurationTest()
		{
			MemcachedClient mc = new MemcachedClient("test/invalidConfig");

			mc.Stats();
		}
 /// <summary>
 /// 获取缓存服务器信息
 /// </summary>
 /// <returns></returns>
 public ServerStats GetServerInfo()
 {
     return(serverInfo ?? memClient.Stats());
 }
Exemple #19
0
        public static void test()
        {
            MemcachedClientConfiguration config = new MemcachedClientConfiguration();

            config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
            config.Protocol = MemcachedProtocol.Binary;
            //config.Authentication.Type = typeof(PlainTextAuthenticator);
            //config.Authentication.Parameters["userName"] = "******";
            //config.Authentication.Parameters["password"] = "******";

            var mc = new MemcachedClient(config);

            for (var i = 0; i < 100; i++)
            {
                mc.Store(StoreMode.Set, "Hello", "World");
            }


            // simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
            List <string> keys = new List <string>();

            for (int i = 1; i < 100; i++)
            {
                string k = "aaaa" + i + "--" + (i * 2);
                keys.Add(k);

                mc.Store(StoreMode.Set, k, i);
            }

            IDictionary <string, ulong>  cas;
            IDictionary <string, object> retvals = mc.Get(keys);

            List <string> keys2 = new List <string>(keys);

            keys2.RemoveRange(0, 50);

            IDictionary <string, object> retvals2 = mc.Get(keys2);

            retvals2 = mc.Get(keys2);

            ServerStats ms = mc.Stats();

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

            // retrieve the item from the cache
            Console.WriteLine(mc.Get("MyKey"));

            Console.WriteLine(mc.Increment("num1", 1, 10));
            Console.WriteLine(mc.Increment("num1", 1, 10));
            Console.WriteLine(mc.Decrement("num1", 1, 14));

            // 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 Person());

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


            //mc2.Store(StoreMode.Set, "D1", 1234L);
            //mc2.Store(StoreMode.Set, "D2", DateTime.Now);
            //mc2.Store(StoreMode.Set, "D3", true);
            //mc2.Store(StoreMode.Set, "D4", new Product());

            Console.WriteLine("D1: {0}", mc.Get("D1"));
            Console.WriteLine("D2: {0}", mc.Get("D2"));
            Console.WriteLine("D3: {0}", mc.Get("D3"));
            Console.WriteLine("D4: {0}", mc.Get("D4"));

            byte[] tmp = mc.Get <byte[]>("D5");

            // delete them from the cache
            mc.Remove("D1");
            mc.Remove("D2");
            mc.Remove("D3");
            mc.Remove("D4");

            ServerStats stats = mc.Stats();

            Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.ConnectionCount));
            Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.GetCount));

            // add an item which is valid for 10 mins
            mc.Store(StoreMode.Set, "D4", new Person(), new TimeSpan(0, 10, 0));
        }
 public ServerStats Stats()
 {
     return(_client.Stats());
 }
Exemple #21
0
 public static ServerStats Stats()
 {
     return(mc.Stats());
 }
Exemple #22
0
        public static void sockpool()
        {
            String[] serverlist = { "10.2.3.62:11211", "10.2.3.173:11211" };
            int      runs       = 100;
            int      start      = 200;

            // initialize the pool for memcache servers
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            pool.InitConnections = 3;
            pool.MinConnections  = 3;
            pool.MaxConnections  = 5;

            pool.SocketConnectTimeout = 1000;
            pool.SocketTimeout        = 3000;

            pool.MaintenanceSleep = 30;
            pool.Failover         = true;

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

            //			// get client instance
            MemcachedClient mc = new MemcachedClient();

            mc.EnableCompression = false;

            //			MemcachedClient mc = new MemcachedClient();
            //			mc.CompressEnable = false;
            //			mc.CompressThreshold = 0;
            //			mc.Serialize = true;

            string keyBase = "testKey";
            string obj     = "This is a test of an object blah blah es, serialization does not seem to slow things down so much.  The gzip compression is horrible horrible performance, so we only use it for very large objects.  I have not done any heavy benchmarking recently";

            long begin = DateTime.Now.Ticks;

            for (int i = start; i < start + runs; i++)
            {
                mc.Set(keyBase + i, obj);
            }
            long end  = DateTime.Now.Ticks;
            long time = end - begin;

            Console.WriteLine(runs + " sets: " + new TimeSpan(time).ToString() + "ms");

            begin = DateTime.Now.Ticks;
            int hits   = 0;
            int misses = 0;

            for (int i = start; i < start + runs; i++)
            {
                string str = (string)mc.Get(keyBase + i);
                if (str != null)
                {
                    ++hits;
                }
                else
                {
                    ++misses;
                }
            }
            end  = DateTime.Now.Ticks;
            time = end - begin;

            Console.WriteLine(runs + " gets: " + new TimeSpan(time).ToString() + "ms");
            Console.WriteLine("Cache hits: " + hits.ToString());
            Console.WriteLine("Cache misses: " + misses.ToString());

            IDictionary stats = mc.Stats();

            foreach (string key1 in stats.Keys)
            {
                Console.WriteLine(key1);
                Hashtable values = (Hashtable)stats[key1];
                foreach (string key2 in values.Keys)
                {
                    Console.WriteLine(key2 + ":" + values[key2]);
                }
                Console.WriteLine();
            }

            SockIOPool.GetInstance().Shutdown();
            Console.ReadLine();
        }
Exemple #23
0
        public static void test()
        {
            MemcachedClientConfiguration config = new MemcachedClientConfiguration();
            config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
            config.Protocol = MemcachedProtocol.Binary;
            //config.Authentication.Type = typeof(PlainTextAuthenticator);
            //config.Authentication.Parameters["userName"] = "******";
            //config.Authentication.Parameters["password"] = "******";

            var mc = new MemcachedClient(config);

            for (var i = 0; i < 100; i++)
                mc.Store(StoreMode.Set, "Hello", "World");

            // simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
            List<string> keys = new List<string>();

            for (int i = 1; i < 100; i++)
            {
                string k = "aaaa" + i + "--" + (i * 2);
                keys.Add(k);

                mc.Store(StoreMode.Set, k, i);
            }

            IDictionary<string, ulong> cas;
            IDictionary<string, object> retvals = mc.Get(keys);

            List<string> keys2 = new List<string>(keys);
            keys2.RemoveRange(0, 50);

            IDictionary<string, object> retvals2 = mc.Get(keys2);
            retvals2 = mc.Get(keys2);

            ServerStats ms = mc.Stats();

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

            // retrieve the item from the cache
            Console.WriteLine(mc.Get("MyKey"));

            Console.WriteLine(mc.Increment("num1", 1, 10));
            Console.WriteLine(mc.Increment("num1", 1, 10));
            Console.WriteLine(mc.Decrement("num1", 1, 14));

            // 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 Person());

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

            //mc2.Store(StoreMode.Set, "D1", 1234L);
            //mc2.Store(StoreMode.Set, "D2", DateTime.Now);
            //mc2.Store(StoreMode.Set, "D3", true);
            //mc2.Store(StoreMode.Set, "D4", new Product());

            Console.WriteLine("D1: {0}", mc.Get("D1"));
            Console.WriteLine("D2: {0}", mc.Get("D2"));
            Console.WriteLine("D3: {0}", mc.Get("D3"));
            Console.WriteLine("D4: {0}", mc.Get("D4"));

            byte[] tmp = mc.Get<byte[]>("D5");

            // delete them from the cache
            mc.Remove("D1");
            mc.Remove("D2");
            mc.Remove("D3");
            mc.Remove("D4");

            ServerStats stats = mc.Stats();
            Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.ConnectionCount));
            Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.GetCount));

            // add an item which is valid for 10 mins
            mc.Store(StoreMode.Set, "D4", new Person(), new TimeSpan(0, 10, 0));
        }