示例#1
0
        /// <inheritdoc/>
        public async Task <long> RemoveByTagAsync(string tag, CommandFlags commandFlags = CommandFlags.None)
        {
            var tagKey = TagHelper.GenerateTagKey(tag);

            var keys = await SetMembersAsync <string>(tagKey, commandFlags).ConfigureAwait(false);

            return(await RemoveAllAsync(keys, commandFlags).ConfigureAwait(false));
        }
示例#2
0
        /// <inheritdoc/>
        public async Task <IEnumerable <T> > GetByTagAsync <T>(string tag, CommandFlags commandFlags = CommandFlags.None)
        {
            var tagKey = TagHelper.GenerateTagKey(tag);

            var keys = await SetMembersAsync <string>(tagKey, commandFlags).ConfigureAwait(false);

            var result = await GetAllAsync <T>(keys).ConfigureAwait(false);

            return(result.Values);
        }
        public async Task AddAsyncTimeSpan_WithTags_TagExists()
        {
            const string testKey   = "test_key";
            const string testValue = "test_value";
            var          testClass = new TestClass <string>(testKey, testValue);
            const string testTag   = "test_tag";

            await Sut.GetDbFromConfiguration().AddAsync(testKey, testClass, TimeSpan.FromSeconds(1), tags: new HashSet <string> {
                testTag
            });

            var tagExists = await db.KeyExistsAsync(TagHelper.GenerateTagKey(testTag));

            Assert.True(tagExists);
        }
        public async Task AddAsync_WithTags_CorrectTaggedKey()
        {
            const string testKey   = "test_key";
            const string testValue = "test_value";
            var          testClass = new TestClass <string>(testKey, testValue);
            const string testTag   = "test_tag";

            await Sut.GetDbFromConfiguration().AddAsync(testKey, testClass, tags: new HashSet <string> {
                testTag
            });

            var tags = await db.SetMembersAsync(TagHelper.GenerateTagKey(testTag));

            var deserialized = tags?.Length > 0 ? serializer.Deserialize <string>(tags[0]) : string.Empty;

            Assert.Equal(testKey, deserialized);
        }