⚠️ Experimental SDK ⚠️
Rust SDK for Momento is experimental and under active development. There could be non-backward compatible changes or removal in the future. Please be aware that you may need to update your source code with the current version of the SDK when its version gets upgraded.
Rust SDK for Momento, a serverless cache that automatically scales without any of the operational overhead required by traditional caching solutions.
```rust use std::env; use momento::simplecacheclient::SimpleCacheClient;
// Initializing Momento let authtoken = env::var("TESTAUTHTOKEN").expect("env var TESTAUTHTOKEN must be set"); let itemdefaultttlseconds = 60 let mut cacheclient = SimpleCacheClient::new(authtoken, itemdefaultttl_seconds).await.unwrap();
// Creating a cache named "cache" let cachename = String::from("cache"); cacheclient.createcache(&cachename).await.unwrap()
// Sets key with default TTL and get value with that key let key = String::from("mykey"); let value = String::from("myvalue"); cacheclient.set(&cachename, key.clone(), value.clone(), None).await.unwrap(); let result = cacheclient.get(&cachename, key.clone()).await.unwrap(); println!("Looked up value: {}", result.value);
// Sets key with TTL of 5 seconds cacheclient.set(&cachename, key.clone(), value.clone(), 5).await.unwrap();
// Permanently deletes cache cacheclient.deletecache(&cache_name).await.unwrap(); ```
Doc and integration tests require an auth token for testing. Set the env var TEST_AUTH_TOKEN
to
provide it.
Running unit tests:
cargo test --lib
Running doc tests:
TEST_AUTH_TOKEN=<auth token> cargo test --doc
Running integration tests:
TEST_AUTH_TOKEN=<auth token> cargo test --tests