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


C# DB.Put方法代码示例

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


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

示例1: TestIterator

        public void TestIterator()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("Tampa", "green");
                db.Put("London", "red");
                db.Put("New York", "blue");

                var expected = new[] { "London", "New York", "Tampa" };

                var actual = new List<string>();
                using (var iterator = db.CreateIterator(new ReadOptions()))
                {
                    iterator.SeekToFirst();
                    while (iterator.Valid())
                    {
                        var key = iterator.StringKey();
                        actual.Add(key);
                        iterator.Next();
                    }
                }

                CollectionAssert.AreEqual(expected, actual);

            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:28,代码来源:ReactiveTests.cs

示例2: Main3

        static void Main3()
        {
            var path = CleanTestDB();

            using (var db = new DB(new Options {CreateIfMissing = true}, path))
            {
                db.Put(1, new[] {2, 3}, new WriteOptions());
                db.Put(2, new[] {1, 2, 4});
                db.Put(3, new[] {1, 3});
                db.Put(4, new[] {2, 5, 7});
                db.Put(5, new[] {4, 6, 7, 8});
                db.Put(6, new[] {5});
                db.Put(7, new[] {4, 5, 8});
                db.Put(8, new[] {5, 7});

                var a = db.Get(1);
                var b = db.Get(2);
                var c = db.Get(3);
                var d = db.Get(4);
                var e = db.Get(5);
                var f = db.Get(6);
                var g = db.Get(7);
                var h = db.Get(8);

            }
        }
开发者ID:huyi,项目名称:LevelDB,代码行数:26,代码来源:Program.cs

示例3: LevelDBBlockchain

 public LevelDBBlockchain()
 {
     Slice value;
     db = DB.Open(Settings.Default.DataDirectoryPath);
     if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), out value) && value.ToBoolean())
     {
         value = db.Get(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock));
         this.current_block = new UInt256(value.ToArray().Take(32).ToArray());
         this.current_height = BitConverter.ToUInt32(value.ToArray(), 32);
     }
     else
     {
         WriteBatch batch = new WriteBatch();
         ReadOptions options = new ReadOptions { FillCache = false };
         using (Iterator it = db.NewIterator(options))
         {
             for (it.SeekToFirst(); it.Valid(); it.Next())
             {
                 batch.Delete(it.Key());
             }
         }
         batch.Put(SliceBuilder.Begin(DataEntryPrefix.CFG_Version), 0);
         db.Write(WriteOptions.Default, batch);
         AddBlockToChain(GenesisBlock);
         db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), true);
     }
     thread_persistence = new Thread(PersistBlocks);
     thread_persistence.Name = "LevelDBBlockchain.PersistBlocks";
     thread_persistence.Start();
     AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
 }
开发者ID:4T-Shirt,项目名称:AntShares,代码行数:31,代码来源:LevelDBBlockchain.cs

