Esempio n. 1
0
        /// <summary>
        /// Gets all the items in a given partition.
        /// </summary>
        /// <typeparam name="TValue">Type of the return value</typeparam>
        /// <param name="partitionName">
        /// Optional value for the name of a partition in the application cache. Partitions can be a good way to categorize or group
        /// certain types of items in the cache together.
        /// </param>
        /// <returns>List of all items in a partition</returns>
        public async Task <List <TValue> > GetAllItemsInPartitionAsync <TValue>(string partitionName) where TValue : class
        {
            if (string.IsNullOrEmpty(partitionName))
            {
                return(new List <TValue>());
            }
            var partitionKey  = ComposePartitionKey(partitionName);
            var partitionHash = await _redisDatabase.HashGetAllAsync(partitionKey).ConfigureAwait(false);

            return(partitionHash
                   .Select(hashEntry => JsonConvert.DeserializeObject <TValue>(hashEntry.Value))
                   .Where(obj => obj != default(TValue)).ToList());
        }