/// <summary> /// Loads all entities from an index or throws, if something wasn't found /// </summary> public static Document[] LoadProjectionIndexEntities(RedisWrapper redis, string indexKey, string indexListKey) { var rawIndex = redis.GetHashFieldsWithRetries(indexKey); if (rawIndex.Length <= 0) { redis.RemoveHashFieldsWithRetries(indexListKey, indexKey); throw new RedisCacheException("Index wasn't found in cache"); } var indexVersionField = new IndexVersionField(); var wrappers = ( from hashField in rawIndex where !indexVersionField.TryInitialize(hashField) select hashField.Value.ToObject <CacheDocumentWrapper>() ) .ToList(); // if the index is being rebuilt if (indexVersionField.IsIndexBeingRebuilt) { throw new RedisCacheException("Index is being rebuilt"); } return(wrappers.Select(w => w.Document).ToArray()); }
/// <summary> /// Loads all entities from an index or throws, if something wasn't found /// </summary> public static Document[] LoadIndexEntities(RedisWrapper redis, string indexKey, string indexListKey) { var rawIndex = redis.GetHashFieldsWithRetries(indexKey); if (rawIndex.Length <= 0) { redis.RemoveHashFieldsWithRetries(indexListKey, indexKey); throw new RedisCacheException("Index wasn't found in cache"); } var indexVersionField = new IndexVersionField(); var entityKeys = ( from hashField in rawIndex where !indexVersionField.TryInitialize(hashField) select hashField.Name.ToEntityKey() ) .ToList(); // if the index is being rebuilt if (indexVersionField.IsIndexBeingRebuilt) { throw new RedisCacheException("Index is being rebuilt"); } try { var wrappers = redis.GetWithRetries <CacheDocumentWrapper>(entityKeys.Select(k => k.ToRedisKey()).ToArray()); return(wrappers.Select(w => w.Document).ToArray()); } catch (Exception) { // if failed to load all entities - dropping the index redis.RemoveHashFieldsWithRetries(indexListKey, indexKey); redis.RemoveWithRetries(indexKey); throw; } }