C#操作Memcached

來源:互聯網
上載者:User

標籤:

memcached用戶端庫

.Net memcached client
https://sourceforge.net/projects/memcacheddotnet

.Net 2.0 memcached client
http://www.codeplex.com/EnyimMemcached

Client developed in .NET 2.0 keeping performance and extensibility in mind. (Supports consistent hashing.)
http://www.codeplex.com/memcachedproviders

BeIT Memcached Client (optimized C# 2.0)
http://code.google.com/p/beitmemcached

 

            int runs = 100;            int start = 200;            if(args.Length > 1)            {                runs = int.Parse(args[0]);                start = int.Parse(args[1]);            }            string[] serverlist = { "192.168.0.191:11211" };//可以添加多個伺服器            //為伺服器初始化IO串連池 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();//            SockIOPool pool = SockIOPool.Instance;//            pool.Servers = serverlist;//            pool.InitConn = 5;//            pool.MinConn = 5;//            pool.MaxConn = 50;//            pool.MaintSleep = 30;//            pool.SocketTO = 1000;//            pool.Nagle = false;//            pool.Initialize();

//建立一個用戶端執行個體 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 = "這是緩衝的內容,如果很大,注意序列化的開銷。也可以壓縮後傳輸。東莞市長安鎮圖書館。"; 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();

 

C#操作Memcached

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.