Update examples

This commit is contained in:
2024-10-22 23:29:32 +02:00
parent 9823faceac
commit a8def7bf94

View File

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