本文整理汇总了C#中WriteBatch.Increment方法的典型用法代码示例。如果您正苦于以下问题:C# WriteBatch.Increment方法的具体用法?C# WriteBatch.Increment怎么用?C# WriteBatch.Increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WriteBatch
的用法示例。
在下文中一共展示了WriteBatch.Increment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleIncrementShouldWorkUsingWriteBatch
public void SimpleIncrementShouldWorkUsingWriteBatch()
{
CreateTrees(Env, 1, "tree");
var writeBatch = new WriteBatch();
writeBatch.Increment("key/1", 10, "tree0");
Env.Writer.Write(writeBatch);
writeBatch = new WriteBatch();
writeBatch.Increment("key/1", 5, "tree0");
Env.Writer.Write(writeBatch);
writeBatch = new WriteBatch();
writeBatch.Increment("key/1", -3, "tree0");
Env.Writer.Write(writeBatch);
using (var tx = Env.NewTransaction(TransactionFlags.Read))
{
var read = tx.ReadTree("tree0").Read("key/1");
Assert.NotNull(read);
Assert.Equal(3, read.Version);
Assert.Equal(12, read.Reader.ReadLittleEndianInt64());
}
}
示例2: Increment
public virtual void Increment(WriteBatch writeBatch, Slice key, long delta, ushort? expectedVersion = null)
{
writeBatch.Increment(key, delta, TableName, expectedVersion);
}
示例3: 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);
//.........这里部分代码省略.........