示例4: TestCreatePutDisposeDatabase

 public void TestCreatePutDisposeDatabase()
 {
     using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
     {
         var saved = db.Put(new WriteOptions { Sync = true }, Slice.FromString("Foo"), Slice.FromString("Bar"));
         Assert.IsTrue(saved);
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:8,代码来源:BasicTests.cs

示例5: TestDeleteEntryFromDatabase

 public void TestDeleteEntryFromDatabase()
 {
     using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
     {
         db.Put(new WriteOptions(), Slice.FromString("Foo"), Slice.FromString("Bar"));
         Assert.IsNotNull(db.Get(new ReadOptions(), Slice.FromString("Foo")));
         Assert.IsTrue(db.Delete(new WriteOptions(), Slice.FromString("Foo")));
         Assert.IsNull(db.Get(new ReadOptions(), Slice.FromString("Foo")));
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:10,代码来源:BasicTests.cs

示例6: Main

        static void Main()
        {
            var l = new Logger(s => Console.WriteLine(s));
            var x = new Options 
                    { 
                        CreateIfMissing = true, 
                        RestartInterval = 13, 
                        MaxOpenFiles = 100,
                        InfoLog = l
                    };

            var db = new DB(x, @"C:\Temp\A");
            db.Put("hello", "world");
            var world = db.Get("hello");
            Console.WriteLine(world);

            for (var j = 0; j < 5; j++)
            {
                var r = new Random(0);
                var data = "";

                for (int i = 0; i < 1024; i++)
                {
                    data += 'a' + r.Next(26);
                }
                for (int i = 0; i < 5*1024; i++)
                {
                    db.Put(string.Format("row{0}", i), data);
                }
                Thread.Sleep(100);
            }
            Console.WriteLine();

            //using(var logger = new Logger(Console.WriteLine))
            //{
            //    Console.WriteLine("hello");
            //}

            db.Dispose();
            GC.KeepAlive(l);
        }
开发者ID:huyi,项目名称:LevelDB,代码行数:41,代码来源:Program.cs

示例7: TestCRUD

        public void TestCRUD()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("Tampa", "green");
                db.Put("London", "red");
                db.Put("New York", "blue");

                Assert.AreEqual(db.Get("Tampa"), "green");
                Assert.AreEqual(db.Get("London"), "red");
                Assert.AreEqual(db.Get("New York"), "blue");

                db.Delete("New York");

                Assert.IsNull(db.Get("New York"));

                db.Delete("New York");
            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:21,代码来源:ReactiveTests.cs

示例8: Main

 public static void Main(string[] args)
 {
     using (var database = new DB("mytestdb", new Options() { CreateIfMissing = true, BloomFilter = new BloomFilterPolicy(10) }))
     {
         database.Put("key1", "value1");
         Assert.AreEqual("value1", database.Get("key1"));
         Assert.IsTrue(database.Get("key1") != null);
         database.Delete("key1");
         Assert.IsFalse(database.Get("key1") != null);
         Assert.IsNull(database.Get("key1"));
     }
 }
开发者ID:ren85,项目名称:leveldb.net,代码行数:12,代码来源:DatabaseTest.cs

示例9: PreloadData

        private static void PreloadData()
        {
            if (Directory.Exists(path))
                Directory.Delete(path, true);

            var options = new Options();
            options.CreateIfMissing = true;
            var leveldb = new DB(options, path);

            var id = Guid.NewGuid().ToString();
            string rowkey = "bob";

            leveldb.Put("/users", "table");
            leveldb.Put("/users/index/column0", "index");
            leveldb.Put("/users/index/column49", "index");

            for (int i = 0; i < rows; i++)
            {
                leveldb.Put(string.Format("/users/{0}", i), "row");
                for (int x = 0; x < columns; x++)
                {
                    leveldb.Put(string.Format("/users/{0}:column{1}", i, x), "bob" + i);
                    leveldb.Put(string.Format("/users/index/column{0}:{1}", x, "bob" + i),
                                string.Format("/users/{0}", i));
                }
            }
            leveldb.Dispose();

            Console.WriteLine(
                "Rows created: " + string.Format("{0:N}", rows) +
                " Columns per row: " + columns +
                " Total keys in DB: " + string.Format("{0:N}", rows * columns));
        }
开发者ID:pedroreys,项目名称:Dazzle,代码行数:33,代码来源:Program.cs

示例10: 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")));
         }
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:14,代码来源:BasicTests.cs

示例11: Cache

        public void Cache()
        {
            Database.Dispose();

            // open the DB with a cache that is not owned by LevelDB, then
            // close DB and then free the cache
            var options = new Options() {
                BlockCache = new Cache(64)
            };
            Database = new DB(options, DatabasePath);
            options = null;
            GC.Collect();
            Database.Put("key1", "value1");
            Database.Dispose();
            GC.Collect();
        }
开发者ID:sdether,项目名称:leveldb-sharp,代码行数:16,代码来源:DBTests.cs

示例12: LevelDBBlockchain

 public LevelDBBlockchain(string path)
 {
     header_index.Add(GenesisBlock.Hash);
     Version version;
     Slice value;
     db = DB.Open(path, new Options { CreateIfMissing = true });
     if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), out value) && Version.TryParse(value.ToString(), out version) && version >= Version.Parse("0.4"))
     {
         ReadOptions options = new ReadOptions { FillCache = false };
         value = db.Get(options, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock));
         this.current_block_hash = new UInt256(value.ToArray().Take(32).ToArray());
         this.current_block_height = BitConverter.ToUInt32(value.ToArray(), 32);
         foreach (Block header in db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_HeaderList), (k, v) =>
         {
             using (MemoryStream ms = new MemoryStream(v.ToArray(), false))
             using (BinaryReader r = new BinaryReader(ms))
             {
                 return new
                 {
                     Index = BitConverter.ToUInt32(k.ToArray(), 1),
                     Headers = r.ReadSerializableArray<Block>()
                 };
             }
         }).OrderBy(p => p.Index).SelectMany(p => p.Headers).ToArray())
         {
             if (header.Hash != GenesisBlock.Hash)
             {
                 header_chain.Add(header.Hash, header, header.PrevBlock);
                 header_index.Add(header.Hash);
             }
             stored_header_count++;
         }
         if (stored_header_count == 0)
         {
             Dictionary<UInt256, Block> table = db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block), (k, v) => Block.FromTrimmedData(v.ToArray(), 0)).ToDictionary(p => p.PrevBlock);
             for (UInt256 hash = GenesisBlock.Hash; hash != current_block_hash;)
             {
                 Block header = table[hash];
                 header_chain.Add(header.Hash, header, header.PrevBlock);
                 header_index.Add(header.Hash);
                 hash = header.Hash;
             }
         }
         else if (current_block_height >= stored_header_count)
         {
             List<Block> list = new List<Block>();
             for (UInt256 hash = current_block_hash; hash != header_index[(int)stored_header_count - 1];)
             {
                 Block header = Block.FromTrimmedData(db.Get(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block).Add(hash)).ToArray(), 0);
                 list.Add(header);
                 header_index.Insert((int)stored_header_count, hash);
                 hash = header.PrevBlock;
             }
             for (int i = list.Count - 1; i >= 0; i--)
             {
                 header_chain.Add(list[i].Hash, list[i], list[i].PrevBlock);
             }
         }
         this.current_header_hash = header_index[header_index.Count - 1];
     }
     else
     {
         WriteBatch batch = new WriteBatch();
         ReadOptions options = new ReadOptions { FillCache = false };
         using (Iterator it = db.NewIterator(options))
         {
             for (it.SeekToFirst(); it.Valid(); it.Next())
             {
                 batch.Delete(it.Key());
             }
         }
         db.Write(WriteOptions.Default, batch);
         Persist(GenesisBlock);
         db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), Assembly.GetExecutingAssembly().GetName().Version.ToString());
     }
     thread_persistence = new Thread(PersistBlocks);
     thread_persistence.Name = "LevelDBBlockchain.PersistBlocks";
     thread_persistence.Start();
     AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
 }
