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


C# MemcachedClient.Store方法代码示例

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


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

        public void Add_Study()
        {
            using (var client = new MemcachedClient())
            {
                var result1 = client.Store(StoreMode.Add, "userid", "123456");
                Assert.True(result1);

                // 不可以多次调用
                var result2 = client.Store(StoreMode.Add, "userid", "123456");
                Assert.False(result2);

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

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

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

示例6: Replace_Study

        public void Replace_Study()
        {
            using (var client = new MemcachedClient())
            {
                // 没有键,不能替换。
                var result1 = client.Store(StoreMode.Replace, "userid", "123456");
                Assert.False(result1);

                // 有的话,就可以。
                client.Store(StoreMode.Add, "userid", "123456");
                var result2 = client.Store(StoreMode.Replace, "userid", "123456");
                Assert.True(result2);

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

示例7: AddCache

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

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

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

 public void NullCache() {
     using (MemcachedClient client = new MemcachedClient("enyim.com/memcached")) {
         String key = Guid.NewGuid().ToString("n");
         Object value = null;
         client.Store(StoreMode.Set, key, value);
         var exist = client.TryGet(key, out value);
         Assert.IsTrue(exist);
         Assert.IsNull(value);
     }
 }
开发者ID:wxr524720,项目名称:Jusfr.Caching,代码行数:10,代码来源:MemcachedTest.cs

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

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

示例14: CanCacheDTO

        public void CanCacheDTO()
        {
            var client = new MemcachedClient();
            var obj = new Dto
            {
                Name = "b",
                Title = "c"
            };

            client.Store(StoreMode.Set, "c", obj);
            var result = client.Get<Dto>("c");

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

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


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