当前位置: 首页>>代码示例>>C#>>正文


C# WriteBatch.Put方法代码示例

本文整理汇总了C#中WriteBatch.Put方法的典型用法代码示例。如果您正苦于以下问题:C# WriteBatch.Put方法的具体用法?C# WriteBatch.Put怎么用?C# WriteBatch.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WriteBatch的用法示例。


在下文中一共展示了WriteBatch.Put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldRecoverDataFromLogFile

		public async Task ShouldRecoverDataFromLogFile()
		{
			var storage = await NewStorageAsync();

			var name = storage.Name;

			var writeBatch = new WriteBatch();
			writeBatch.Put("A", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			writeBatch.Put("B", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			writeBatch.Put("D", new MemoryStream(Encoding.UTF8.GetBytes("123")));
			storage.Writer.WriteAsync(writeBatch).Wait();

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();

			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				
				using(var it = newStorage.Reader.NewIterator(new ReadOptions()))
				{
					it.Seek("C");
					Assert.True(it.IsValid);
					it.Prev();
					Assert.True(it.IsValid);
					Assert.Equal("B", it.Key);
				}
			}
		} 
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:33,代码来源:CanIterateBackward.cs

示例2: CanGetLatestVersion

		public async Task CanGetLatestVersion()
		{
			var storage = await NewStorageAsync();
			var name = storage.Name;

			for (int j = 0; j < 3; j++)
			{
				for (int i = 0; i < 65; i++)
				{
					for (int k = 0; k < 4; k++)
					{
						var writeBatch = new WriteBatch();
						writeBatch.Put("A" + k, new MemoryStream(new[] { (byte)i, (byte)k }));
						await storage.Writer.WriteAsync(writeBatch);
					}
				}
			}

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();

			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				var stream = newStorage.Reader.Read("A2");
				Assert.Equal(64, stream.ReadByte());
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:32,代码来源:RecoveryTests.cs

示例3: CanOpenAndCloseWithUpdate

		public async Task CanOpenAndCloseWithUpdate()
		{
			var storage = await NewStorageAsync();
			var name = storage.Name;

			var str1 = "test1";
			var str2 = "test2";

			var s1 = new MemoryStream(Encoding.UTF8.GetBytes(str1));
			var s2 = new MemoryStream(Encoding.UTF8.GetBytes(str2));

			var writeBatch = new WriteBatch();
			writeBatch.Put("A", s1);
			await storage.Writer.WriteAsync(writeBatch);

			writeBatch = new WriteBatch();
			writeBatch.Put("A", s2);
			await storage.Writer.WriteAsync(writeBatch);

			var fileSystem = storage.StorageState.FileSystem;

			storage.Dispose();


			using (var newStorage = new Storage(new StorageState(name, new StorageOptions())
			{
				FileSystem = fileSystem
			}))
			{
				await newStorage.InitAsync();
				AssertEqual(str2, newStorage.Reader.Read("A"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:33,代码来源:RecoveryTests.cs

示例4: SnapshotTest

		public async Task SnapshotTest()
		{
			using (var storage = await NewStorageAsync())
			{
				var str1 = "test1";
				var str2 = "test2";

				var s1 = new MemoryStream(Encoding.UTF8.GetBytes(str1));
				var s2 = new MemoryStream(Encoding.UTF8.GetBytes(str2));

				var writeBatch = new WriteBatch();
				writeBatch.Put("key1", s1);

				await storage.Writer.WriteAsync(writeBatch);

				var snapshot = storage.Commands.CreateSnapshot();

				writeBatch = new WriteBatch();
				writeBatch.Put("key1", s2);

				await storage.Writer.WriteAsync(writeBatch);

				AssertEqual(str2, storage.Reader.Read("key1"));
				AssertEqual(str1, storage.Reader.Read("key1", new ReadOptions
					                                                  {
						                                                  Snapshot = snapshot
					                                                  }));

				storage.Commands.ReleaseSnapshot(snapshot);
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:31,代码来源:SnapshotTests.cs

示例5: TestIteratorWithSnapshot

        public void TestIteratorWithSnapshot()
        {
            using (var db = new DB(new Options { CreateIfMissing = true }, "test2.db"))
            {
                using (var batch = new WriteBatch())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        batch.Put(Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
                    }

                    db.Write(new WriteOptions { Sync = true }, batch);
                }

                using (var snapshot = db.GetSnapshot())
                using (var batch = new WriteBatch())
                using (var itr = db.NewIterator(new ReadOptions { Snapshot = snapshot }))
                {
                    itr.Seek(Slice.FromString("key::"));
                    Assert.IsTrue(itr.Valid());
                    int entriesDeleted = 0;
                    while (itr.Valid())
                    {
                        batch.Delete(itr.Key());
                        itr.Next();
                        entriesDeleted++;
                    }

                    db.Write(new WriteOptions(), batch);
                    Assert.AreEqual(100, entriesDeleted);
                }
            }
        }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:33,代码来源:BasicTests.cs

示例6: ReadFromMemTable

		public async Task ReadFromMemTable()
		{
			using (var storage = await NewStorageAsync())
			{
				var batch = new WriteBatch();
				batch.Put("test1", new MemoryStream(Encoding.UTF8.GetBytes("test")));
				await storage.Writer.WriteAsync(batch);

				Assert.NotNull(storage.Reader.Read("test1"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:11,代码来源:StorageReaderTests.cs

示例7: WillNotFindMissingValue

		public async Task WillNotFindMissingValue()
		{
			using (var storage = await NewStorageAsync(new StorageOptions()))
			{
				var writeBatch = new WriteBatch();
				writeBatch.Put("system/config", new MemoryStream());
				await storage.Writer.WriteAsync(writeBatch);

				Assert.Null(storage.Reader.Read("system/Test"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:11,代码来源:WillNotFindMissingValues.cs

示例8: BatchWriteRangeInTask

        private static Task BatchWriteRangeInTask(string dbName, int offset, int limit)
        {
            return Task.Run(() =>
            {
                using (var db = new DB(new Options { CreateIfMissing = true }, dbName))
                using (var batch = new WriteBatch())
                {
                    for (int i = offset; i < limit; i++)
                    {
                        batch.Put(Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
                    }

                    db.Write(new WriteOptions { Sync = true }, batch);
                }
            });
        }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:16,代码来源:MultiThreadedTests.cs

示例9: ReadFromImmutableMemTable

		public async Task ReadFromImmutableMemTable()
		{
			using (var storage = await NewStorageAsync(new StorageOptions
				                                     {
					                                     WriteBatchSize = 1
				                                     }))
			{
				var batch1 = new WriteBatch();
				batch1.Put("test1", new MemoryStream(Encoding.UTF8.GetBytes("test")));
				await storage.Writer.WriteAsync(batch1);

				var batch2 = new WriteBatch();
				batch2.Put("test2", new MemoryStream(Encoding.UTF8.GetBytes("test")));
				await storage.Writer.WriteAsync(batch2);

				Assert.NotNull(storage.Reader.Read("test1"));
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:18,代码来源:StorageReaderTests.cs

示例10: DoWrite

		private Task<BenchmarkResult> DoWrite(BenchmarkParameters parameters, bool seq)
		{
			var random = new Random();
			var generator = new RandomGenerator();

			var result = new BenchmarkResult(parameters);

			var tasks = new List<Task>(parameters.Num);

			long bytes = 0;
			for (var i = 0; i < parameters.Num; i += parameters.EntriesPerBatch)
			{
				var batch = new WriteBatch();
				for (var j = 0; j < parameters.EntriesPerBatch; j++)
				{
					var k = seq ? i + j : random.Next() % options.Num;
					var key = string.Format("{0:0000000000000000}", k);
					batch.Put(key, generator.Generate(parameters.ValueSize));
					bytes += parameters.ValueSize + key.Length;
					result.FinishOperation();
				}

				tasks.Add(storage.Writer.WriteAsync(batch, new WriteOptions
															   {
																   FlushToDisk = parameters.Sync
															   }));
			}

			result.AddBytes(bytes);

			return Task.WhenAll(tasks).ContinueWith(t => result);
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:32,代码来源:Benchmark.cs

示例11: ReadWhileWriting

		private Task<BenchmarkResult> ReadWhileWriting(BenchmarkParameters parameters)
		{
			var random = new Random();
			var generator = new RandomGenerator();

			var readTask = ReadRandom(parameters);
			Task.Factory.StartNew(async () =>
				{
					while (readTask.IsCompleted == false)
					{
						var batch = new WriteBatch();

						var k = random.Next() % options.Num;
						var key = string.Format("{0:0000000000000000}", k);

						batch.Put(key, generator.Generate(parameters.ValueSize));
						await storage.Writer.WriteAsync(batch);
					}
				});

			return readTask;
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:22,代码来源:Benchmark.cs

示例12: Put

		public static void Put(this Storage db, string key, string val)
		{
			var writeBatch = new WriteBatch();
			writeBatch.Put(key, new MemoryStream(Encoding.UTF8.GetBytes(val)));
			db.Writer.WriteAsync(writeBatch).Wait();
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:6,代码来源:DbExt.cs

示例13: ProcessWrites

		private async Task ProcessWrites(int size, int timeToWait)
		{
			var generator = new RandomGenerator();
			var random = new Random();

			while (true)
			{
				try
				{
					var batchSize = random.Next(1, 10);
					var batch = new WriteBatch();

					for (var i = 0; i < batchSize; i++)
					{
						var k = random.Next();
						var key = string.Format("{0:0000000000000000}", k);

						batch.Put(key, generator.Generate(size));

					}

					await storage.Writer.WriteAsync(batch);
					statistics.NumberOfWrites += batchSize;
					statistics.NumberOfWritesSinceLastReport += batchSize;
					statistics.BytesWritten += batchSize * (size + 16);

					await Task.Delay(timeToWait);
				}
				catch (Exception)
				{
					statistics.NumberOfWriteExceptions++;
				}
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:34,代码来源:StressBenchmark.cs

示例14: MakeTables

		private async Task MakeTables(Storage storage, int n, string small, string large)
		{
			for (int i = 0; i < n; i++)
			{
				var writeBatch = new WriteBatch();
				writeBatch.Put(small, new MemoryStream(Encoding.UTF8.GetBytes("begin")));
				await storage.Writer.WriteAsync(writeBatch);

				writeBatch = new WriteBatch();
				writeBatch.Put(large, new MemoryStream(Encoding.UTF8.GetBytes("end")));
				await storage.Writer.WriteAsync(writeBatch);

				await storage.Commands.CompactMemTableAsync();
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:15,代码来源:CompactionTests.cs

示例15: DoWrite

		private async Task DoWrite(Storage storage, int num, bool seq)
		{
			var random = new Random();
			var generator = new RandomGenerator();

			for (var i = 0; i < num; i += 1)
			{
				var batch = new WriteBatch();
				for (var j = 0; j < 1; j++)
				{
					var k = seq ? i + j : random.Next() % num;
					var key = string.Format("{0:0000000000000000}", k);
					batch.Put(key, generator.Generate(100));
				}

				await storage.Writer.WriteAsync(batch);
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:18,代码来源:IteratorTests.cs


注:本文中的WriteBatch.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。