pub struct PaperClient { /* private fields */ }Implementations§
Source§impl PaperClient
impl PaperClient
Sourcepub fn new(paper_addr: impl FromPaperAddr) -> PaperClientResult<Self>
pub fn new(paper_addr: impl FromPaperAddr) -> PaperClientResult<Self>
Creates a new instance of the client and connects to the server.
If a connection could not be established, a PaperClientError
is returned.
§Examples
use paper_client::PaperClient;
let client = PaperClient::new("paper://127.0.0.1:3145").unwrap();Sourcepub fn ping(&mut self) -> PaperClientResult<PaperValue>
pub fn ping(&mut self) -> PaperClientResult<PaperValue>
Pings the server.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.ping() {
Ok(value) => println!("{value:?}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn version(&mut self) -> PaperClientResult<PaperValue>
pub fn version(&mut self) -> PaperClientResult<PaperValue>
Gets the cache version.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.version() {
Ok(value) => println!("{value:?}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn auth(&mut self, token: impl AsPaperAuthToken) -> PaperClientResult<()>
pub fn auth(&mut self, token: impl AsPaperAuthToken) -> PaperClientResult<()>
Attempts to authorize the connection with the supplied auth token. This must match the auth token specified in the server’s configuration to be successful.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.auth("my_token") {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn get(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>
pub fn get(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>
Gets the value of the supplied key from the cache.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.get("key") {
Ok(value) => println!("{value:?}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn set(
&mut self,
key: impl AsPaperKey,
value: impl TryInto<PaperValue>,
ttl: Option<u32>,
) -> PaperClientResult<()>
pub fn set( &mut self, key: impl AsPaperKey, value: impl TryInto<PaperValue>, ttl: Option<u32>, ) -> PaperClientResult<()>
Sets the supplied key, value, and ttl to the cache.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.set("key", "value", None) {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn del(&mut self, key: impl AsPaperKey) -> PaperClientResult<()>
pub fn del(&mut self, key: impl AsPaperKey) -> PaperClientResult<()>
Deletes the value of the supplied key from the cache.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.del("key") {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn has(&mut self, key: impl AsPaperKey) -> PaperClientResult<bool>
pub fn has(&mut self, key: impl AsPaperKey) -> PaperClientResult<bool>
Checks if the cache contains an object with the supplied key without altering the eviction order of the objects.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.has("key") {
Ok(has) => println!("{has}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn peek(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>
pub fn peek(&mut self, key: impl AsPaperKey) -> PaperClientResult<PaperValue>
Gets (peeks) the value of the supplied key from the cache without altering the eviction order of the objects.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.peek("key") {
Ok(value) => println!("{value:?}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn ttl(
&mut self,
key: impl AsPaperKey,
ttl: Option<u32>,
) -> PaperClientResult<()>
pub fn ttl( &mut self, key: impl AsPaperKey, ttl: Option<u32>, ) -> PaperClientResult<()>
Sets the TTL associated with the supplied key.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.ttl("key", Some(5)) {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn size(&mut self, key: impl AsPaperKey) -> PaperClientResult<u32>
pub fn size(&mut self, key: impl AsPaperKey) -> PaperClientResult<u32>
Gets the size of the value of the supplied key from the cache in bytes.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.size("key") {
Ok(size) => println!("{size}"),
Err(err) => println!("{err:?}"),
}Sourcepub fn wipe(&mut self) -> PaperClientResult<()>
pub fn wipe(&mut self) -> PaperClientResult<()>
Wipes the contents of the cache.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.wipe() {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn resize(&mut self, size: u64) -> PaperClientResult<()>
pub fn resize(&mut self, size: u64) -> PaperClientResult<()>
Resizes the cache to the supplied size.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.resize(10) {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn policy(&mut self, policy: PaperPolicy) -> PaperClientResult<()>
pub fn policy(&mut self, policy: PaperPolicy) -> PaperClientResult<()>
Sets the cache’s eviction policy.
§Examples
use paper_client::{PaperClient, PaperPolicy};
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.policy(PaperPolicy::Lru) {
Ok(_) => println!("done"),
Err(err) => println!("{err:?}"),
}Sourcepub fn status(&mut self) -> PaperClientResult<Status>
pub fn status(&mut self) -> PaperClientResult<Status>
Gets the cache’s status.
§Examples
use paper_client::PaperClient;
let mut client = PaperClient::new("paper://127.0.0.1:3145").unwrap();
match client.status() {
Ok(status) => println!("{status:?}"),
Err(err) => println!("{err:?}"),
}