public async Task RemoveFromStart(ITransaction tx, string key, int countToRemove = 1)
        {
            var metadata = await GetMetadataAsync(tx, key).ConfigureAwait(false);

            var from  = metadata.From;
            var count = metadata.Count;

            if (countToRemove > count)
            {
                throw new InvalidOperationException($"Trying to remove {countToRemove} entries from {_name} with only {count} messages");
            }
            for (var i = 0; i < countToRemove; i++)
            {
                var listKey = new ReliableListKey {
                    Key = key, Id = from
                };
                await _valueStore.TryRemoveAsync(tx, listKey).ConfigureAwait(false);

                from++;
                count--;
            }
            var updatedMetadata = new ReliableListMetaData {
                From = from, Count = count
            };

            await UpdateMetadataAsync(tx, key, updatedMetadata).ConfigureAwait(false);
        }
 public AsyncEnumerable(ITransaction tx, string key, ReliableListMetaData metadata, ReliableLists <TValue> list)
 {
     _tx       = tx;
     _key      = key;
     _metadata = metadata;
     _list     = list;
 }
        public async Task AddAsync(ITransaction tx, string key, TValue value)
        {
            var metadata = await GetMetadataAsync(tx, key).ConfigureAwait(false);

            var index   = metadata.From + metadata.Count;
            var listKey = new ReliableListKey {
                Key = key, Id = index
            };
            await _valueStore.SetAsync(tx, listKey, value).ConfigureAwait(false);

            var updatedMetadata = new ReliableListMetaData {
                From = metadata.From, Count = metadata.Count + 1
            };

            await UpdateMetadataAsync(tx, key, updatedMetadata).ConfigureAwait(false);
        }
        public async Task AddRangeAsync(ITransaction tx, string key, IEnumerable <TValue> values)
        {
            var metadata = await GetMetadataAsync(tx, key).ConfigureAwait(false);

            var from  = metadata.From;
            var count = metadata.Count;

            foreach (var value in values)
            {
                var listKey = new ReliableListKey {
                    Key = key, Id = from + count
                };
                await _valueStore.SetAsync(tx, listKey, value).ConfigureAwait(false);

                count++;
            }
            var updatedMetadata = new ReliableListMetaData {
                From = from, Count = count
            };

            await UpdateMetadataAsync(tx, key, updatedMetadata).ConfigureAwait(false);
        }
 private Task UpdateMetadataAsync(ITransaction tx, string key, ReliableListMetaData updatedMetadata) =>
 _metadataStore.SetAsync(tx, MakeMetadataKey(key), updatedMetadata);