You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-rocksdb/src/main.rs

59 lines
1.2 KiB

extern crate rocksdb;
extern crate test;
use rocksdb::open;
use test::Bencher;
#[allow(dead_code)]
fn main() {
10 years ago
match rocksdb::create_or_open("/tmp/rust-rocksdb".to_string()) {
Ok(db) => {
for i in range(0u, 20) {
spawn(proc() {
db.put(b"my key", b"my value");
db.get(b"my key").map( |value| {
match value.to_utf8() {
Some(v) =>
println!("retrieved utf8 value {}", v),
None =>
println!("did not read valid utf-8 out of the db"),
}});
db.get(b"NOT my key").on_absent(|| { println!("value not found") });
db.close();
});
}
10 years ago
},
Err(e) => panic!(e),
}
}
#[allow(dead_code)]
#[bench]
fn writes(b: &mut Bencher) {
10 years ago
let db = open("testdb".to_string(), true).unwrap();
let mut i = 0 as u64;
b.iter(|| {
db.put(i.to_string().as_bytes(), b"v1111");
i += 1;
});
db.close();
}
#[allow(dead_code)]
#[bench]
fn reads(b: &mut Bencher) {
10 years ago
let db = open("testdb".to_string(), true).unwrap();
let mut i = 0 as u64;
b.iter(|| {
db.get(i.to_string().as_bytes()).on_error(
|e| {
println!("error: {}", e);
e
});
i += 1;
});
db.close();
}