transactions/
transactions.rs1use gemstone_rs::{Config, Error, Oop, Session};
9
10fn main() -> gemstone_rs::Result<()> {
11 let mut session = Session::login(Config::from_env()?)?;
12
13 let committed_key = "GemStoneRsTransactionCommitted";
14 session.transaction(|session| {
15 let value = session.new_string("committed by gemstone-rs")?;
16 session.global_put(committed_key, value)
17 })?;
18
19 let committed = session.global_get(committed_key)?;
20 println!("committed value: {}", session.fetch_string(committed)?);
21
22 let aborted_key = "GemStoneRsTransactionAborted";
23 let aborted: gemstone_rs::Result<()> = session.transaction(|session| {
24 let value = session.new_string("this write should abort")?;
25 session.global_put(aborted_key, value)?;
26 Err(Error::IllegalOop {
27 operation: "intentional example abort",
28 })
29 });
30
31 println!("abort path returned error: {}", aborted.is_err());
32 session.global_put(committed_key, Oop::NIL)?;
33 Ok(())
34}