本文整理汇总了C#中DB.GetSnapshot方法的典型用法代码示例。如果您正苦于以下问题:C# DB.GetSnapshot方法的具体用法?C# DB.GetSnapshot怎么用?C# DB.GetSnapshot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB.GetSnapshot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: TestReadFromSnapshotOfDatabase
public void TestReadFromSnapshotOfDatabase()
{
using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
{
db.Put(new WriteOptions(), Slice.FromString("Foo"), Slice.FromString("Bar"));
using (var snapshot = db.GetSnapshot())
{
var opts = new ReadOptions{ Snapshot = snapshot };
Assert.IsNotNull(db.Get(opts, Slice.FromString("Foo")));
Assert.IsTrue(db.Delete(new WriteOptions(), Slice.FromString("Foo")));
Assert.IsNotNull(db.Get(opts, Slice.FromString("Foo")));
}
}
}
示例3: ReadRangeInTask
private static Task ReadRangeInTask(string dbName, int offset, int limit)
{
return Task.Run(() =>
{
using (var db = new DB(new Options { CreateIfMissing = true }, dbName))
{
using (var snapshot = db.GetSnapshot())
using (var itr = db.NewIterator(new ReadOptions { Snapshot = snapshot }))
{
itr.Seek(Slice.FromString($"key::{offset,20:D20}"));
while (itr.Valid())
{
itr.Next();
}
}
}
});
}