public async Task ExpirationTestTimeSpan()
        {
            using (MemcachedClient client = GetClient())
            {
                var cacheKey = $"ExpirationTest-TimeSpan-{new Random().Next()}";
                Assert.True(await client.StoreAsync(StoreMode.Set, cacheKey, "ExpirationTest:TimeSpan", new TimeSpan(0, 0, 3)), "Expires:Timespan failed");
                Assert.Equal("ExpirationTest:TimeSpan", await client.GetValueAsync <string>(cacheKey));

                await Task.Delay(TimeSpan.FromSeconds(4));

                Assert.Null(await client.GetValueAsync <string>(cacheKey));
            }
        }
        public async Task ExpirationTestDateTime()
        {
            using (MemcachedClient client = GetClient())
            {
                var      cacheKey  = $"Expires-DateTime-{new Random().Next()}";
                DateTime expiresAt = DateTime.Now.AddSeconds(3);
                Assert.True(await client.StoreAsync(StoreMode.Set, cacheKey, "Expires:DateTime", expiresAt), "Expires:DateTime failed");
                Assert.Equal("Expires:DateTime", await client.GetValueAsync <string>(cacheKey));

                await Task.Delay(TimeSpan.FromSeconds(4));

                Assert.Null(await client.GetValueAsync <string>(cacheKey));
            }
        }
        public async Task StoreStringTest()
        {
            using (MemcachedClient client = GetClient())
            {
                Assert.True(await client.StoreAsync(StoreMode.Set, "TestString", "Hello world!", DateTime.Now.AddSeconds(10)), "StoreString failed.");

                Assert.Equal("Hello world!", await client.GetValueAsync <string>("TestString"));
            }
        }
 /// <summary>
 /// 获取缓存
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static async Task <object> GetAsnyAsync(string key)
 {
     try
     {
         key = _DEPEND_ + "_" + key.ToLower();
         return(await mclient.GetValueAsync <object>(key));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public async Task IncrementNoDefaultTest()
        {
            using (MemcachedClient client = GetClient())
            {
                Assert.Equal((ulong)2, client.Increment("VALUE", 2, 2));
                Assert.Equal((ulong)4, client.Increment("VALUE", 2, 2));

                var value = await client.GetValueAsync <string>("VALUE");

                Assert.Equal("4", value);
            }
        }
Exemple #6
0
        public async Task FlushTest()
        {
            using (MemcachedClient client = GetClient())
            {
                for (int i = 0; i < 10; i++)
                {
                    string cacheKey = $"Hello_Flush_{i}";
                    Assert.True(await client.StoreAsync(StoreMode.Set, cacheKey, i, DateTime.Now.AddSeconds(30)));
                }

                await client.FlushAllAsync();

                for (int i = 0; i < 10; i++)
                {
                    string cacheKey = $"Hello_Flush_{i}";
                    Assert.Null(await client.GetValueAsync <string>(cacheKey));
                }
            }
        }