public IEnumerable <Document> GetEntities(SearchConditions searchConditions, IEnumerable <string> projectedFields, string orderByFieldName, bool orderByDesc) { string indexKey = this.GetIndexKey(searchConditions); string indexListKey = this.GetIndexListKeyInCache(); try { Document[] result = null; // if a full index was found if (this._redis.HashFieldExistsWithRetries(indexListKey, indexKey)) { result = RedisIndex.LoadIndexEntities(this._redis, indexKey, indexListKey); } else if (projectedFields != null) { // then trying to use a projection index indexKey = this.GetIndexKey(searchConditions, projectedFields); if (this._redis.HashFieldExistsWithRetries(indexListKey, indexKey)) { result = RedisProjectionIndex.LoadProjectionIndexEntities(this._redis, indexKey, indexListKey); } } // if we failed to load both full and projection index if (result == null) { this.OnMiss.FireSafely(); return(null); } this.OnHit.FireSafely(); this.Log("Index ({0}) with {1} items successfully loaded from cache", indexKey, result.Length); if (string.IsNullOrEmpty(orderByFieldName)) { return(result); } // creating a comparer to sort the results var comparer = PrimitiveComparer.GetComparer(this._tableEntityType, orderByFieldName); return(orderByDesc ? result.OrderByDescending(doc => doc[orderByFieldName].AsPrimitive(), comparer) : result.OrderBy(doc => doc[orderByFieldName].AsPrimitive(), comparer) ); } catch (Exception ex) { this.Log("Failed to load index ({0}) from cache. {1}", indexKey, ex); this.OnMiss.FireSafely(); return(null); } }
private Task <bool> AddToIndex(RedisIndex index, string value, double indexScore) { return(this._redisDb.SortedSetAddAsync(index.ToString(), value, indexScore)); }
public Task <bool> AddToIndex(RedisIndex index, UInt256 hash, double indexScore) { return(this.AddToIndex(index, hash.ToString(), indexScore)); }
public async Task <UInt256> GetFromHashIndex(RedisIndex index, double indexScore) { var values = (await _redisDb.SortedSetRangeByScoreAsync(index.ToString(), indexScore, indexScore)).ToStringArray(); return(values.Any() ? UInt256.Parse(values.First()) : null); }
public IndexAttribute(RedisIndex index) { Index = index; }
/// <summary> /// Retrieves the length / number of elements in an index /// </summary> /// <param name="index">Index to retrieve the length of</param> /// <returns></returns> public long GetIndexLength(RedisIndex index) { return(_redisDb.SortedSetLength(index.ToString())); }
/// <summary> /// Retrieves a specified range of values from a Redis Sorted Set based on a range of scores /// </summary> /// <param name="index">Index to search</param> /// <param name="startIndexScore">Range starting score</param> /// <param name="endIndexScore">Range end score</param> /// <returns></returns> public RedisValue[] GetRangeFromIndex(RedisIndex index, double startIndexScore, double endIndexScore) { return(_redisDb.SortedSetRangeByScore(index.ToString(), startIndexScore, endIndexScore)); }
/// <summary> /// Retrieves a specified value from a Redis Sorted Set based on score. /// </summary> /// <param name="index">Index to search</param> /// <param name="indexScore">Score to retrieve.</param> /// <returns></returns> public RedisValue[] GetFromIndex(RedisIndex index, double indexScore) { return(_redisDb.SortedSetRangeByScore(index.ToString(), indexScore, indexScore)); }
/// <summary> /// Adds a specified value and score to a Redis Sorted Set. Using a Redis Sorted Set will give us a O(log(n)) complexity on search. /// </summary> /// <param name="index">Index to write</param> /// <param name="indexScore">Score to assign</param> /// <param name="value">Value associated with score</param> public void AddToIndex(RedisIndex index, double indexScore, string value) { _redisDb.SortedSetAdd(index.ToString(), value, indexScore); }