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

C# MemcachedClient类代码示例

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

本文整理汇总了C#中MemcachedClient的典型用法代码示例。如果您正苦于以下问题:C# MemcachedClient类的具体用法?C# MemcachedClient怎么用?C# MemcachedClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MemcachedClient类属于命名空间,在下文中一共展示了MemcachedClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StoreWithProtoTranscoder

        public void StoreWithProtoTranscoder()
        {
            var config = GetConfig();
            var transcoder = new ProtoBuf.Caching.Enyim.NetTranscoder();
            config.Transcoder =  transcoder;
            SomeType obj = new SomeType { Id = 1, Name = "abc" }, clone;
            string cloneString;
            Assert.AreEqual(0, transcoder.Deserialized);
            Assert.AreEqual(0, transcoder.Serialized);
            using (var client = new MemcachedClient(config))
            {
                client.Store(StoreMode.Set, "raw1", obj);
                client.Store(StoreMode.Set, "raw2", "def");
            }
            Assert.AreEqual(0, transcoder.Deserialized);
            Assert.AreEqual(1, transcoder.Serialized);
            using (var client = new MemcachedClient(config))
            {
                clone = (SomeType)client.Get("raw1");
                cloneString = (string)client.Get("raw2");
            }
            Assert.AreEqual(1, transcoder.Deserialized);
            Assert.AreEqual(1, transcoder.Serialized);

            Assert.AreEqual(1, clone.Id);
            Assert.AreEqual("abc", clone.Name);
            Assert.AreEqual("def", cloneString);
        }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:28,代码来源:BasicTests.cs


示例2: IsExists

 /// <summary>
 /// 是否存在该缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <returns></returns>
 public static bool IsExists(string key)
 {
     using (MemcachedClient mc = new MemcachedClient())
     {
         return mc.Get(key) != null;
     }
 }
开发者ID:cityjoy,项目名称:CommonToolkit,代码行数:12,代码来源:EnyimMemcacheHelper).cs


示例3: AddCache

 /// <summary>
 /// 添加缓存(键不存在则添加,存在则替换)
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="minutes">缓存时间(分钟)</param>
 /// <returns></returns>
 public static bool AddCache(string key, object value, int minutes)
 {
     using (MemcachedClient mc = new MemcachedClient())
     {
         return mc.Store(StoreMode.Set, key, value, DateTime.Now.AddMinutes(minutes));
     }
 }
开发者ID:cityjoy,项目名称:CommonToolkit,代码行数:14,代码来源:EnyimMemcacheHelper).cs


示例4: GetClient

        protected override MemcachedClient GetClient()
        {
            MemcachedClient client = new MemcachedClient("test/binaryConfig");
            client.FlushAll();

            return client;
        }
开发者ID:sneal,项目名称:EnyimMemcached,代码行数:7,代码来源:BinaryMemcachedClientTest.cs


示例5: MemcachedLocker

        public MemcachedLocker(MemcachedClient client, string key, TimeSpan timeOut)
        {
            this.client = client;
            this.key = key;
            this.timeOut = timeOut;

            int sleep = 10;
            DateTime now = DateTime.Now;
            while (DateTime.Now - now < timeOut)
            {
                if (client.Add<DateTime?>(key, DateTime.Now.Add(timeOut)))
                    return;

                //需要排除锁未释放的可能,如果检测到超过超时时间2倍的话,尝试获得锁
                ulong version;
                var time = client.Get<DateTime?>(key, out version);
                if (time == null || (time.HasValue && time.Value.ToLocalTime().Add(timeOut + timeOut) < DateTime.Now))
                {
                    LocalLoggingService.Warning("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "MemcachedLocker", "MemcachedLocker",
                                        string.Format("发现一个超时的分布式锁,超时时间:{0} Key : {1}",
                                        time, key));
                    if (client.Add<DateTime?>(key, DateTime.Now.Add(timeOut), version))
                        return;
                }

                if (sleep < 1000)
                    sleep = sleep * 110 / 100;
                else
                    sleep = 1000;

                Thread.Sleep(sleep);
            }

            throw new TimeoutException(string.Format("获得锁的时间超过了设定的最大时间 {0}", timeOut.ToString()));
        }
开发者ID:yhhno,项目名称:Adhesive,代码行数:35,代码来源:MemcachedLocker.cs


