-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hello,
If I use Redis this is the syntax:
let value: Option<String> = cache_client.get(&key).await.ok();
if let Some(value) = value {
let item = serde_json::from_str::<Item>(&value).unwrap();
items.lock().unwrap().push(item);
} else {
warning!("MISSING CACHE KEY: {}", key);
}
Using Momento:
let get_response = cache_client
.get("cache_name", key)
.await
.map_err(|e| error!("ERROR - Momento - get_object {:?}", e))
.ok();
if let Some(get_response) = get_response {
let value: Option<String> = match get_response {
Get::Hit { value } => value.try_into().ok(),
Get::Miss => None,
};
if let Some(value) = value {
let item = serde_json::from_str::<MyItem>(&value)?;
items.push(item);
} else {
warning!("MISSING CACHE KEY: {}", key);
}
} else {
error!("MOMENTO get is null: {}", key);
}
Is there a way to convert types quickly? https://docs.rs/redis/latest/redis/#type-conversions
Thank you so much for your help.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels