/// <summary> /// Retrieves all keys that match the given filter value, or an empty array if there are no matches. /// </summary> public async Task <IEnumerable <TKey> > FilterAsync(ITransaction tx, TFilter filter, TimeSpan timeout, CancellationToken token) { var result = await _index.TryGetValueAsync(tx, filter, timeout, token).ConfigureAwait(false); TKey[] results = result.HasValue ? result.Value : new TKey[0]; Array.Sort(results); return(results); }
private static async Task <List <Guid> > GetOldGetMsgIds(GetOldMessagesInput input, IReliableDictionary2 <Guid, List <Guid> > indexDict, ITransaction tx) { if (await indexDict.ContainsKeyAsync(tx, input.Id)) { var lstMessageIndex = (await indexDict.TryGetValueAsync(tx, input.Id)).Value; var oldestMsgIndex = lstMessageIndex.IndexOf(input.OldestMsgId); if (oldestMsgIndex == 0) { return(null); } var endIndex = oldestMsgIndex - 1; var startIndex = oldestMsgIndex - MaxMessageAmount; var amount = MaxMessageAmount; if (startIndex < 0) { startIndex = 0; amount = endIndex - startIndex + 1; } return(lstMessageIndex.GetRange(startIndex, amount)); } return(null); }
/// <summary> /// Retrieves all keys that satisfy the given full-text search, or an empty array if there are no matches. /// </summary> public async Task <IEnumerable <TKey> > SearchAsync(ITransaction tx, string search, int count, TimeSpan timeout, CancellationToken token) { var keys = new HashSet <TKey>(); var words = GetDistinctWords(search); foreach (var word in words) { var result = await _index.TryGetValueAsync(tx, word, timeout, token).ConfigureAwait(false); if (result.HasValue) { keys.AddRange(result.Value); } if (keys.Count >= count) { break; } } return(keys.Take(count)); }
public async Task <ConditionalValue <TValue> > TryGetAsync(ITransaction tx, string key, int index) { if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index)); } var metadataValue = await TryGetMetadataAsync(tx, key).ConfigureAwait(false); if (metadataValue.HasValue) { var listKey = new ReliableListKey { Key = key, Id = index }; return(await _valueStore.TryGetValueAsync(tx, listKey).ConfigureAwait(false)); } else { return(new ConditionalValue <TValue>()); } }
public Task <ConditionalValue <TValue> > TryGetValueAsync(ITransaction tx, TKey key) { return(_dictionary.TryGetValueAsync(tx, key)); }
private Task <ConditionalValue <ReliableListMetaData> > TryGetMetadataAsync(ITransaction tx, string key) => _metadataStore.TryGetValueAsync(tx, MakeMetadataKey(key));