示例6: TestThem

        public void TestThem(List<string> servers)
        {
            var mbc = new MemcachedClientConfiguration();
            foreach (var server in servers)
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(server), 11211);
                mbc.Servers.Add(endPoint);
            }

            _couchbaseClient = new MemcachedClient(mbc);

            _couchbaseClient.Store(StoreMode.Set, Key, Value);
            Debug.Assert((string)_couchbaseClient.Get(Key) == Value);

            List<Thread> workers = new List<Thread>();

            for (int s = 0; s < NumThreads; s++)
            {
                Thread workerThread = new Thread(Run);
                workerThread.Start();
                workers.Add(workerThread);
            }

            foreach (var thread in workers)
            {
                while (thread.IsAlive)
                {
                    Thread.Sleep(1);
                }

                thread.Join();
            }
        }
开发者ID:vitaly-rudenya,项目名称:couchbasenodeaddspy,代码行数:33,代码来源:Program.cs


示例7: TestThrottlingFailurePolicy

		public void TestThrottlingFailurePolicy()
		{
			var config = new MemcachedClientConfiguration();
			config.AddServer("nonexisting.enyim.com:2244");

			config.SocketPool.FailurePolicyFactory = new ThrottlingFailurePolicyFactory(4, TimeSpan.FromMilliseconds(2000));
			config.SocketPool.ConnectionTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromMilliseconds(10);
			config.SocketPool.MinPoolSize = 1;
			config.SocketPool.MaxPoolSize = 1;

			var client = new MemcachedClient(config);
			var canFail = false;
			var didFail = false;

			client.NodeFailed += node =>
			{
				Assert.IsTrue(canFail, "canfail");

				didFail = true;
			};

			Assert.IsNull(client.Get("a"), "Get should have failed. 1");
			Assert.IsNull(client.Get("a"), "Get should have failed. 2");

			canFail = true;
			Thread.Sleep(2000);

			Assert.IsNull(client.Get("a"), "Get should have failed. 3");
			Assert.IsNull(client.Get("a"), "Get should have failed. 4");
			Assert.IsNull(client.Get("a"), "Get should have failed. 5");
			Assert.IsNull(client.Get("a"), "Get should have failed. 6");

			Assert.IsTrue(didFail, "didfail");
		}
开发者ID:623442733,项目名称:EnyimMemcached,代码行数:35,代码来源:FailurePolicyTest.cs


示例8: SetUp

        public void SetUp()
        {
            var config = new MemcachedClientConfiguration();
            config.AddServer("127.0.0.1", 11211);

            _Client = new MemcachedClient(config);
        }
开发者ID:enyim,项目名称:EnyimMemcached,代码行数:7,代码来源:MemcachedClientTestsBase.cs


示例9: Initialize

		public override void Initialize(string name, NameValueCollection config)
		{
			if (config == null)
			{
				throw new ArgumentNullException("config");
			}
			if (string.IsNullOrEmpty(name))
			{
				name = "MemcachedProviders.CacheProvider";
			}
			if (string.IsNullOrEmpty(config["description"]))
			{
				config.Remove("description");
				config.Add("description", "Memcached Cache Provider");
			}

			base.Initialize(name, config);

			if (String.IsNullOrEmpty(config["section"]))
			{
				throw new ArgumentException("未配置 section 属性。");
			}

			IMemcachedClientConfiguration section = (IMemcachedClientConfiguration)this.Configuration.GetSection(config["section"]);
			if (section == null)
			{
				throw new ConfigurationErrorsException(String.Format("未找到适用于 MemcachedDistributeCacheProvider 的配置节 {0}", config["section"]));
			}

			this.client = new CustomMemcachedClient(section);
		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:31,代码来源:MemcachedDistributeCacheProvider.cs


示例10: TestFixtureSetUp

		public void TestFixtureSetUp()
		{
			hasher = new SHA1Hasher();
			instances = new MemcachedInstances(100, Common.Properties.MainCacheServerIPEndPoints);
			mc = new MemcachedClient(instances, hasher);
			
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:7,代码来源:ClientTests.cs


示例11: testMemcachedProviders

        static void testMemcachedProviders()  
        {
            MemcachedClient client = new MemcachedClient("enyim.com/memcached");
            //存值  --不带过期时间的存储,Memcached将根据LRU来决定过期策略  
            bool result = client.Store(Enyim.Caching.Memcached.StoreMode.Add, "name", "dinglang");
            
            //带过期时间的缓存    
            //bool success = client.Store(StoreMode.Add, person.UserName, person, DateTime.Now.AddMinutes(10));   
            if (result)
            {
                Console.Write("成功存入缓存");

                //取值    
                object name = client.Get("name");
                if (name != null)
                {
                    Console.Write("取出的值为:" + name);
                }
                else
                {
                    Console.Write("取值失败");
                }
            }
            else
            {
                Console.Write("存入缓存失败");
            }
        }    
开发者ID:WondersGroupBioBank,项目名称:BioBank,代码行数:28,代码来源:Program.cs


示例12: ElasticacheClient

        public ElasticacheClient(string regionName, IDictionary<string, string> properties, MemcachedClient memcachedClient)
        {
            _region = regionName;
            _client = memcachedClient;
            _expiry = 300;

            if (properties == null) return;

            var expirationString = GetExpirationString(properties);
            if (expirationString != null)
            {
                _expiry = Convert.ToInt32(expirationString);
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("using expiration of {0} seconds", _expiry);
                }
            }

            if (properties.ContainsKey("regionPrefix"))
            {
                _regionPrefix = properties["regionPrefix"];
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("new regionPrefix :{0}", _regionPrefix);
                }
            }
            else
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("no regionPrefix value given, using defaults");
                }
            }
        }
