• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#操作Memcached

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DataSet数据导入Excel 修正版- .net FrameWork 4.0以上发布时间:2022-07-14
下一篇:
C#Attribute(转)发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap