예제 #1
0
 public TCacheGetTests()
 {
     using (TCacheService cache = new TCacheService())
     {
         bool cleaned = cache.RemoveKey(TestQueueName).Result&& cache.RemoveKey(TestQueueNameSecond).Result;
     }
 }
예제 #2
0
        public async Task SearchKeyValues()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test2:5", "test1");

                await cache.SetObjectAsKeyValue("user:test2:6", "test2");

                await cache.SetObjectAsKeyValue("user:test2:7", "test3");

                await cache.SetObjectAsKeyValue("user:test2:8", "test4");

                var results = await cache.SearchKeyValues("user:test2*");

                bool resultCheck = results.ContainsValue("test1") && results.ContainsValue("test2") && results.ContainsValue("test3") && results.ContainsValue("test4");

                Assert.Equal(4, results.Count);
                Assert.True(resultCheck);

                foreach (var item in results.Keys)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
예제 #3
0
        public async Task SearchKeyValuesTyped()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test3:9", new Cat { Name = "Ted" });

                await cache.SetObjectAsKeyValue("user:test3:10", new Cat { Name = "Fred" });

                await cache.SetObjectAsKeyValue("user:test3:11", new Cat { Name = "Ned" });

                await cache.SetObjectAsKeyValue("user:test3:12", new Cat { Name = "Bed" });

                var results = await cache.SearchKeyValues <Cat>("user:test3*");

                List <string> resultValues = results.Values.Select(x => x.Name).ToList();

                bool resultCheck = resultValues.Contains("Ted") && resultValues.Contains("Fred") && resultValues.Contains("Ned") && resultValues.Contains("Bed");

                Assert.Equal(4, results.Count);
                Assert.True(resultCheck);

                foreach (var item in results.Keys)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
예제 #4
0
 public TCacheCreatePushTests()
 {
     using (TCacheService cache = new TCacheService())
     {
         bool cleaned = cache.RemoveKey(TestQueueName).Result;
     }
 }
예제 #5
0
        public async Task RemoveKeyNoKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                bool result = await cache.RemoveKey("blah blah blah");

                Assert.True(result);
            }
        }
예제 #6
0
        public async Task RemoveQueue()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.RemoveKey(TestQueueName);

                bool exists = await cache.QueueExists(TestQueueName);

                Assert.False(exists);
            }
        }
예제 #7
0
        public async Task TypedValueFetch()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test5", new Cat { Name = "Billy", Age = 90 });

                var result = await cache.GetValueFromKey <Cat>("test5");

                await cache.RemoveKey("test5");

                Assert.True(result is Cat && result.Name == "Billy" && result.Age == 90);
            }
        }
예제 #8
0
        public async Task SetKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test2", "hi!");

                string value = await cache.GetValueFromKey("test2");

                await cache.RemoveKey("test2");

                Assert.Equal("hi!", value);
            }
        }
예제 #9
0
        public async Task KeyExistsTest()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test6", "test");

                bool result = await cache.KeyExists("test6");

                await cache.RemoveKey("test6");

                Assert.True(result);
            }
        }
예제 #10
0
        /// <summary>
        /// Remove a user
        /// </summary>
        /// <param name="removeUser"></param>
        /// <returns></returns>
        public async Task <bool> RemoveUser(User removeUser)
        {
            User foundUser = await GetUser(removeUser);

            if (foundUser == null)
            {
                throw new UserNotFoundException();
            }

            await _cacheService.RemoveKey(_userPrefix + foundUser._Id.ToString());

            return(true);
        }
예제 #11
0
        public async Task RemoveKeyWithKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                // set
                await cache.SetObjectAsKeyValue("test1", "blah blah blah");

                // remove
                await cache.RemoveKey("test1");

                // check
                string result = await cache.GetValueFromKey("test1");

                // asert
                Assert.Null(result);
            }
        }
예제 #12
0
        public async Task SearchKeys()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test1:1", "test");

                await cache.SetObjectAsKeyValue("user:test1:2", "test");

                await cache.SetObjectAsKeyValue("user:test1:3", "test");

                await cache.SetObjectAsKeyValue("user:test1:4", "test");

                List <string> results = await cache.SearchKeys("user:test1*");

                Assert.Equal(4, results.Count);

                foreach (var item in results)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
예제 #13
0
 public async Task <bool> RemoveKey(string keyName)
 {
     return(await _cacheService.RemoveKey(keyName));
 }