Compare commits

...

2 Commits

Author SHA1 Message Date
8d2a503a89 Release 0.2.0 2024-10-22 23:29:35 +02:00
a8def7bf94 Update examples 2024-10-22 23:29:35 +02:00
2 changed files with 7 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "objcache_examples"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
rust-version = "1.81"
@@ -12,5 +12,5 @@ path = "src/main.rs"
tokio = { version = "1.*", default-features = false, features = ["rt-multi-thread", "macros"] }
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi"] }
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
serde = { version = "1.0.213", default-features = false, features = ["std", "derive"] }
objcache = { path = "../" }

View File

@@ -11,7 +11,7 @@ use objcache::{CacheError, Client, RedisCacheArgs, RedisClient};
#[derive(Debug, Serialize, Deserialize)]
struct Item {
val: usize,
value: usize,
}
#[derive(Debug)]
@@ -32,7 +32,7 @@ impl From<CacheError> for Error {
}
async fn get_item(v: usize) -> Result<Item, Error> {
Ok(Item { val: v })
Ok(Item { value: v })
}
#[tokio::main]
@@ -59,7 +59,7 @@ async fn main() -> Result<(), Error> {
println!("{item:?}");
let item = client.wrap(
|v| Box::pin(async move { Ok::<_, Error>(Item { val: v }) }),
|v| Box::pin(async move { Ok::<_, Error>(Item { value: v }) }),
&RedisCacheArgs {
lock_name: b"item_lock",
key_name: b"item",
@@ -68,6 +68,8 @@ async fn main() -> Result<(), Error> {
)(100)
.await?;
assert_eq!(item.value, 100);
println!("{item:?}");
Ok(())