Ejemplo n.º 1
0
        private async Task <List <TValue> > GetAllItemsFromSetAsync <TValue>(string setCacheKey) where TValue : class
        {
            if (string.IsNullOrEmpty(setCacheKey))
            {
                return(new List <TValue>());
            }
            if (!_redisDatabase.KeyExists(setCacheKey))
            {
                return(new List <TValue>());
            }
            var setMembers = await _redisDatabase.SetMembersAsync(setCacheKey).ConfigureAwait(false);

            if (setMembers.Length < 1)
            {
                return(new List <TValue>());
            }
            var resultList = new List <TValue>();

            foreach (var member in setMembers)
            {
                var cachedItem = await GetValueAsync <TValue>(member.ToString()).ConfigureAwait(false);

                if (cachedItem == default(TValue))
                {
                    await _redisDatabase.SetRemoveAsync(setCacheKey, member).ConfigureAwait(false);

                    continue;
                }
                resultList.Add(cachedItem);
            }
            return(resultList);
        }