当前位置: 首页>>代码示例>>C#>>正文


C# MemcachedClient类代码示例

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


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


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