Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void Error()
        {
            var options = new Options()
            {
                CreateIfMissing = false
            };
            var db = new DB(options, "non-existent");

            Assert.Fail();
            db.Get("key1");
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public object Get(string key, Type type)
        {
            FormaterBuffer buffer = Formater.Pop();
            long           count;
            object         result = null;

            try
            {
                count = mDataBase.Get(Encoding.UTF8.GetBytes(key), buffer.Array);
                if (count > 0)
                {
                    result = Formater.Deserialize(type, buffer, 0, (int)count);
                }
                return(result);
            }
            finally
            {
                Formater.Push(buffer);
            }
        }
Exemplo n.º 5
0
 public static T Get <T>(this DB db, ReadOptions options, byte prefix, ISerializable key, Func <Slice, T> resultSelector)
 {
     return(resultSelector(db.Get(options, SliceBuilder.Begin(prefix).Add(key))));
 }
Exemplo n.º 6
0
 public static T Get <T>(this DB db, ReadOptions options, byte prefix, ISerializable key) where T : class, ISerializable, new()
 {
     return(db.Get(options, SliceBuilder.Begin(prefix).Add(key)).ToArray().AsSerializable <T>());
 }
Exemplo n.º 7
0
 protected override TValue GetInternal(TKey key)
 {
     return(db.Get <TValue>(ReadOptions.Default, prefix, key));
 }
Exemplo n.º 8
0
 public string Get(string key)
 {
     return(_db.Get(key));
 }