| Crates.io | rdcache |
| lib.rs | rdcache |
| version | 0.1.2 |
| created_at | 2024-07-26 10:08:55.518502+00 |
| updated_at | 2024-07-27 07:50:56.272298+00 |
| description | a simple cache using redis backend |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1316002 |
| size | 28,208 |
Rust version of rockscache
use std::time::Duration;
use rdcache::{Client, Options};
use rustis::client::Client as RedisClient;
#[tokio::main]
async fn main() {
let rdb = RedisClient::connect("127.0.0.1:6379").await.unwrap();
let client = Client::new(rdb, Options::default());
let key = "key";
let r = client
.fetch(key, Duration::from_secs(600), || async {
println!("Fetching data from the database");
Ok(Some("data".to_string()))
})
.await;
println!("{:?}", r);
client.tag_as_deleted(key).await.unwrap();
let r = client
.fetch(key, Duration::from_secs(600), || async {
println!("Fetching data from the database");
Ok(Some("data2".to_string()))
})
.await;
println!("{:?}", r);
}
The output will be like:
Fetching data from the database
Ok(Some("data"))
Fetching data from the database
Ok(Some("data2"))