开发者ID:henriquecampos,项目名称:NHibernate.Caches.Elasticache,代码行数:34,代码来源:ElasticacheClient.cs


示例13: GetCache

 /// <summary>
 /// 获取缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <returns>返回缓存,没有找到则返回null</returns>
 public static object GetCache(string key)
 {
     using (MemcachedClient mc = new MemcachedClient())
     {
         return mc.Get(key);
     }
 }
开发者ID:cityjoy,项目名称:CommonToolkit,代码行数:12,代码来源:EnyimMemcacheHelper).cs


示例14: Initialize

 public static void Initialize(Enyim.Caching.Configuration.MemcachedClientConfiguration config)
 {
     if (client != null)
     {
         throw new Exception("MemcachedClient has already been initialized");
     }
     client = new MemcachedClient(config);
 }
开发者ID:Costo,项目名称:BikeShare,代码行数:8,代码来源:Cache.cs


示例15: InitialiseInternal

 protected override void InitialiseInternal()
 {
     if (_cache == null)
     {
         Log.Debug("MemcachedCache.Initialise - initialising");
         _cache = new MemcachedClient();
     }
 }
开发者ID:Narinyir,项目名称:caching,代码行数:8,代码来源:MemcachedCache.cs


示例16: DecrementTest

        public void DecrementTest()
        {
            MemcachedClient mc = new MemcachedClient();
            mc.Store(StoreMode.Set, "VALUE", "100");

            Assert.AreEqual(98L, mc.Decrement("VALUE", 2));
            Assert.AreEqual(88L, mc.Decrement("VALUE", 10));
        }
开发者ID:jamesmalcolmphillips,项目名称:EnyimMemcached,代码行数:8,代码来源:MemcachedClientTest.cs


示例17: ConfigurationTest

        public void ConfigurationTest() {
            using(var client = new MemcachedClient()) {
                client.ShouldNotBeNull("client");

                //client.Cas(StoreMode.Set, "item1", 1);
                //client.Cas(StoreMode.Set, "item2", 2);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:8,代码来源:MemcachedClientFixture.cs


示例18: CanCacheString

        public void CanCacheString()
        {
            var client = new MemcachedClient();

            client.Store(StoreMode.Add, "a", "b");
            var result = client.Get<string>("a");

            Assert.AreEqual("b", result);
        }
开发者ID:mbjurman,项目名称:Hacks,代码行数:9,代码来源:MemcachedTests.cs


示例19: MemcachedDistributeCache

		internal MemcachedDistributeCache(MemcachedClient client, string cacheName, string regionName, TimeSpan asyncTimeToLive, TimeSpan asyncUpdateInterval)
		{
			this.client = client;
			this.cacheName = cacheName;
			this.regionName = regionName;

			this.asyncTimeToLive = asyncTimeToLive;
			this.asyncUpdateInterval = asyncUpdateInterval;
		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:9,代码来源:MemcachedDistributeCache.cs


示例20: ResetMemcached

 /// <summary>
 /// 创建Memcached
 /// </summary>
 /// <returns></returns>
 private static MemcachedClient ResetMemcached()
 {
     if (memcached != null) { memcached = null; }
     memcached = MemcachedClient.GetInstance();
     memcached.SendReceiveTimeout = 5000;
     memcached.MaxPoolSize = 1000;
     memcached.MinPoolSize = 10;
     return memcached;
 }
开发者ID:jyk1987,项目名称:sdn,代码行数:13,代码来源:CacheClient.cs



注:本文中的MemcachedClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Memory类代码示例发布时间:2022-05-24
下一篇:
C# MembershipUser类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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