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


C# WriteBatch.MultiAdd方法代码示例

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


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

示例1: CanAddMultiValuesUnderTheSameKeyToBatch

        public void CanAddMultiValuesUnderTheSameKeyToBatch()
        {
            using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
            {
                var rand = new Random();
                var testBuffer = new byte[168];
                rand.NextBytes(testBuffer);

                CreateTrees(env, 1, "multitree");

                var batch = new WriteBatch();

                batch.MultiAdd("key", "value1", "multitree0");
                batch.MultiAdd("key", "value2", "multitree0");

                env.Writer.Write(batch);

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    var tree = tx.Environment.CreateTree(tx,"multitree0");
                    using (var it = tree.MultiRead("key"))
                    {
                        Assert.True(it.Seek(Slice.BeforeAllKeys));

                        Assert.Equal("value1", it.CurrentKey.ToString());
                        Assert.True(it.MoveNext());

                        Assert.Equal("value2", it.CurrentKey.ToString());
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:32,代码来源:MultiAdds.cs

示例2: MultiAdd

		public virtual void MultiAdd(WriteBatch writeBatch, Slice key, Slice value, ushort? expectedVersion = null)
		{
			writeBatch.MultiAdd(key, value, TableName, expectedVersion);
		}
开发者ID:randacc,项目名称:ravendb,代码行数:4,代码来源:TableBase.cs

示例3: AddMultiRecords

		private void AddMultiRecords(StorageEnvironment env, IList<string> trees, int documentCount, bool sequential)
		{
			var key = Guid.NewGuid().ToString();
			var batch = new WriteBatch();

			for (int i = 0; i < documentCount; i++)
			{
				foreach (var tree in trees)
				{
					var value = sequential ? string.Format("tree_{0}_record_{1}_key_{2}", tree, i, key) : Guid.NewGuid().ToString();

					batch.MultiAdd((i % 10).ToString(), value, tree);
				}
			}

			env.Writer.Write(batch);
		}
开发者ID:paulcbetts,项目名称:ravendb,代码行数:17,代码来源:MultiAdds.cs

示例4: SplitterIssue2

		public void SplitterIssue2()
		{
			var storageEnvironmentOptions = StorageEnvironmentOptions.CreateMemoryOnly();
			storageEnvironmentOptions.ManualFlushing = true;
			using (var env = new StorageEnvironment(storageEnvironmentOptions))
			{
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "multi");
					tx.Commit();
				}

				var batch = new WriteBatch();

				batch.MultiAdd("0", "1", "multi");
				batch.MultiAdd("1", "1", "multi");
				batch.MultiAdd("2", "1", "multi");
				batch.MultiAdd("3", "1", "multi");
				batch.MultiAdd("4", "1", "multi");
				batch.MultiAdd("5", "1", "multi");

				env.Writer.Write(batch);

				using (var tx = env.NewTransaction(TransactionFlags.Read))
				{
					var tree = tx.Environment.State.GetTree(tx,"multi");
					using (var iterator = tree.MultiRead(tx, "0"))
					{
						Assert.True(iterator.Seek(Slice.BeforeAllKeys));

						var count = 0;
						do
						{
							count++;
						} while (iterator.MoveNext());

						Assert.Equal(1, count);
					}
				}

				batch = new WriteBatch();

				batch.MultiAdd("0", "2", "multi");
				batch.MultiAdd("1", "2", "multi");
				batch.MultiAdd("2", "2", "multi");
				batch.MultiAdd("3", "2", "multi");
				batch.MultiAdd("4", "2", "multi");
				batch.MultiAdd("5", "2", "multi");

				env.Writer.Write(batch);

				using (var tx = env.NewTransaction(TransactionFlags.Read))
				{
					var tree = tx.Environment.State.GetTree(tx,"multi");
					using (var iterator = tree.MultiRead(tx, "0"))
					{
						Assert.True(iterator.Seek(Slice.BeforeAllKeys));

						var count = 0;
						do
						{
							count++;
						} while (iterator.MoveNext());

						Assert.Equal(2, count);
					}
				}
			}
		}
开发者ID:paulcbetts,项目名称:ravendb,代码行数:69,代码来源:MultiAdds.cs

示例5: Record_debug_journal_and_replay_it

		public void Record_debug_journal_and_replay_it()
		{
			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				env.DebugJournal = new DebugJournal(debugJouralName, env, true);
				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("{ \"title\": \"foo\",\"name\":\"bar\"}"));
					writeBatch.Add("foo", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree");

					writeBatch.MultiAdd("multi-foo", "AA", "test-tree");
					env.Writer.Write(writeBatch);
				}

                using (var writeBatch = new WriteBatch())
                {
                    writeBatch.Increment("incr-key", 5, "test-tree");
                    env.Writer.Write(writeBatch);
                }

                using (var tx = env.NewTransaction(TransactionFlags.Read))
                {
                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());

                    using (var writeBatch = new WriteBatch())
                    {
                        writeBatch.Increment("incr-key", 5, "test-tree");
                        env.Writer.Write(writeBatch);
                    }

                    Assert.Equal(5, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
                }

			    using (var tx = env.NewTransaction(TransactionFlags.Read))
			    {
                    Assert.Equal(10, tx.ReadTree("test-tree").Read("incr-key").Reader.ReadLittleEndianInt64());
			    }

			    using (var writeBatch = new WriteBatch())
				{
					writeBatch.MultiAdd("multi-foo", "BB", "test-tree");
					writeBatch.MultiAdd("multi-foo", "CC", "test-tree");

					writeBatch.Delete("foo-bar", "test-tree");
					env.Writer.Write(writeBatch);
				}

				using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
				{
					env.CreateTree(tx, "test-tree2");
					tx.Commit();
				}

				using (var writeBatch = new WriteBatch())
				{
					var valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1!"));
					writeBatch.Add("foo", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2!"));
					writeBatch.Add("bar", valueBuffer, "test-tree2");

					valueBuffer = new MemoryStream(Encoding.UTF8.GetBytes("testing testing 1 2 3!"));
					writeBatch.Add("foo-bar", valueBuffer, "test-tree2");
					env.Writer.Write(writeBatch);
				}
			}

			using (var env = new StorageEnvironment(StorageEnvironmentOptions.CreateMemoryOnly()))
			{
				env.DebugJournal = DebugJournal.FromFile(debugJouralName, env);
				env.DebugJournal.Replay();

				using (var snapshot = env.CreateSnapshot())
				{
					Assert.Equal("{ \"title\": \"foo\",\"name\":\"bar\"}", snapshot.Read("test-tree", "foo").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2!", snapshot.Read("test-tree", "bar").Reader.ToStringValue());

				    Assert.Equal("testing testing 1!", snapshot.Read("test-tree2", "foo").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2!", snapshot.Read("test-tree2", "bar").Reader.ToStringValue());
				    Assert.Equal("testing testing 1 2 3!", snapshot.Read("test-tree2", "foo-bar").Reader.ToStringValue());

                    Assert.Equal(10, snapshot.Read("test-tree", "incr-key").Reader.ReadLittleEndianInt64());

					Assert.Equal(0,snapshot.ReadVersion("test-tree","foo-bar"));

					using (var iter = snapshot.MultiRead("test-tree","multi-foo"))
					{
						iter.Seek(Slice.BeforeAllKeys);
//.........这里部分代码省略.........
开发者ID:cocytus,项目名称:ravendb,代码行数:101,代码来源:DebugJournalTest.cs

示例6: Replay

        public void Replay()
        {
            var wasDebugRecording = _env.IsDebugRecording;
            _env.IsDebugRecording = false;

            using (var writeBatch = new WriteBatch())
            {
                ActivityEntry entry;
                while (WriteQueue.TryDequeue(out entry))
                {
                    switch (entry.ActionType)
                    {
                        case DebugActionType.Add:
                            writeBatch.Add(entry.Key, entry.ValueStream, entry.TreeName);
                            break;
                        case DebugActionType.Delete:
                            writeBatch.Delete(entry.Key, entry.TreeName);
                            break;
                        case DebugActionType.MultiAdd:
                            writeBatch.MultiAdd(entry.Key, new Slice(Encoding.UTF8.GetBytes(entry.Value.ToString())), entry.TreeName);
                            break;
                        case DebugActionType.MultiDelete:
                            writeBatch.MultiDelete(entry.Key, new Slice(Encoding.UTF8.GetBytes(entry.Value.ToString())), entry.TreeName);
                            break;
                        case DebugActionType.CreateTree:
                            using (var tx = _env.NewTransaction(TransactionFlags.ReadWrite))
                            {
                                _env.CreateTree(tx, entry.TreeName);
                                tx.Commit();
                            }
                            break;
                        default: //precaution against newly added action types
                            throw new InvalidOperationException("unsupported tree action type");
                    }
                }

                _env.Writer.Write(writeBatch);
            }

            _env.IsDebugRecording = wasDebugRecording; //restore the state as it was
        }
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:41,代码来源:DebugJournal.cs


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