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


C# MemcachedClient.Get方法代码示例

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


在下文中一共展示了MemcachedClient.Get方法的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: RunProgram

        public void RunProgram()
        {
            const string key = "testkey";
            var cacheClient = new MemcachedClient(ConfigurationManager.GetSection("enyim.com/memcached") as IMemcachedClientConfiguration);
            cacheClient.Store(StoreMode.Add, key, "testvalue");
            var item = cacheClient.Get(key);
            Console.WriteLine(item);

            cacheClient.Store(StoreMode.Set, key, "something else");
            item = cacheClient.Get(key);
            Console.WriteLine(item);
        }
开发者ID:GrahamClark,项目名称:TestConsoleApp,代码行数:12,代码来源:Runner.cs

示例3: Get_Study

        public void Get_Study()
        {
            using (var client = new MemcachedClient())
            {
                // 没有键,返回null。
                var result1 = client.Get("userid");
                Assert.Null(result1);

                client.Store(StoreMode.Set, "userid", "123456");
                var result2 = client.Get("userid");
                Assert.AreEqual("123456", result2);

                client.FlushAll();
            }
        }
开发者ID:happyframework,项目名称:Study.Memcached,代码行数:15,代码来源:MemcachedClientStudy.cs

示例4: 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

示例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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: CanCacheList

        public void CanCacheList()
        {
            var client = new MemcachedClient();
            var list = new List<string> { "a", "b" };

            client.Store(StoreMode.Set, "d", list);

            var result = client.Get<List<string>>("d");
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("a", result[0]);
            Assert.AreEqual("b", result[1]);
        }
开发者ID:mbjurman,项目名称:Hacks,代码行数:12,代码来源:MemcachedTests.cs

示例11: 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

示例12: MemcachedContainerStrategy

        static MemcachedContainerStrategy()
        {
            // //初始化memcache服务器池
            //SockIOPool pool = SockIOPool.GetInstance();
            ////设置Memcache池连接点服务器端。
            //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();

            //cache = new MemcachedClient();
            //cache.EnableCompression = false;
            try
            {
                //config.Authentication.Type = typeof(PlainTextAuthenticator);
                //config.Authentication.Parameters["userName"] = "username";
                //config.Authentication.Parameters["password"] = "password";
                //config.Authentication.Parameters["zone"] = "zone";//domain?   ——Jeffrey 2015.10.20
                DateTime dt1 = DateTime.Now;
                var config = GetMemcachedClientConfiguration();
                var cache = new MemcachedClient(config);

                var testKey = Guid.NewGuid().ToString();
                var testValue = Guid.NewGuid().ToString();
                cache.Store(StoreMode.Set, testKey, testValue);
                var storeValue = cache.Get(testKey);
                if (storeValue as string != testValue)
                {
                    throw new Exception("MemcachedStrategy失效,没有计入缓存!");
                }
                cache.Remove(testKey);
                DateTime dt2 = DateTime.Now;

                WeixinTrace.Log(string.Format("MemcachedStrategy正常启用,启动及测试耗时:{0}ms", (dt2 - dt1).TotalMilliseconds));
            }
            catch (Exception ex)
            {
                //TODO:记录是同日志
                WeixinTrace.Log(string.Format("MemcachedStrategy静态构造函数异常:{0}", ex.Message));
            }
        }
开发者ID:CurryHan,项目名称:WeiXinMPSDK,代码行数:52,代码来源:MemcachedContainerStrategy.cs

示例13: TestIfCalled

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

			config.SocketPool.FailurePolicyFactory = new FakePolicy();
			config.SocketPool.ConnectionTimeout = TimeSpan.FromSeconds(4);
			config.SocketPool.ReceiveTimeout = TimeSpan.FromSeconds(6);

			var client = new MemcachedClient(config);

			Assert.IsNull(client.Get("a"), "Get should have failed.");
		}
开发者ID:623442733,项目名称:EnyimMemcached,代码行数:13,代码来源:FailurePolicyTest.cs

示例14: AddSetReplaceTest

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

            Assert.AreEqual("1", mc.Get("VALUE"), "Store failed");

            mc.Store(StoreMode.Add, "VALUE", "2");
            Assert.AreEqual("1", mc.Get("VALUE"), "Item should not have been Added");

            mc.Store(StoreMode.Replace, "VALUE", "4");
            Assert.AreEqual("4", mc.Get("VALUE"), "Replace failed");

            mc.Remove("VALUE");

            mc.Store(StoreMode.Replace, "VALUE", "8");
            Assert.IsNull(mc.Get("VALUE"), "Item should not have been Replaced");

            mc.Remove("VALUE");

            mc.Store(StoreMode.Add, "VALUE", "16");
            Assert.AreEqual("16", mc.Get("VALUE"), "Add failed");
        }
开发者ID:jamesmalcolmphillips,项目名称:EnyimMemcached,代码行数:23,代码来源:MemcachedClientTest.cs

示例15: StoreWithDefaultTranscoder

 public void StoreWithDefaultTranscoder()
 {
     var config = GetConfig();
     SomeType obj = new SomeType { Id = 1, Name = "abc" }, clone;
     using (var client = new MemcachedClient(config))
     {
         client.Store(StoreMode.Set, "raw1", obj);
     }
     using (var client = new MemcachedClient(config))
     {
         clone = (SomeType) client.Get("raw1");
     }
     Assert.AreEqual(1, clone.Id);
     Assert.AreEqual("abc", clone.Name);
 }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:15,代码来源:BasicTests.cs


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