开发者ID:butine,项目名称:research,代码行数:80,代码来源:LevelDBBlockchain.cs

示例13: WriteRangeInTask

 private static Task WriteRangeInTask(string dbName, int offset, int limit)
 {
     return Task.Run(() =>
     {
         var writeOpts = new WriteOptions();
         using (var db = new DB(new Options { CreateIfMissing = true }, dbName))
         {
             for (int i = offset; i < limit; i++)
             {
                 db.Put(writeOpts, Slice.FromString($"key::{i,20:D20}"), Slice.FromString($"{i,32}"));
             }
         }
     });
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:14,代码来源:MultiThreadedTests.cs

示例14: TestEnumerable

        public void TestEnumerable()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("Tampa", "green");
                db.Put("London", "red");
                db.Put("New York", "blue");

                var expected = new[] { "London", "New York", "Tampa" };
                var actual = from kv in db as IEnumerable<KeyValuePair<string, string>>
                             select kv.Key;

                CollectionAssert.AreEqual(expected, actual.ToArray());
            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:17,代码来源:ReactiveTests.cs

示例15: TestGetProperty

        public void TestGetProperty()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                var r = new Random(0);
                var data = "";
                for (var i = 0; i < 1024; i++)
                {
                    data += 'a' + r.Next(26);
                }

                for (int i = 0; i < 5 * 1024; i++)
                {
                    db.Put(string.Format("row{0}", i), data);
                }

                var stats = db.PropertyValue("leveldb.stats");

                Assert.IsNotNull(stats);
                Assert.IsTrue(stats.Contains("Compactions"));
            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:24,代码来源:ReactiveTests.cs


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