basic_operations/basic_operations.rs
1use std::path::Path;
2use std::time::Duration;
3
4use epoch_db::DB;
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 // 1. Open the database. It will be created if it doesn't exist.
8 let db = DB::new(Path::new("./my_database"))?;
9
10 // 2. Set a value with a 10-second TTL.
11 db.set("user:1", "Alice", Some(Duration::from_secs(10)))?;
12
13 // 3. Get the value back.
14 if let Some(value) = db.get("user:1")? {
15 println!("Found value: {}", value); // "Found value: Alice"
16 }
17
18 // 4. Remove the data.
19 db.remove("user:1")?;
20
21 Ok(())
22}