public void Test6() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mdbx"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (MdbxEnvironment env = new MdbxEnvironment()) { env.Open(path, EnvironmentFlag.NoTLS, Convert.ToInt32("666", 8)); using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly)) { ulong snapshotID = tran.GetID(); } using (MdbxTransaction tran = env.BeginTransaction()) { ulong txnID = tran.GetID(); } env.Close(); } }
public void Test4() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mdbx"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (MdbxEnvironment env = new MdbxEnvironment()) { env.Open(path, EnvironmentFlag.NoTLS, Convert.ToInt32("666", 8)); string key = Guid.NewGuid().ToString("N"); // some key byte[] value = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); // some value in bytes // mdbx_get using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly)) { MdbxDatabase db = tran.OpenDatabase(); byte[] getBytes = db.Get(key); Assert.Null(getBytes); } // mdbx_put using (MdbxTransaction tran = env.BeginTransaction()) { MdbxDatabase db = tran.OpenDatabase(); db.Put(key, value); tran.Commit(); } // mdbx_get using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly)) { MdbxDatabase db = tran.OpenDatabase(); byte[] getBytes = db.Get(key); Assert.NotNull(getBytes); Assert.Equal(value.Length, getBytes.Length); Assert.Equal(value, getBytes); } env.Close(); } }
public void Test2() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mdbx"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (MdbxEnvironment env = new MdbxEnvironment()) { env.Open(path, EnvironmentFlag.NoTLS, Convert.ToInt32("666", 8)); var putBytes = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); // mdbx_put using (MdbxTransaction tran = env.BeginTransaction()) { MdbxDatabase db = tran.OpenDatabase(); db.Put(putBytes, putBytes); tran.Commit(); } // mdbx_get using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly)) { MdbxDatabase db = tran.OpenDatabase(); byte[] getBytes = db.Get(putBytes); Assert.NotNull(getBytes); Assert.Equal(putBytes.Length, getBytes.Length); Assert.Equal(putBytes, getBytes); } // mdbx_del using (MdbxTransaction tran = env.BeginTransaction()) { MdbxDatabase db = tran.OpenDatabase(); bool deleted = db.Del(putBytes); Assert.True(deleted); deleted = db.Del(putBytes); Assert.False(deleted); tran.Commit(); } env.Close(); } }
public void Test3() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mdbx"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // register serializer for our custom type SerializerRegistry.Register(new BasicTest3PayloadSerializer()); using (MdbxEnvironment env = new MdbxEnvironment()) { env.Open(path, EnvironmentFlag.NoTLS, Convert.ToInt32("666", 8)); // mdbx_put using (MdbxTransaction tran = env.BeginTransaction()) { MdbxDatabase db = tran.OpenDatabase(); db.Put("ana_key", new BasicTest3Payload() { Person = "Ana", Age = 50 }); tran.Commit(); } // mdbx_get using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly)) { MdbxDatabase db = tran.OpenDatabase(); BasicTest3Payload payload = db.Get <string, BasicTest3Payload>("ana_key"); Assert.NotNull(payload); Assert.Equal("Ana", payload.Person); Assert.Equal(50, payload.Age); } env.Close(); } }
public void Test2() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mdbx"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (MdbxEnvironment env = new MdbxEnvironment()) { env.Open(path, EnvironmentFlag.NoTLS, Convert.ToInt32("666", 8)); var stat = env.Info(); env.Close(); } }